2016-03-24 17 views
0

私はこれと似ているが、これと似ていない多くの質問があります。Cmake.txtにBoostライブラリを追加しようとしています(Clion Ide)

Clionを使用してCmakeで認識されている問題を認識しています。Clionに含まれているincboostテンプレートを含め、いくつかの方法を試しました。

cmakeのバージョン私は上記のincboost自動生成です3.4 ブーストバージョン1.60.0

find_package(Boost) 
    if (Boost_FOUND) 
    include_directories(${Boost_INCLUDE_DIR}) 
endif() 

は、これは何の結果を生成しません。

第二の試みは、以下の

set(Boost_Dir "C:\\Program Files (x86)\\boost_1_60_0\\") 
find_package(Boost 1.60.0 COMPONENTS filesystem) 
include_directories(${Boost_Dir}) 

CmakeFiles\Svp.dir/objects.a(main.cpp.obj): 
In function`_static_initialization_and_destruction_0': 

C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:221: undefined reference 
to `boost::system::generic_category()' 

C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:222: undefined 
reference to `boost::system::generic_category()' 

C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:223: undefined 
reference to `boost::system::system_category()' 

collect2.exe: error: ld returned 1 exit status 

mingw32-make.exe[3]: *** [Svp.exe] Error 1 

CMakeFiles\Svp.dir\build.make:96: recipe for target 'Svp.exe' failed 

CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Svp.dir/all' failed 

mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2 

CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Svp.dir/rule' failed 

mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2 

Makefile:117: recipe for target 'Svp' failed 

mingw32-make.exe: *** [Svp] Error 2 

私の第三の試みがこの

set(boost "C:\\Program Files (x86)\\boost_1_60_0\\boost\\") 
INCLUDE_DIRECTORIES(${boost}) 

fatal error: boost/filesystem/config.hpp: No such file or directory 
# include <boost/filesystem/config.hpp> 
            ^
compilation terminated. 
mingw32-make.exe[3]: *** [CMakeFiles/Svp.dir/main.cpp.obj] Error 1 
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2 
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2 

を生成し、最終的にここHow do you add boost libraries in CMakeLists.txt与えられた解決策は、私のエラー出力を変更していないです。

+0

私は別のコンパイラを使っていろいろなプロジェクトで私のブースト設定を使ったことを明確にしてくれます。それはCmake.txtにどのように置かれているのかという問題であることを知っています。 – Afflicted

+0

あなたは、 ? –

+0

ここでちょうどg ++ – Afflicted

答えて

1

は、ここでは私のプロジェクトでは、移植可能な方法で、私はそれを使用する方法は次のとおりです。

if (WIN32) 
    set(BOOST_ROOT "C:/Program Files (x86)/boost_1_60_0/") 
    set(Boost_USE_STATIC_LIBS ON) 
    set(Boost_USE_MULTITHREAD ON) 

    include_directories(${BOOST_ROOT}) 
    link_directories(${BOOST_ROOT}/stage/lib) # add this before add_executable() 
endif() 

# Here call your add_executable method 
# add_executable(TARGET_NAME ...) 

if(NOT MSVC) 
    find_package(Boost REQUIRED COMPONENTS date_time filesystem wserialization system serialization thread regex) 

    if (Boost_FOUND) 
     include_directories(${Boost_INCLUDE_DIRS}) 
     target_link_libraries(TARGET_NAME ${Boost_LIBRARIES}) 
    endif() 
endif() 

あなたはいつかブーストを見つけるfind_package支援するBoost_USE_STATIC_LIBSBoost_USE_MULTITHREAD変数を指定する必要があります。

また、ブーストライブラリの正しいパスをset(BOOST_ROOT, $path)と指定してください。さらに、find_packageに必要なboostパッケージを指定してください。インスタンス

find_package(Boost REQUIRED COMPONENTS date_time filesystem thread regex)

のためにあなただけのdate_timefilesystemthreadregexパッケージ

が必要な場合

、それはあなたのために働くかどう私に知らせてください。

+0

ええ、申し訳ありません、私はちょうどそれを取得し、テストしていた:)助けてくれてありがとう! – Afflicted

関連する問題