我有一个CMakeLists.txt文件,包含以下内容:
target_link_libraries(${PROJECT_NAME} OpenNI2)当我运行cmake ,我没有收到任何错误。 但是当我运行make ,我收到以下错误:
/usr/bin/ld: cannot find -lOpenNI2但是,我的构建目录中有一个名为libOpenNI2.so的文件。 那么为什么不能找到这个呢? 我以为build目录是在target_link_libraries的搜索路径上?
谢谢!
I have a CMakeLists.txt file, with the following:
target_link_libraries(${PROJECT_NAME} OpenNI2)When I run cmake, I receive no errors. But when I run make, I receive the following error:
/usr/bin/ld: cannot find -lOpenNI2However, I have a file called libOpenNI2.so in my build directory. So why can ld not find this? I thought that the build directory was on the search path for target_link_libraries?
Thanks!
最满意答案
这是因为在链接时,链接器不会查看当前目录,而只会查找一组预定义目录。
您需要告诉CMake库的位置,例如,通过在target_link_library命令中提供库的完整路径,或将其添加为导入的库 。
That's because when linking, the linker doesn't look in the current directory but only in a set of predefined directories.
You need to tell CMake where the library is, for example by giving the full path to the library in the target_link_library command, or adding it as an imported library.
更多推荐
发布评论