0

I've got an issue with the CMakeLists.txt file: I'm trying to build a C++ project made with VisualStudio inside CMake, so I've created all the necessaries files. While the "configure" command works well inside the cmake-gui screen, the "generate" command gives me the error: "CMake Error: CMake can not determine linker language for target: Lab2". My visual studio file only has one .cpp files, no headers, and one pic that I'm using inside the cpp file.

What I've written inside the CmakeLists.txt file is the following:

cmake_minimum_required(VERSION 3.9)

# set the project name
project(Lab2)

# add the executable
add_executable(Lab2 source.cpp)

The name of the folder on the desktop is "Lab2" and inside there are the "source", "build", "data", "include" directories. Inside the "source" there are both source.cpp file and "Lab2.cpp.txt" files.

What is wrong? Thank you so much!

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
Albeh95
  • 1
  • 1
  • 3
    Btw. if `source.cpp` is actually stored in `source/source.cpp` (relative to the location of the `CMakeLists.txt` file) then you have to tell CMake so. It won't actually look into sub-directories automatically. Concerning your include dir it might be necessary to add this also to the defaults. Please, note the `include_directories("${CMAKE_SOURCE_DIR}")` I used in the above linked sample to make the source directory as a default include (although I didn't need it in my sample). – Scheff's Cat May 09 '20 at 11:41
  • 1
    @Scheff thank you! it worked, I had to replace source.cpp with source/source.cpp :) – Albeh95 May 09 '20 at 11:48
  • 1
    That means that the **first error** message shown by CMake was `Cannot find source file`. And the error you show us - `can not determine linker language` - is just a **consequence** of the first error. When debug a problem, always take a look into the **first** error/warning message: all other errors could just be a result of the first one. – Tsyvarev May 09 '20 at 12:27

0 Answers0