Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake /w Ninja generates build files but no executable

Tags:

c++

cmake

ninja

My first time attempt at CMake and I need some help

CMake /w Ninja & clang++ generates build files but no executable

/CMakeLists.txt

cmake_minimum_required(VERSION 3.17)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

project(Example)

include(find_compiler)

add_subdirectory(src)

src/CMakeLists.txt

add_executable(Example main.cpp)

I'm not sure what to do. Thank you.

like image 446
animeinabox Avatar asked Oct 27 '25 09:10

animeinabox


1 Answers

The primary purpose fo CMake is to create all the build-related files needed to create your executable (i.e. to configure build system), not to build it, so the behaviour you are experiencing is expected.

(I suppose you used Ninja generator, i.e. you executed cmake with -G Ninja as one of the parameters)

In order to actually build your executable, you must execute ninja, after successful configuration (i.e. successful run of cmake):

$ cd build_folder
$ cmake -G Ninja source_folder
$ ninja

if everything goes well, you should have Example executable in you build folder.

You can also initiate actual building using CMake using following set fo commands:

$ cd build_folder
$ cmake -G Ninja source_folder
$ cmake --build .

cheers,

like image 145
gordan.sikic Avatar answered Oct 28 '25 23:10

gordan.sikic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!