Using Catkin with CMake Interface Library












1














I am currently trying to use a c++ header-only library declared as a cmake interface library within catkin. This library is supposed to be used by other packages in catkin_ws/src. I was able to compile all packages with catkin_make but not with catkin build.



catkin build fails within the cmake command find_package(... interface_lib) in dependent packages.



Error-Message for the example below would be:




Project 'testnode' tried to find library 'interface_library'. The library
is neither a target nor built/installed properly. Did you compile project
'interface_library'? Did you find_package() it before the subdirectory
containing its code is included?




How do i need to setup CMakeLists.txt and package.xml files to make catkin build work with interface libraries?



Minimal example:



Interface Library



File: catkin_ws/src/interface_library/include/interface_library.hpp



#pragma once

#define RATE 10


File: catkin_ws/src/interface_library/CMakeLists.txt



cmake_minimum_required(VERSION 3.0.0)
project(interface_library)

find_package(catkin REQUIRED)

catkin_package(INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME})

add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE include)


File: catkin_ws/src/interface_library/package.xml



<package format="2">
<name>interface_library</name>
<description>Test interface library</description>
<version>0.0.1</version>
<maintainer email="master@disaster.com">Master of Disaster</maintainer>
<license>MIT</license>
<buildtool_depend>catkin</buildtool_depend>
</package>


Testnode



File: catkin_ws/src/testnode/src/testnode.cpp



#include <iostream>
#include "interface_library.hpp"

int main(void)
{
std::cout << RATE << std::endl;
}


File: catkin_ws/src/testnode/CMakeLists.txt



cmake_minimum_required(VERSION 3.0.0)
project(testnode)

find_package(catkin REQUIRED COMPONENTS interface_library)

catkin_package()

include_directories(${catkin_INCLUDE_DIRS})

add_executable(${PROJECT_NAME}_node src/testnode.cpp)


File: catkin_ws/src/testnode/package.xml



<?xml version="1.0"?>
<package format="2">
<name>testnode</name>
<version>0.0.0</version>
<description>The testnode package</description>
<maintainer email="master@disaster.com">Master of Disaster</maintainer>
<license>MIT</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>interface_library</build_depend>
<build_export_depend>interface_library</build_export_depend>
<exec_depend>interface_library</exec_depend>
</package>









share|improve this question



























    1














    I am currently trying to use a c++ header-only library declared as a cmake interface library within catkin. This library is supposed to be used by other packages in catkin_ws/src. I was able to compile all packages with catkin_make but not with catkin build.



    catkin build fails within the cmake command find_package(... interface_lib) in dependent packages.



    Error-Message for the example below would be:




    Project 'testnode' tried to find library 'interface_library'. The library
    is neither a target nor built/installed properly. Did you compile project
    'interface_library'? Did you find_package() it before the subdirectory
    containing its code is included?




    How do i need to setup CMakeLists.txt and package.xml files to make catkin build work with interface libraries?



    Minimal example:



    Interface Library



    File: catkin_ws/src/interface_library/include/interface_library.hpp



    #pragma once

    #define RATE 10


    File: catkin_ws/src/interface_library/CMakeLists.txt



    cmake_minimum_required(VERSION 3.0.0)
    project(interface_library)

    find_package(catkin REQUIRED)

    catkin_package(INCLUDE_DIRS include
    LIBRARIES ${PROJECT_NAME})

    add_library(${PROJECT_NAME} INTERFACE)
    target_include_directories(${PROJECT_NAME} INTERFACE include)


    File: catkin_ws/src/interface_library/package.xml



    <package format="2">
    <name>interface_library</name>
    <description>Test interface library</description>
    <version>0.0.1</version>
    <maintainer email="master@disaster.com">Master of Disaster</maintainer>
    <license>MIT</license>
    <buildtool_depend>catkin</buildtool_depend>
    </package>


    Testnode



    File: catkin_ws/src/testnode/src/testnode.cpp



    #include <iostream>
    #include "interface_library.hpp"

    int main(void)
    {
    std::cout << RATE << std::endl;
    }


    File: catkin_ws/src/testnode/CMakeLists.txt



    cmake_minimum_required(VERSION 3.0.0)
    project(testnode)

    find_package(catkin REQUIRED COMPONENTS interface_library)

    catkin_package()

    include_directories(${catkin_INCLUDE_DIRS})

    add_executable(${PROJECT_NAME}_node src/testnode.cpp)


    File: catkin_ws/src/testnode/package.xml



    <?xml version="1.0"?>
    <package format="2">
    <name>testnode</name>
    <version>0.0.0</version>
    <description>The testnode package</description>
    <maintainer email="master@disaster.com">Master of Disaster</maintainer>
    <license>MIT</license>

    <buildtool_depend>catkin</buildtool_depend>
    <build_depend>interface_library</build_depend>
    <build_export_depend>interface_library</build_export_depend>
    <exec_depend>interface_library</exec_depend>
    </package>









    share|improve this question

























      1












      1








      1







      I am currently trying to use a c++ header-only library declared as a cmake interface library within catkin. This library is supposed to be used by other packages in catkin_ws/src. I was able to compile all packages with catkin_make but not with catkin build.



      catkin build fails within the cmake command find_package(... interface_lib) in dependent packages.



      Error-Message for the example below would be:




      Project 'testnode' tried to find library 'interface_library'. The library
      is neither a target nor built/installed properly. Did you compile project
      'interface_library'? Did you find_package() it before the subdirectory
      containing its code is included?




      How do i need to setup CMakeLists.txt and package.xml files to make catkin build work with interface libraries?



      Minimal example:



      Interface Library



      File: catkin_ws/src/interface_library/include/interface_library.hpp



      #pragma once

      #define RATE 10


      File: catkin_ws/src/interface_library/CMakeLists.txt



      cmake_minimum_required(VERSION 3.0.0)
      project(interface_library)

      find_package(catkin REQUIRED)

      catkin_package(INCLUDE_DIRS include
      LIBRARIES ${PROJECT_NAME})

      add_library(${PROJECT_NAME} INTERFACE)
      target_include_directories(${PROJECT_NAME} INTERFACE include)


      File: catkin_ws/src/interface_library/package.xml



      <package format="2">
      <name>interface_library</name>
      <description>Test interface library</description>
      <version>0.0.1</version>
      <maintainer email="master@disaster.com">Master of Disaster</maintainer>
      <license>MIT</license>
      <buildtool_depend>catkin</buildtool_depend>
      </package>


      Testnode



      File: catkin_ws/src/testnode/src/testnode.cpp



      #include <iostream>
      #include "interface_library.hpp"

      int main(void)
      {
      std::cout << RATE << std::endl;
      }


      File: catkin_ws/src/testnode/CMakeLists.txt



      cmake_minimum_required(VERSION 3.0.0)
      project(testnode)

      find_package(catkin REQUIRED COMPONENTS interface_library)

      catkin_package()

      include_directories(${catkin_INCLUDE_DIRS})

      add_executable(${PROJECT_NAME}_node src/testnode.cpp)


      File: catkin_ws/src/testnode/package.xml



      <?xml version="1.0"?>
      <package format="2">
      <name>testnode</name>
      <version>0.0.0</version>
      <description>The testnode package</description>
      <maintainer email="master@disaster.com">Master of Disaster</maintainer>
      <license>MIT</license>

      <buildtool_depend>catkin</buildtool_depend>
      <build_depend>interface_library</build_depend>
      <build_export_depend>interface_library</build_export_depend>
      <exec_depend>interface_library</exec_depend>
      </package>









      share|improve this question













      I am currently trying to use a c++ header-only library declared as a cmake interface library within catkin. This library is supposed to be used by other packages in catkin_ws/src. I was able to compile all packages with catkin_make but not with catkin build.



      catkin build fails within the cmake command find_package(... interface_lib) in dependent packages.



      Error-Message for the example below would be:




      Project 'testnode' tried to find library 'interface_library'. The library
      is neither a target nor built/installed properly. Did you compile project
      'interface_library'? Did you find_package() it before the subdirectory
      containing its code is included?




      How do i need to setup CMakeLists.txt and package.xml files to make catkin build work with interface libraries?



      Minimal example:



      Interface Library



      File: catkin_ws/src/interface_library/include/interface_library.hpp



      #pragma once

      #define RATE 10


      File: catkin_ws/src/interface_library/CMakeLists.txt



      cmake_minimum_required(VERSION 3.0.0)
      project(interface_library)

      find_package(catkin REQUIRED)

      catkin_package(INCLUDE_DIRS include
      LIBRARIES ${PROJECT_NAME})

      add_library(${PROJECT_NAME} INTERFACE)
      target_include_directories(${PROJECT_NAME} INTERFACE include)


      File: catkin_ws/src/interface_library/package.xml



      <package format="2">
      <name>interface_library</name>
      <description>Test interface library</description>
      <version>0.0.1</version>
      <maintainer email="master@disaster.com">Master of Disaster</maintainer>
      <license>MIT</license>
      <buildtool_depend>catkin</buildtool_depend>
      </package>


      Testnode



      File: catkin_ws/src/testnode/src/testnode.cpp



      #include <iostream>
      #include "interface_library.hpp"

      int main(void)
      {
      std::cout << RATE << std::endl;
      }


      File: catkin_ws/src/testnode/CMakeLists.txt



      cmake_minimum_required(VERSION 3.0.0)
      project(testnode)

      find_package(catkin REQUIRED COMPONENTS interface_library)

      catkin_package()

      include_directories(${catkin_INCLUDE_DIRS})

      add_executable(${PROJECT_NAME}_node src/testnode.cpp)


      File: catkin_ws/src/testnode/package.xml



      <?xml version="1.0"?>
      <package format="2">
      <name>testnode</name>
      <version>0.0.0</version>
      <description>The testnode package</description>
      <maintainer email="master@disaster.com">Master of Disaster</maintainer>
      <license>MIT</license>

      <buildtool_depend>catkin</buildtool_depend>
      <build_depend>interface_library</build_depend>
      <build_export_depend>interface_library</build_export_depend>
      <exec_depend>interface_library</exec_depend>
      </package>






      c++ cmake ros catkin






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 17:53









      JFT

      143




      143
























          1 Answer
          1






          active

          oldest

          votes


















          0














          older catkin or catkin_make uses merged development space but newer catkin or catkin build use linked development space by default.



          First thing you should do is to separate catkin workspaces from each other in 2 different folder. Then set up change catkin build's workspace to merged-devel with:



          catkin config --merge-devel



          and also manually expand it's search areas to both your main ROS folder (default in /opt/ros/<your-version>) and other catkin workspaces which you may use with:



          catkin config --expand <path-to-ros-workspace>



          after that add your projects and build.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267571%2fusing-catkin-with-cmake-interface-library%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            older catkin or catkin_make uses merged development space but newer catkin or catkin build use linked development space by default.



            First thing you should do is to separate catkin workspaces from each other in 2 different folder. Then set up change catkin build's workspace to merged-devel with:



            catkin config --merge-devel



            and also manually expand it's search areas to both your main ROS folder (default in /opt/ros/<your-version>) and other catkin workspaces which you may use with:



            catkin config --expand <path-to-ros-workspace>



            after that add your projects and build.






            share|improve this answer


























              0














              older catkin or catkin_make uses merged development space but newer catkin or catkin build use linked development space by default.



              First thing you should do is to separate catkin workspaces from each other in 2 different folder. Then set up change catkin build's workspace to merged-devel with:



              catkin config --merge-devel



              and also manually expand it's search areas to both your main ROS folder (default in /opt/ros/<your-version>) and other catkin workspaces which you may use with:



              catkin config --expand <path-to-ros-workspace>



              after that add your projects and build.






              share|improve this answer
























                0












                0








                0






                older catkin or catkin_make uses merged development space but newer catkin or catkin build use linked development space by default.



                First thing you should do is to separate catkin workspaces from each other in 2 different folder. Then set up change catkin build's workspace to merged-devel with:



                catkin config --merge-devel



                and also manually expand it's search areas to both your main ROS folder (default in /opt/ros/<your-version>) and other catkin workspaces which you may use with:



                catkin config --expand <path-to-ros-workspace>



                after that add your projects and build.






                share|improve this answer












                older catkin or catkin_make uses merged development space but newer catkin or catkin build use linked development space by default.



                First thing you should do is to separate catkin workspaces from each other in 2 different folder. Then set up change catkin build's workspace to merged-devel with:



                catkin config --merge-devel



                and also manually expand it's search areas to both your main ROS folder (default in /opt/ros/<your-version>) and other catkin workspaces which you may use with:



                catkin config --expand <path-to-ros-workspace>



                after that add your projects and build.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 at 16:15









                Mohammad Ali

                30018




                30018






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267571%2fusing-catkin-with-cmake-interface-library%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python