本文介绍了如何针对与cmake的boost.system链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的makefile生成cmake的编译C ++文件依赖于提高文件系统库。

在连接过程中,我得到以下错误:


未定义的符号:
  提振::系统:: get_generic_category(),从引用:
      __static_initialization_and_destruction_0(INT,INT)在FaceRecognizer.cpp.o
      __static_initialization_and_destruction_0(INT,INT)在FaceRecognizer.cpp.o
      __static_initialization_and_destruction_0(INT,INT)在FaceRecognizer.cpp.o
  提振::系统:: get_system_category(),从引用:
      __static_initialization_and_destruction_0(INT,INT)在FaceRecognizer.cpp.o
      __static_initialization_and_destruction_0(INT,INT)在FaceRecognizer.cpp.o
LD:符号(S)未找到
collect2:劳工处返回1退出状态
使[2]:*** [SRC / ImageMarker]错误1

从产生这个错误Makefile中的动作是这一行:


CD /用户/雅努什/文件/工作区/ ImageMarker /调试/ src目录&&的/ opt / local / bin目录/ cmake的-E cmake_link_script CMakeFiles / ImageMarker.dir / link.txt --verbose = 1
在/ usr /斌/ C ++ -O3 -Wall -Wno德precated -g -verbose轮候册,-search_paths_first -headerpad_max_install_names -fPIC CMakeFiles / ImageMarker.dir / ImageMarker.cpp.o CMakeFiles / ImageMarker.dir /图像。 cpp.o CMakeFiles / ImageMarker.dir / utils.cpp.o CMakeFiles / ImageMarker.dir / XMLWriter.cpp.o CMakeFiles / ImageMarker.dir / FaceRecognizer.cpp.o -o ImageMarker -L /选择/ local / lib目录../ libTinyXml.a /opt/local/lib/libboost_filesystem-mt.dylib

一些谷歌搜索给我看,这个错误似乎是与升压文件系统库的Mac常见,因为我必须对一个boost.system库链接,或让我的项目取决于boost.system库。

如何强制cmake的没有硬编码库路径对库进行链接?

下面从otool的结果:

  otool -L /opt/local/lib/libboost_filesystem-mt.dylib
 /opt/local/lib/libboost_filesystem-mt.dylib:
 /opt/local/lib/libboost_filesystem-mt.dylib(兼容版本0.0.0,目前版本0.0.0)
 /opt/local/lib/libboost_system-mt.dylib(兼容版本0.0.0,目前版本0.0.0)
 /usr/lib/libstdc++.6.dylib(兼容版本7.0.0,目前版本7.4.0)
 /usr/lib/libgcc_s.1.dylib(兼容1.0.0版本,目前版本1.0.0)
 /usr/lib/libSystem.B.dylib(兼容版本1.0.0,当前版本111.0.0)


解决方案

在linux下的CMake数字本身boost_filesystem反对boost_system联系。很明显,你必须明确地告诉它在Mac上:

  find_package(升压组件的系统文件系统必填)
#...
target_link_libraries(mytarget
  $ {} Boost_FILESYSTEM_LIBRARY
  $ {} Boost_SYSTEM_LIBRARY

I use a cmake generated makefile to compile a c++ file that depends on the boost filesystem library.

During the linking process I get the following error:

Undefined symbols:
  "boost::system::get_generic_category()", referenced from:
      __static_initialization_and_destruction_0(int, int)in FaceRecognizer.cpp.o
      __static_initialization_and_destruction_0(int, int)in FaceRecognizer.cpp.o
      __static_initialization_and_destruction_0(int, int)in FaceRecognizer.cpp.o
  "boost::system::get_system_category()", referenced from:
      __static_initialization_and_destruction_0(int, int)in FaceRecognizer.cpp.o
      __static_initialization_and_destruction_0(int, int)in FaceRecognizer.cpp.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [src/ImageMarker] Error 1

The action from the makefile that generates this error is this line:

cd /Users/janusz/Documents/workspace/ImageMarker/Debug/src && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/ImageMarker.dir/link.txt --verbose=1
/usr/bin/c++   -O3 -Wall -Wno-deprecated -g -verbose -Wl,-search_paths_first -headerpad_max_install_names -fPIC CMakeFiles/ImageMarker.dir/ImageMarker.cpp.o CMakeFiles/ImageMarker.dir/Image.cpp.o CMakeFiles/ImageMarker.dir/utils.cpp.o CMakeFiles/ImageMarker.dir/XMLWriter.cpp.o CMakeFiles/ImageMarker.dir/FaceRecognizer.cpp.o  -o ImageMarker  -L/opt/local/lib ../libTinyXml.a /opt/local/lib/libboost_filesystem-mt.dylib

Some googling showed me that this error seems to be common on macs with the boost file system library because I have to link against a boost.system library or make my project depending on the boost.system library.

How do i force cmake to link against the library without hardcoding the library path?

Here the result from otool:

otool -L /opt/local/lib/libboost_filesystem-mt.dylib
 /opt/local/lib/libboost_filesystem-mt.dylib:
 /opt/local/lib/libboost_filesystem-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
 /opt/local/lib/libboost_system-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
 /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
 /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
 /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
解决方案

On linux CMake figures itself that boost_filesystem is linked against boost_system. Obviously you have to tell it explicitly on Mac:

find_package(Boost COMPONENTS system filesystem REQUIRED)
#...
target_link_libraries(mytarget
  ${Boost_FILESYSTEM_LIBRARY}
  ${Boost_SYSTEM_LIBRARY}
)

这篇关于如何针对与cmake的boost.system链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 00:38