我是静态链接提升。当我这样做时,我得到一些未定义的引用错误(下面)。
[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
)
这里是我发现提升的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 static lib,就会发生这种情况。
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
...
我已经没有想法;我还应该检查一下吗?
答案 0 :(得分:1)
libinfinite.a
需要在命令行中的boost库之前。