链接到 Boost 1.63 静态库时未定义的引用
references undefined when linking against boost 1.63 static libs
我静态地链接到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
)
这是我找到提升的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/中
我的理解是,如果链接器在正确路径之前在系统安装上找到提升静态库,则可能会发生这种情况。
Cmake似乎找到了提升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,但没有安装 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
...
我已经没有想法了;还有什么我应该检查的吗?
该libinfinite.a
需要在命令行中的 boost 库之前。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用