Search code examples
c++cmakeremote-debuggingclion

How to build my project with Clion Remote?


I successfully set up a remote project in CLion. It recognizes the compiler and everything on the remote host and also synchronizes changes.
Now to my problem:
When I try to build and run the project it gives me an error that it can't find a certain lib:

fatal error: Eigen/SparseCore: No such file or directory
 #include <Eigen/SparseCore> 

But when I log into the server via ssh I can go to the synced directory, run make and it compiles with no errors. I can then run the compiled app no problem.

Here's the CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(projectName)

set(CMAKE_CXX_STANDARD 14)

include_directories(/usr/local/PRIV)
include_directories(/usr/local/PRIV/Includes)
include_directories(/usr/local/PRIV/Includes/SubDir)
include_directories(/usr/local/PRIV/Includes/SubDir/eigen3)
include_directories(/usr/local/PRIV/Includes/SubDir/eigen3/Eigen/)
include_directories(/usr/local/PRIV/Includes/SubDir/qhull)

add_executable(
        Example/MyTopTen/Makefile
        Example/MyTopTen/MyTopTen.cc
        Example/MyTopTen/MyTopTen.h
        Example/MyTopTen/Readme.txt
        Example/Makefile
        Example/Example.cc
        )

I'm very new to cmake projects and Stackoverflow so if I can improve this question just let me know!


Solution

  • Please follow Eigen guide how to use it with CMake https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html

    In this case your CMakeLists.txt should looks like

    cmake_minimum_required(VERSION 3.10)
    project(projectName)
    
    set(CMAKE_CXX_STANDARD 14)
    
    find_package (Eigen3 3.3 REQUIRED NO_MODULE)
    include_directories(${EIGEN3_INCLUDE_DIR})
    
    add_executable(myTargetName
            Example/MyTopTen/MyTopTen.cc
            Example/MyTopTen/MyTopTen.h
            Example/Example.cc
            )
    target_link_libraries (myTargetName Eigen3::Eigen)
    

    After that Reload CMake project in CLion via Tools | CMake | Reset Cache and Reload Project.