私はエラーがある:ここCMakeLists.txt で--std = C++ 11のタグを含んでいリンカーエラー:G ++ 5.4のUbuntu 16.04
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.58.0
-- Found MLPACK: /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cortana/ClionProjects/hmmClassification/build
Scanning dependencies of target hmm
[ 50%] Building CXX object CMakeFiles/hmm.dir/source/main.cpp.o
[100%] Linking CXX executable hmm
/usr/bin/ld: CMakeFiles/hmm.dir/source/main.cpp.o: undefined reference to symbol '_ZN5boost15program_options3argB5cxx11E'
//usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.58.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hmm.dir/build.make:95: recipe for target 'hmm' failed
make[2]: *** [hmm] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/hmm.dir/all' failed
make[1]: *** [CMakeFiles/hmm.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2
はcmakeのです:
cmake_minimum_required(VERSION 3.3)
project(hmm)
set(PROJECT_VERSION "0.0.1")
# Default configuration values. These must be before the project command or
# they won't work in Windows.
# If no build type is specified, default to "Release"
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"None Debug Release RelWithDebInfo MinSizeRel"
FORCE)
endif()
# Install to "dist" directory in Windows for testing and as a staging directory
# for the installer.
if (WIN32 AND NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX dist CACHE STRING "Install path prefix.")
endif()
if (NOT MSVC)
# Enable the C++11 standard
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11)
endif()
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost REQUIRED)
find_package(MLPACK REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(${Boost_DEFINITIONS})
include_directories(${MLPACK_INCLUDE_DIRS})
link_directories(${MLPACK_LIBRARY_DIRS})
add_definitions(${MLPACK_DEFINITIONS})
# Global CMake options
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
# Testing configuration
enable_testing()
#add_subdirectory(source)
file(GLOB SOURCE_FILES
source/main.cpp)
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${CMAKE_PROJECT_NAME}
${Boost_LIBRARIES}
${MLPACK_LIBRARIES})
私はこの問題をここでは理解していません。 BoostとMLPack(コードに必要)が正しくインストールされています。また、以前の回答でこの問題の解決策である--std = C++ 11タグを使用しました。この問題を解決するにはどうすればよいですか?
編集:冗長cmakeのの 出力:
/usr/bin/c++ -I/home/cortana/ClionProjects/hmmClassification/build -I/home/cortana/ClionProjects/hmmClassification -I/usr/local/include -std=c++11 -std=c++11 -g -o CMakeFiles/hmm.dir/source/main.cpp.o -c /home/cortana/ClionProjects/hmmClassification/source/main.cpp
[100%] Linking CXX executable hmm
/usr/bin/cmake -E cmake_link_script CMakeFiles/hmm.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 -std=c++11 -g CMakeFiles/hmm.dir/source/main.cpp.o -o hmm -L/usr/local/lib -rdynamic /usr/local/lib/libmlpack.so -Wl,-rpath,/usr/local/lib
/usr/bin/ld: CMakeFiles/hmm.dir/source/main.cpp.o: undefined reference to symbol '_ZN5boost15program_options3argB5cxx11E'
//usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.58.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hmm.dir/build.make:98: recipe for target 'hmm' failed
make[2]: *** [hmm] Error 1
make[2]: Leaving directory '/home/cortana/ClionProjects/hmmClassification/build'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/hmm.dir/all' failed
make[1]: *** [CMakeFiles/hmm.dir/all] Error 2
make[1]: Leaving directory '/home/cortana/ClionProjects/hmmClassification/build'
Makefile:97: recipe for target 'all' failed
make: *** [all] Error 2
(その関連する場合)プロジェクトツリーがある:
.
├── cmake
│ └── FindMLPACK.cmake
├── CMakeLists.txt
└── source
├── CMakeLists.txt
├── HMMEval.h
├── HMMExperiments.h
├── hmm.h
├── hmm_impl.h
├── HMMPredict.h
├── HMMTrain.h
└── main.cpp
MLPACKが表示されている間、リンカのコマンドラインにBoostライブラリが表示されません。 'Boost_LIBRARIES'変数にリンクするときの内容は何ですか? ( 'cmake'の段階で変数の内容を出力するのにmessage()コマンドを使うことができます)。 – Tsyvarev
cmake: 'MESSAGE(STATUS $ {Boost_LIBRARIES})'でこのコマンドを使用しましたが、出力がありません。 boostは前にcmakeによって利用可能であると述べられているが。 –
奇妙な。不適切な 'FindBoost.cmake'スクリプトが' find_package(Boost) 'によって実行されたようです。 Boost関連の変数( "Boost"または "BOOST"が含まれています)はCMakeのキャッシュにありますか(ビルドディレクトリの 'CMakeCache.txt'ファイル)ですか? (変数 'Boost_LIBRARIES'自体がキャッシュに存在しない可能性がありますが、これは正常な動作です)。 – Tsyvarev