[SOLVED] Target link Eigen library on Clion fails

Issue

This Content is from Stack Overflow. Question asked by Bmk95

I am trying to link eigen to my project on clion, but the following error is printed:

This is my cmakelist file with all the attempts to link the library:

cmake_minimum_required(VERSION 2.8.3)
project(planner_standalone_grasp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-diagnostics-color")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# find all cpp files in currect directory (where CMakeLists.txt is)
file(GLOB SOURCE_FILES FILES_MATCHING PATTERN "./src/*.cpp")


include_directories(src)


add_executable(${PROJECT_NAME} main.cpp ${SOURCE_FILES})
add_executable(${PROJECT_NAME}_snap main_snap.cpp ${SOURCE_FILES})
add_executable(${PROJECT_NAME}_multi main_multicore.cpp ${SOURCE_FILES})

set(EXE_LIBS
    ctop_common
    ctop_log
    ctop_util

    eigen
    crl
    crl-algorithm
    crl-loader
    crl-tsplib
    yaml-cpp
)


target_link_directories(${PROJECT_NAME} PUBLIC lib/comrob/lib/)
target_link_directories(${PROJECT_NAME} PUBLIC ctop/common/cmake-build-debug/)
target_link_directories(${PROJECT_NAME} PUBLIC ctop/log/cmake-build-debug/)
target_link_directories(${PROJECT_NAME} PUBLIC ctop/util/cmake-build-debug/)


set(EIGEN_DIR "/usr/local/include/Eigen/")
include_directories(${EIGEN_DIR})


find_package (Eigen3 3.3 REQUIRED NO_MODULE)
target_link_libraries (${PROJECT_NAME} Eigen3::Eigen)

target_link_directories(${PROJECT_NAME} PUBLIC lib/eigen/Eigen/)
target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/include/Eigen/)
target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/include/eigen3/Eigen/)


target_link_libraries(${PROJECT_NAME} ${EXE_LIBS})
target_link_libraries(${PROJECT_NAME}_snap ${EXE_LIBS})
target_link_libraries(${PROJECT_NAME}_multi ${EXE_LIBS})

All other libraries in the project are successfully linked except Eigen – This is the error message:

[6/6] Linking CXX executable planner_standalone_grasp
FAILED: planner_standalone_grasp 
: && /usr/bin/c++ -O0 -fno-diagnostics-color -std=c++17 -g -rdynamic CMakeFiles/planner_standalone_grasp.dir/main.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/Grasp.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/WallEdge.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/WallGraph.cpp.o CMakeFiles/planner_standalone_grasp.dir/src/pt2eigen.cpp.o -o planner_standalone_grasp -L/home/sim/CLionProjects/Test/lib/comrob/lib   -L/home/sim/CLionProjects/Test/ctop/common/cmake-build-debug   -L/home/sim/CLionProjects/Test/ctop/log/cmake-build-debug   -L/home/sim/CLionProjects/Test/ctop/util/cmake-build-debug   -L/home/sim/CLionProjects/Test/lib/eigen/Eigen   -L/usr/local/include/Eigen   -L/usr/local/include/eigen3/Eigen -Wl,-rpath,/home/sim/CLionProjects/Test/lib/comrob/lib:/home/sim/CLionProjects/Test/ctop/common/cmake-build-debug:/home/sim/CLionProjects/Test/ctop/log/cmake-build-debug:/home/sim/CLionProjects/Test/ctop/util/cmake-build-debug:/home/sim/CLionProjects/Test/lib/eigen/Eigen:/usr/local/include/Eigen:/usr/local/include/eigen3/Eigen  -lctop_common  -lctop_log  -lctop_util  -leigen  -lcrl  -lcrl-algorithm  -lcrl-loader  -lcrl-tsplib  -lyaml-cpp && :
/usr/bin/ld: cannot find -leigen
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Any help would be highly appreciated!



Solution

In my experience there is two possible causes for this issue:

  1. there is no library named libeigen. in the provided directories (the ones in target_link_directories). Perhaps the path is wrong?
    You should know that usually library files are not located in the include directories of a repository…
  2. there is a library named as such, though it was compiled for the wrong platform… i.e. a library compiled for linux cannot be linked if you are making an executable for windows. Usually you can find the source code and compile it yourself.

Hope this helps.


This Question was asked in StackOverflow by Bmk95 and Answered by Plegeus It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?