【发布时间】:2011-03-26 19:11:36
【问题描述】:
让我快速解决问题。我有一个依赖于 boost 的库“serial”,它是在 cmake 中设置的,我安装了一个 Findserial.cmake 来帮助我的第二个库“xbow_400”找到它。这一切都很好,直到我尝试编译链接到“xbow_400”的“test_xbow_400”,此时我得到这个链接错误:
Undefined symbols:
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in test_xbow_400.o
__static_initialization_and_destruction_0(int, int)in test_xbow_400.o
__static_initialization_and_destruction_0(int, int)in libxbow_400.a(xbow_400.o)
__static_initialization_and_destruction_0(int, int)in libxbow_400.a(xbow_400.o)
__static_initialization_and_destruction_0(int, int)in libserial.a(serial.o)
__static_initialization_and_destruction_0(int, int)in libserial.a(serial.o)
"boost::system::system_category()", referenced from:
boost::asio::error::get_system_category() in test_xbow_400.o
__static_initialization_and_destruction_0(int, int)in test_xbow_400.o
boost::asio::error::get_system_category() in libxbow_400.a(xbow_400.o)
__static_initialization_and_destruction_0(int, int)in libxbow_400.a(xbow_400.o)
boost::asio::error::get_system_category() in libserial.a(serial.o)
boost::system::error_code::error_code()in libserial.a(serial.o)
__static_initialization_and_destruction_0(int, int)in libserial.a(serial.o)
ld: symbol(s) not found
现在,我可以通过将这些行添加到“xbow_400”的 CMakeLists.txt 文件中来解决此问题:
+ # Find Boost
+ find_package(Boost COMPONENTS system filesystem thread REQUIRED)
+
+ link_directories(${Boost_LIBRARY_DIRS})
+ include_directories(${Boost_INCLUDE_DIRS})
# Compile the xbow_400 Library
add_library(xbow_400 src/xbow_400.cpp include/xbow_400.h)
- target_link_libraries(xbow_400 ${serial_LIBRARIES})
+ target_link_libraries(xbow_400 ${serial_LIBRARIES} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
但是,我想让 xbow_400 使用串行,而不必专门查找 boost 并链接到它。 (xbow_400代码不包含也不直接使用boost,只能通过串口库)。
这可能吗?如果是这样,我应该向 Findserial.cmake 添加东西还是应该改变我构建串行的方式?
串行库:https://github.com/wjwwood/serial xbow_400:https://github.com/wjwwood/Crossbow-IMU400CC-100
我使用的是 OS X 10.6.6。我还没有在 Linux 或 Windows 上尝试过。
【问题讨论】: