0

I am using CLion to write a Cmake project. here is the tree view of the directory(files are ignored),where lemon-1.3-1 is the third party library.

├── cmake-build-debug
│   ├── CMakeFiles
│   │   ├── 3.15.3
│   │   │   ├── CompilerIdC
│   │   │   │   └── tmp
│   │   │   └── CompilerIdCXX
│   │   │       └── tmp
│   │   ├── CheckTypeSize
│   │   ├── CMakeTmp
│   │   ├── graph_partition_essay.dir
│   │   └── Progress
│   └── lemon-1.3.1
│       ├── cmake
│       ├── CMakeFiles
│       │   ├── check.dir
│       │   └── dist.dir
│       └── lemon
│           └── CMakeFiles
│               └── lemon.dir
│                   └── bits
└── lemon-1.3.1
    ├── cmake
    │   └── nsis
    ├── contrib
    ├── demo
    ├── doc
    │   ├── html
    │   │   └── search
    │   └── images
    ├── lemon
    │   ├── bits
    │   └── concepts
    ├── scripts
    ├── test
    └── tools

Also I write the following CMakeLists.txt. Using this file, the auto code completion can function normally.

cmake_minimum_required(VERSION 3.15)
project(graph_partition_essay)

set (LEMON_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/lemon-1.3.1)
add_subdirectory(lemon-1.3.1)
add_executable(graph_partition_essay main.cpp)

and the main.cpp

#include <iostream>
#include "lemon-1.3.1/lemon/list_graph.h"

using namespace lemon;
int main() {
    ListDigraph g;
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

But when I run the main function, I got the following error message.

In file included from F:\xxx\graph_partition_essay\main.cpp:2:
F:\xxx\graph_partition_essay\lemon-1.3.1/lemon/list_graph.h:26:10: fatal error: lemon/core.h: No such file or directory
   26 | #include <lemon/core.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

How can I fix this problem?

rici
  • 234,347
  • 28
  • 237
  • 341
syheliel
  • 151
  • 1
  • 7
  • Usually you install a library first, and then create another project for the executable and use installed library there. – arrowd Feb 04 '21 at 07:04
  • You don't need to create a full build script. You just need to create an imported target (recommended) or add the include dir, link dir and library name of your lemon installation. (this is all assuming there is no cmake configuration script provided by the lib; there may actually be something like this in the cmake dir; check first, if there's something `find_package` can understand). Issue in the output you posted could simply be solved by using `target_include_directories(graph_partition_essay PRIVATE ...include dirs go here...)` Linking will fail though. – fabian Feb 04 '21 at 18:50

0 Answers0