2017-07-05 5 views
0

私はブーストに対して静的にリンクしています。私がそうするとき、私はいくつかの未定義の参照エラーを得る(下記)。は、ブースト1.63の静的ライブラリとのリンク時に未定義です

[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 
) 

私の目標リンクするライブラリは次のように定義されています。私も設定

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

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エントリがあります以下:

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のビルドが適切な静的なlib-libboost_date_time.aを構築したことを確認しました。$ {BOOST}/stage/lib/

にあります。

これはリンカが見つけた正しいパスの前に、システムのboost静的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ので、ブーストの私のシステムがインストールバージョンを実行するには、そう避けるために、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 

を私はリンカ出力を設定します。私は正しい静的libaryに対してリンクしています、次の出力を介して

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

リンカの完全なコマンドラインを表示するとエラーになります。その 'libinfinite.a'は、コマンドラインのboostライブラリの前に置く必要があります。 –

+0

libinfinite.aはコマンドラインでブーストライブラリに先行する必要があります - これは問題を解決しました - ありがとう! –

答えて

1

そのlibinfinite.aは、コマンドラインでブーストライブラリに先行する必要があります。

関連する問題