0

We have been given a C++ group project, and we've been given the completed project in .o format too, so as we work over the break we can test the individual parts we are working on.

I'm using CLion and I'd like to firstl compile the whole project from the object files to see how it works and from there I should be able to remove the .o files I am working on and include my own .h/.cpp versions.

Can someone tell me how to write the CMakeLists.txt, or at least tell me what to read? I couldn't find any specific documentation, and I don't know where to start.

**edit I had a look at the other solution mentioned in the duplicate, but implementing that didn't work, I still needed to set the target properties. Possibly down to the object files being created with a different piece of software?

Weaver
  • 145
  • 8
  • 1
    Just list the object files with the [`add_executable`](https://cmake.org/cmake/help/v3.14/command/add_executable.html) CMake command. – Some programmer dude Mar 29 '19 at 12:17
  • I did actually try that as a wild guess to start, I got `CMake Error: CMake can not determine linker language for target: myProject CMake Error: Cannot determine link language for target "myProject".` – Weaver Mar 29 '19 at 12:27
  • 1
    Add a language in the [`project`](https://cmake.org/cmake/help/v3.14/command/project.html) command. Or use [`set_target_property`](https://cmake.org/cmake/help/v3.14/command/set_target_properties.html) to set the [`LINKER_LANGUAGE`](https://cmake.org/cmake/help/v3.14/prop_tgt/LINKER_LANGUAGE.html) property on the executable target. – Some programmer dude Mar 29 '19 at 12:31

1 Answers1

2

Thanks to Some programmer dude I got it working. I'll write it out here for clarity.

First I added all the .o files in the add_executable. After that I added the language in the project command but it didn't work, still had the

CMake Error: CMake can not determine linker language for target: myProject  
CMake Error: Cannot determine link language for target "myProject" 

so I added set_target_properties. First the project name, then PROPERTIES then the thing I wanted to set: LINKER_LANGUAGE, then the language.

My file ended up looking like this:

cmake_minimum_required(VERSION 3.12)
project(myProject)

set(CMAKE_CXX_STANDARD 14)

add_executable(myProject
        first.o
        second.o
        third.o
        fourth.o)

set_target_properties(myProject PROPERTIES LINKER_LANGUAGE CXX )
Weaver
  • 145
  • 8