c++godbolt

How to generate a multi-file godbolt project from scratch?


So from the reddit post, I got to https://godbolt.org/z/WseTsM8YG and I decided I'd try my hand at making a multi-file project on godbolt from scratch. However, something seems to be wrong. My project: https://godbolt.org/z/7asGz3Wov

Seems that main.cpp can't see the header.h file for some reason. I added each file separately, and they appear to be in the same directory as shown here: shows main.cpp and the project where it and header.h reside

I even attempted to add the current directory to the include list (which shouldn't be necessary) with the -I. command line switch. Not surprisingly, it didn't work.

My original CMakeLists.txt file:

cmake_minimum_required(VERSION 3.5)

project(main.exe VERSION 1.0 LANGUAGES CXX)

add_executable(main main.cpp source1.cpp source2.cpp)

I then changed to align with the reddit example:

cmake_minimum_required(VERSION 3.5)

#project(main.exe VERSION 1.0 LANGUAGES CXX)

add_executable(main main.cpp source1.cpp source2.cpp)

target_link_libraries(main)

That didn't do anything either.

It would appear the files are not located in the same directory. What magic am I missing to do that?


Solution

  • The compiler tab you have open does not use your Multifile CMake setup.

    In the Tree View, you need to click on "Add new" and then "Execution only". This will trigger the execution of cmake --build with the given cmake options. It will also tell you all the other things that still need fixing (your code doesn't compile).

    In addition, your target_link_libraries does nothing, since you don't specify any libraries to link to.

    See here: godbolt.org/z/1Woeo6x9E.