0

I'm starting a new C++ project and thought it would be a good time to try and learn CMake in the process. So I tried to set up everything so that my JobScheduler project would be a library that I would use in the test run. You can see below my different CMakeLists:

Top level folder CMakeLists

cmake_minimum_required(VERSION 3.2)
project(JobScheduler 
        VERSION 1.0
        LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_subdirectory(Tests)
add_subdirectory(JobScheduler)

"Tests" folder CMakeLists

cmake_minimum_required(VERSION 3.2)

add_executable (JobSchedulerDemo main.cpp)

target_link_libraries (JobSchedulerDemo LINK_PUBLIC JobSchedulerLib)

"JobScheduler" folder CMakeLists

cmake_minimum_required(VERSION 3.2)

add_library(JobSchedulerLib test.h)
set_target_properties(JobSchedulerLib PROPERTIES LINKER_LANGUAGE C++)

target_include_directories (JobSchedulerLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

But when I try to generate I have these 2 errors:

1> [CMake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
1> [CMake] Missing variable is:
1> [CMake] CMAKE_C++_ARCHIVE_CREATE
1> [CMake] CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
1> [CMake] Missing variable is:
1> [CMake] CMAKE_C++_ARCHIVE_FINISH

I tried to google it without success. Can anyone helps?

Maeglix
  • 33
  • 4
  • 3
    Instead of `LINKER_LANGUAGE C++` it should be `LINKER_LANGUAGE CXX`: In CMake variables C++ compiler is encoded as `CXX`, like you do in the `project()` call. – Tsyvarev Nov 02 '22 at 13:09
  • It worked indeed. The funny part is that I copy pasted this line to solve a previous CMake error. I should have payed more attention to it. Thanks a lot! – Maeglix Nov 02 '22 at 13:13
  • Now CMake runs perfectly, but I have a LNK1104 when I try to compile. It doesn't find JobScheduler\JobSchedulerLib.Lib. Any idea @Tsyvarev? – Maeglix Nov 02 '22 at 13:36
  • 1
    Try: `add_library(JobSchedulerLib INTERFACE test.h)` and change `PUBLIC` to `INTERFACE` and remove `LINKER_LANGUAGE` line. – KamilCuk Nov 02 '22 at 13:40
  • 2
    With `add_library(JobSchedulerLib test.h)` you define a library with **no sources**, so there is nothing to compile into `.lib` file. If you want to create a target for **header only** library, then see [that question](https://stackoverflow.com/questions/60604249/how-to-make-a-header-only-library-with-cmake). – Tsyvarev Nov 02 '22 at 13:40

0 Answers0