CMAKE linker does not find library; but library is found with find_library












0















I have a catkin library under the Name mylib which I build with catkin build
Furthermore, I have a node in which uses functions from this library. I enabled this link as I usually do in the CMakeLists.txt of the node:



find_package(catkin REQUIRED COMPONENTS
mylib
)

add_executable(exec
src/main.cpp
)

target_link_libraries(exec
${catkin_LIBRARIES}
)


However it did not succeed this time. Linker error
I then added:



find_package(catkin REQUIRED COMPONENTS
mylib
)
find_library( MYLIB NAMES
mylib
)
message(${MYLIB})

add_executable(exec
src/main.cpp
)

add_dependencies(exec ${MYLIB})

target_link_libraries(exec
${catkin_LIBRARIES}
${MYLIB}
)


The thing is the message() statement prints the correct path of the library, where i can also find it in the explorer.
However I get the warning:



(add_dependencies):   Policy CMP0046 is not set: Error on non-existent dependency in   add_dependencies.


Which refers to the exact same path for the library and says it is not existent.



The linker error is



/usr/bin/ld: cannot find -lmylib


Remark: I could solve the error by adding the path to the library manually



link_directories($ENV{HOME}/test/devel/lib)


I do not understand why the library is found first, but cannot be linked as its package name. But it works by providing the full path.
I appreciate any insight!










share|improve this question























  • In any case, remove add_dependencies call: This function adjusts dependencies between targets, but path to the library is not a target.

    – Tsyvarev
    Nov 13 '18 at 14:04
















0















I have a catkin library under the Name mylib which I build with catkin build
Furthermore, I have a node in which uses functions from this library. I enabled this link as I usually do in the CMakeLists.txt of the node:



find_package(catkin REQUIRED COMPONENTS
mylib
)

add_executable(exec
src/main.cpp
)

target_link_libraries(exec
${catkin_LIBRARIES}
)


However it did not succeed this time. Linker error
I then added:



find_package(catkin REQUIRED COMPONENTS
mylib
)
find_library( MYLIB NAMES
mylib
)
message(${MYLIB})

add_executable(exec
src/main.cpp
)

add_dependencies(exec ${MYLIB})

target_link_libraries(exec
${catkin_LIBRARIES}
${MYLIB}
)


The thing is the message() statement prints the correct path of the library, where i can also find it in the explorer.
However I get the warning:



(add_dependencies):   Policy CMP0046 is not set: Error on non-existent dependency in   add_dependencies.


Which refers to the exact same path for the library and says it is not existent.



The linker error is



/usr/bin/ld: cannot find -lmylib


Remark: I could solve the error by adding the path to the library manually



link_directories($ENV{HOME}/test/devel/lib)


I do not understand why the library is found first, but cannot be linked as its package name. But it works by providing the full path.
I appreciate any insight!










share|improve this question























  • In any case, remove add_dependencies call: This function adjusts dependencies between targets, but path to the library is not a target.

    – Tsyvarev
    Nov 13 '18 at 14:04














0












0








0








I have a catkin library under the Name mylib which I build with catkin build
Furthermore, I have a node in which uses functions from this library. I enabled this link as I usually do in the CMakeLists.txt of the node:



find_package(catkin REQUIRED COMPONENTS
mylib
)

add_executable(exec
src/main.cpp
)

target_link_libraries(exec
${catkin_LIBRARIES}
)


However it did not succeed this time. Linker error
I then added:



find_package(catkin REQUIRED COMPONENTS
mylib
)
find_library( MYLIB NAMES
mylib
)
message(${MYLIB})

add_executable(exec
src/main.cpp
)

add_dependencies(exec ${MYLIB})

target_link_libraries(exec
${catkin_LIBRARIES}
${MYLIB}
)


The thing is the message() statement prints the correct path of the library, where i can also find it in the explorer.
However I get the warning:



(add_dependencies):   Policy CMP0046 is not set: Error on non-existent dependency in   add_dependencies.


Which refers to the exact same path for the library and says it is not existent.



The linker error is



/usr/bin/ld: cannot find -lmylib


Remark: I could solve the error by adding the path to the library manually



link_directories($ENV{HOME}/test/devel/lib)


I do not understand why the library is found first, but cannot be linked as its package name. But it works by providing the full path.
I appreciate any insight!










share|improve this question














I have a catkin library under the Name mylib which I build with catkin build
Furthermore, I have a node in which uses functions from this library. I enabled this link as I usually do in the CMakeLists.txt of the node:



find_package(catkin REQUIRED COMPONENTS
mylib
)

add_executable(exec
src/main.cpp
)

target_link_libraries(exec
${catkin_LIBRARIES}
)


However it did not succeed this time. Linker error
I then added:



find_package(catkin REQUIRED COMPONENTS
mylib
)
find_library( MYLIB NAMES
mylib
)
message(${MYLIB})

add_executable(exec
src/main.cpp
)

