我在静态链接boost。当我这样做时,我得到一些未定义的引用错误(如下所示)。
[100%] Linking CXX executable infiniteTests
/home/wdog/src/protos/infinite/libinfinite.a(ServiceDiscovery.cpp.o): In function `boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::simple_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::ostream&)':
/home/wdog/src/3rdp/boost_1_63_0/boost/date_time/date_formatting.hpp:44: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
/home/wdog/src/3rdp/boost_1_63_0/boost/date_time/date_formatting.hpp:49: undefined reference to `boost::gregorian::greg_month::as_long_string() const'
collect2: error: ld returned 1 exit status当我动态链接时,可能存在引用,并且构建链接成功。
我需要能够建立这个静态;该项目的要求。
我正在使用cmake构建。我的链接目录的顺序如下:
link_directories(
$ENV{PROJECT_LIB_DIR}
$ENV{BOOST_LIBRARY_DIR}
$ENV{HIREDIS_LIB_DIR}
$ENV{LIBEVENT_LIB_DIR}
$ENV{PROJECT_ROOT}
/usr/lib
/usr/local/lib
)我的目标链接库定义为:
target_link_libraries(
${sThisProject}
${Boost_LIBRARIES}
libhiredis.a
libevent.a
libevent_core.a
libevent_pthreads.a
libssl.so
libcrypto.so
libpthread.so.0
)下面是我找到boost的CMakeLists.txt条目:
find_package( Boost 1.63 EXACT REQUIRED COMPONENTS system chrono date_time filesystem program_options regex thread REQUIRED )我还设置了以下内容:
SET (Boost_NO_SYSTEM_PATHS ON)
SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME ON)我已经检查了我的1.63版本已经成功地构建了适当的静态库-- libboost_date_time.a --它位于${BOOST}/stage/ lib /中
我的理解是,如果链接器在正确的路径之前在系统安装上发现了一个boost静态库,就会发生这种情况。
Cmake似乎找到了boost 1_63的正确路径:
(构建过程中的输出:)
-- Boost version: 1.63.0
-- Found the following Boost libraries:
-- system
-- chrono
-- date_time
-- filesystem
-- program_options
-- regex
-- thread我运行的是fedora 25,所以我的系统安装的boost版本是1_60,所以为了避免上面的问题,我完全卸载了它:
sudo dnf remove boost boost-atomic boost-chrono boost-container boost-context boost-coroutine boost-date-time boost-devel boost-filesystem boost-graph boost-iostreams boost-locale boost-log boost-math boost-program-options boost-python boost-random boost-regex boost-serialization boost-signals boost-system boost-test boost-thread boost-timer boost-type_erasure boost-wave我在源码树的第三方目录中构建了1.63,但没有安装。它是使用以下命令构建的:
./bootstrap.sh
./b2 -j8我用以下命令设置链接器输出:
SET (CMAKE_EXE_LINKER_FLAGS -v)并通过以下输出确定我链接到正确的静态库:
-o
...
/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_system.a
/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_chrono.a
**/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_date_time.a**
/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_filesystem.a
/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_program_options.a
/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_regex.a
/home/wdog/src/3rdp/boost_1_63_0/stage/lib/libboost_thread.a
...我的想法已经用完了,还有什么我应该检查的吗?
发布于 2017-07-05 22:39:10
在命令行中,libinfinite.a需要放在boost库之前。
https://stackoverflow.com/questions/44927372
复制相似问题