CMAKE linker does not find library; but library is found with find_library
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
add a comment |
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
In any case, removeadd_dependenciescall: This function adjusts dependencies between targets, but path to the library is not a target.
– Tsyvarev
Nov 13 '18 at 14:04
add a comment |
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
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
c++ cmake ros catkin
asked Nov 13 '18 at 13:37
FrancoFranco
12
12
In any case, removeadd_dependenciescall: This function adjusts dependencies between targets, but path to the library is not a target.
– Tsyvarev
Nov 13 '18 at 14:04
add a comment |
In any case, removeadd_dependenciescall: 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
add a comment |
1 Answer
1
active
oldest
votes
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().
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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().
add a comment |
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().
add a comment |
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().
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().
answered Nov 13 '18 at 13:45
Thomas SablikThomas Sablik
2,54111028
2,54111028
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
In any case, remove
add_dependenciescall: This function adjusts dependencies between targets, but path to the library is not a target.– Tsyvarev
Nov 13 '18 at 14:04