add_dependencies(exec ${MYLIB})

target_link_libraries(exec
${catkin_LIBRARIES}
${MYLIB}
)


The thing is the message() statement prints the correct path of the library, where i can also find it in the explorer.
However I get the warning:



(add_dependencies):   Policy CMP0046 is not set: Error on non-existent dependency in   add_dependencies.


Which refers to the exact same path for the library and says it is not existent.



The linker error is



/usr/bin/ld: cannot find -lmylib


Remark: I could solve the error by adding the path to the library manually



link_directories($ENV{HOME}/test/devel/lib)


I do not understand why the library is found first, but cannot be linked as its package name. But it works by providing the full path.
I appreciate any insight!







c++ cmake ros catkin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 13:37









FrancoFranco

12




12













  • In any case, remove add_dependencies call: This function adjusts dependencies between targets, but path to the library is not a target.

    – Tsyvarev
    Nov 13 '18 at 14:04



















  • In any case, remove add_dependencies call: This function adjusts dependencies between targets, but path to the library is not a target.

    – Tsyvarev
    Nov 13 '18 at 14:04

















In any case, remove add_dependencies call: This function adjusts dependencies between targets, but path to the library is not a target.

– Tsyvarev
Nov 13 '18 at 14:04





In any case, remove add_dependencies call: This function adjusts dependencies between targets, but path to the library is not a target.

– Tsyvarev
Nov 13 '18 at 14:04












1 Answer
1






active

oldest

votes


















1














The library is not in your linker path. E.g. your linker looks in /link and you have a lib in /home. You know where to look and can see it in your file browser but the linker won't find it because it only looks in '/link'.



'find_package' looks for the package and sets some variables but it doesn't change the linker path.



You have to set the linker path by yourself. In most cases find_package sets a variable containing the linker path.



find_package provides some functions like catkin_package(). These functions set your build environment.




catkin_package() is a catkin-provided CMake macro. This is required to specify catkin-specific information to the build system which in turn is used to generate pkg-config and CMake files.



This function must be called before declaring any targets with add_library() or add_executable().







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%2f53282269%2fcmake-linker-does-not-find-library-but-library-is-found-with-find-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









    1














    The library is not in your linker path. E.g. your linker looks in /link and you have a lib in /home. You know where to look and can see it in your file browser but the linker won't find it because it only looks in '/link'.



    'find_package' looks for the package and sets some variables but it doesn't change the linker path.



    You have to set the linker path by yourself. In most cases find_package sets a variable containing the linker path.



    find_package provides some functions like catkin_package(). These functions set your build environment.




    catkin_package() is a catkin-provided CMake macro. This is required to specify catkin-specific information to the build system which in turn is used to generate pkg-config and CMake files.



    This function must be called before declaring any targets with add_library() or add_executable().







    share|improve this answer




























      1














      The library is not in your linker path. E.g. your linker looks in /link and you have a lib in /home. You know where to look and can see it in your file browser but the linker won't find it because it only looks in '/link'.



      'find_package' looks for the package and sets some variables but it doesn't change the linker path.



      You have to set the linker path by yourself. In most cases find_package sets a variable containing the linker path.



      find_package provides some functions like catkin_package(). These functions set your build environment.




      catkin_package() is a catkin-provided CMake macro. This is required to specify catkin-specific information to the build system which in turn is used to generate pkg-config and CMake files.



      This function must be called before declaring any targets with add_library() or add_executable().







      share|improve this answer


























        1












        1








        1







        The library is not in your linker path. E.g. your linker looks in /link and you have a lib in /home. You know where to look and can see it in your file browser but the linker won't find it because it only looks in '/link'.



        'find_package' looks for the package and sets some variables but it doesn't change the linker path.



        You have to set the linker path by yourself. In most cases find_package sets a variable containing the linker path.



        find_package provides some functions like catkin_package(). These functions set your build environment.




        catkin_package() is a catkin-provided CMake macro. This is required to specify catkin-specific information to the build system which in turn is used to generate pkg-config and CMake files.



        This function must be called before declaring any targets with add_library() or add_executable().







        share|improve this answer













        The library is not in your linker path. E.g. your linker looks in /link and you have a lib in /home. You know where to look and can see it in your file browser but the linker won't find it because it only looks in '/link'.



        'find_package' looks for the package and sets some variables but it doesn't change the linker path.



        You have to set the linker path by yourself. In most cases find_package sets a variable containing the linker path.



        find_package provides some functions like catkin_package(). These functions set your build environment.




        catkin_package() is a catkin-provided CMake macro. This is required to specify catkin-specific information to the build system which in turn is used to generate pkg-config and CMake files.



        This function must be called before declaring any targets with add_library() or add_executable().








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 13:45









        Thomas SablikThomas Sablik

        2,54111028




        2,54111028






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282269%2fcmake-linker-does-not-find-library-but-library-is-found-with-find-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

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly