-1

我的错误是:

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

我在 CMakeLists.txt 中包含了 --std=c++11 标记这是 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
4

2 回答 2

1

尽管您正在调用find_package(Boost REQUIRED),但您没有指定要找到的任何 Boost 组件,因此${Boost_LIBRARIES}最终什么都不包含,即使您指定了

  target_link_libraries(hmm
    ${MLPACK_LIBRARIES}
    ${Boost_LIBRARIES})

它不起作用。所以解决方案是将Boost所需的组件添加到调用中find_package()

find_package(Boost COMPONENTS program_options REQUIRED)

理想情况下,我认为您的 CMake 脚本FindMLPACK.cmake也应该找到 Boost 依赖项并将它们附加到${MLPACK_LIBRARIES},但这是一个不同的问题。

于 2016-09-30T15:26:07.640 回答
-1

根据这个问题,您是否尝试在 MLPack之后与 bost 库链接?
我相信您可以通过排列 cmake 文件中的最后两行来做到这一点。

于 2016-09-15T06:04:16.480 回答