(Linux) 无法通过 cmake 链接档案
在命令行上,以下命令生成可执行文件:
g++ -o a.out main.cpp class1.cc class2.cc /usr/lib/libgsl.a /usr/lib/libgslcblas.a
但是我不确定如何让 cmake 正常工作。 当我添加像这样的行时,
include_directories(/usr/lib/)
link_libraries(usr/lib/libgsl.a usr/libgslcblas.a)
配置似乎可以工作,但构建失败:
CMakeFiles/kmv.dir/main.o: In function `main':
main.cpp:27: undefined reference to `gsl_matrix_alloc'
main.cpp:35: undefined reference to `gsl_matrix_fscanf'
collect2: ld returned 1 exit status
make[2]: *** [kmv] Error 1
make[1]: *** [CMakeFiles/kmv.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
似乎是一个合成问题。欢迎任何提示。谢谢。
On the command line, the following produces an executable:
g++ -o a.out main.cpp class1.cc class2.cc /usr/lib/libgsl.a /usr/lib/libgslcblas.a
However I am unsure how to get cmake to work properly.
When I add a line like
include_directories(/usr/lib/)
link_libraries(usr/lib/libgsl.a usr/libgslcblas.a)
the configuring seems to work but building fails:
CMakeFiles/kmv.dir/main.o: In function `main':
main.cpp:27: undefined reference to `gsl_matrix_alloc'
main.cpp:35: undefined reference to `gsl_matrix_fscanf'
collect2: ld returned 1 exit status
make[2]: *** [kmv] Error 1
make[1]: *** [CMakeFiles/kmv.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
Seems to be a synthax problem. Any hint is welcome. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是
尝试
其中 targetName 是您想要创建的输出二进制文件的名称。路径
/usr/lib
应该已经在 CMake 的默认库搜索路径中,因此您不必指定该路径,但如果您确实必须指定自定义库路径,则可以这样做就像这样include_directories
CMake 指令用于添加标头搜索路径,而不是库搜索路径...Instead of
try
Where targetName is the name of the output binary you intend to create. The path
/usr/lib
should already be in the default library search path for CMake, so you shouldn't have to specify that, but if you did have to specify a custom library path, you would do it like soThe
include_directories
CMake directive is used for adding header search paths, not library search paths...可能 link_libraries 已被弃用
http://www.cmake.org/pipermail/cmake/2009-April /028439.html
尝试使用 target_link_libraries。
Probably, link_libraries is deprecated
http://www.cmake.org/pipermail/cmake/2009-April/028439.html
Try using target_link_libraries instead.