-1

The error I have is :

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

I have included the --std=c++11 tag in CMakeLists.txt Here is the 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})

I dont understand the problem here. Boost and MLPack (required in the code) are properly installed. Also i have used the --std=c++11 tag that was the solution to this problem in previous answers. How do I fix this problem?

Edit: Output of verbose 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

The project tree is (if its relevant) :

.
├── cmake
│   └── FindMLPACK.cmake
├── CMakeLists.txt
└── source
    ├── CMakeLists.txt
    ├── HMMEval.h
    ├── HMMExperiments.h
    ├── hmm.h
    ├── hmm_impl.h
    ├── HMMPredict.h
    ├── HMMTrain.h
    └── main.cpp
coatless
  • 20,011
  • 13
  • 69
  • 84
  • Don't see any Boost library in the linker's command line (while MLPACK presents). What is content of `Boost_LIBRARIES` variable when you link with it? (you may use message() command for output content of variable during `cmake` stage). – Tsyvarev Sep 15 '16 at 07:51
  • I used this command in cmake : `MESSAGE(STATUS ${Boost_LIBRARIES})`, it doesnt give any output. Although boost is mentioned as being available by cmake before. – salander_lisbeth Sep 15 '16 at 08:08
  • Weird. Looks like improper `FindBoost.cmake` script has been executed via `find_package(Boost)`. Is any Boost-related variable (contained "Boost" or "BOOST") exists in the CMake cache (file `CMakeCache.txt` in the build directory)? (variable `Boost_LIBRARIES` itself may be absent in the cache, this is normal behavior). – Tsyvarev Sep 15 '16 at 08:47

2 Answers2

1

Although you are calling find_package(Boost REQUIRED), you are not specifying any components of Boost to be found, so ${Boost_LIBRARIES} ends up containing nothing, and even though you specify

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

it doesn't work. So the solution is to add the required components of Boost to the call to find_package():

find_package(Boost COMPONENTS program_options REQUIRED)

Ideally I think that your CMake script FindMLPACK.cmake should find the Boost dependencies too and append them to ${MLPACK_LIBRARIES}, but that is a different issue.

ryan
  • 839
  • 4
  • 13
  • It is present there in the cmake. – salander_lisbeth Sep 30 '16 at 15:28
  • I'm sorry, I didn't scroll down. In this case I think that your FindBoost call is wrong. Try this: `find_package(Boost COMPONENTS program_options REQUIRED)`. – ryan Sep 30 '16 at 15:30
  • I will edit my answer and clarify what was needed... if this solved your problem, it would be a good idea to mark the answer as correct for future people with the same problem. – ryan Sep 30 '16 at 15:32
-1

according to this question, have you tried to link with the bost libraries after the MLPack ones?
I believe you could do it by permuting the last two lines in your cmake file.

MayeulC
  • 1,628
  • 17
  • 24
  • OK, is there a way you could display the ld parameters? – MayeulC Sep 15 '16 at 06:38
  • I dont know how to get the ld parameters when I am using cmake. How would I get them? – salander_lisbeth Sep 15 '16 at 07:05
  • The error seems to be with the linker invocation: `error: ld returned 1 exit status`. By using a verbose compiling mode, you should be able to see the full `ld` command line, which would help for debugging. You might be able to do so by following [these instructions](https://cmake.org/Wiki/CMake_FAQ#Is_there_an_option_to_produce_more_.27verbose.27_compiling.3F). Basically, setting `CMAKE_VERBOSE_MAKEFILE` to `ON` – MayeulC Sep 15 '16 at 07:07