简体   繁体   中英

references undefined when linking against boost 1.63 static libs

I'm linking against boost statically. When I do so, I get some undefined reference errors (below).

[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

When I link dynamically, the references are presumably present, and the build links successfully.

I need to be able to build this statically; requirement of the project.

I'm building with cmake. My link directories are ordered thus:

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
)

My target link libaries are defined as:

target_link_libraries(
    ${sThisProject}
    ${Boost_LIBRARIES}
    libhiredis.a
    libevent.a
    libevent_core.a
    libevent_pthreads.a
    libssl.so
    libcrypto.so
    libpthread.so.0
)

Here's the CMakeLists.txt entry where I find boost:

find_package( Boost 1.63 EXACT REQUIRED COMPONENTS system chrono date_time filesystem program_options regex thread REQUIRED )

I also set the following:

SET (Boost_NO_SYSTEM_PATHS ON)
SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME ON)

I've checked that my build of 1.63 has successfully built the appropriate static lib - libboost_date_time.a - and it's present in ${BOOST}/stage/lib/

It's my understanding that this can happen if the linker finds a boost static lib on the system install before the correct path.

Cmake appears to find the correct path for boost 1_63:

(output during build:)

-- Boost version: 1.63.0
-- Found the following Boost libraries:
--   system
--   chrono
--   date_time
--   filesystem
--   program_options
--   regex
--   thread

I run fedora 25, so my system installed version of boost was 1_60, so to avoid the above problem, I uninstalled it completely:

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

I built but do not install 1.63 in a 3rd party directory in my source tree. It's built with the following commands:

./bootstrap.sh
./b2 -j8

I set linker output with:

SET (CMAKE_EXE_LINKER_FLAGS -v)

And determined via the following output that I'm linking against the correct static libary:

-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
...

I've run out of ideas; is there something else I should check?

libinfinite.a需要在命令行中的boost库之前。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM