#MY CMAKE DOESN'T WORK

22 messages · Page 1 of 1 (latest)

earnest thistle
#

So I got this project for wxwidgets
I use cmake with vscode
Here is my cmake file I use:

cmake_minimum_required(VERSION 3.10)
project(Platformer VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

file(GLOB RESOURCE_SOURCES "src/*.cpp")

add_executable(Platformer ${RESOURCE_SOURCES})

# Add hdrs directory to include path so #include <main.h> works
target_include_directories(Platformer PUBLIC "${PROJECT_SOURCE_DIR}/hdrs")

find_package(wxWidgets REQUIRED COMPONENTS net core base)
if(wxWidgets_USE_FILE)
    include(${wxWidgets_USE_FILE})
endif()
target_link_libraries(Platformer ${wxWidgets_LIBRARIES})

Here is my presets file:

{
    "version": 8,
    "configurePresets": [
        {
            "name": "GCC 14.2.0 x86_64-linux-gnu",
            "displayName": "GCC 14.2.0 x86_64-linux-gnu",
            "description": "Using compilers: C = /usr/bin/gcc, CXX = /usr/bin/g++",
            "binaryDir": "${sourceDir}/out/build/${presetName}",
            "cacheVariables": {
                "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
                "CMAKE_C_COMPILER": "/usr/bin/gcc",
                "CMAKE_CXX_COMPILER": "/usr/bin/g++",
                "CMAKE_BUILD_TYPE": "Debug"
            }
        }
    ]
}

the folder structure is that there is a hdrs and src folder which contains the headers and the source files
When I make a new file named main.cpp and one named main.h in their respective folders
It says that main.h cannot be found HOWEVER it is there and the intelisense even detects it
it wont compile I cleaned and rebuilded the cmake many times
But when u rename it It works (main.h and main.cpp to App.h and App.cpp for example)
ANY OTHER FILE OTHER THAN THE MAIN.h and MAIN.cpp works
(Also by compiling it errors too)
Here is the error

main.h: No such file or directory

It is a wxwidgets project btw
And I used the official guide for the cmake (vscode)

covert obsidianBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

earnest thistle
analog arch
#

You typically never create a file called main.h, header/source file separation doesn't apply to the function containing int main()

earnest thistle
#

I think its something like WinMain in wxwidgets
is that the same?

earnest thistle
#

wdym by seperation?\

ashen kelp
#

Try changing target_include_directories(...) to just include_directories(...) and do it before the call to add_executable

earnest thistle
ashen kelp
analog arch
# earnest thistle wdym seperation doesn't apply?

You put all the functions and classes in 1 file (not separated by declaration and definition). Maybe you could still teeecchnically separate it as long as you keep int main() in the .cpp file only (not 100% sure that works) but it's unconventional

earnest thistle
#

thanksssss

#

!solved

covert obsidianBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

ashen kelp
#

Solved how

ashen kelp
earnest thistle
#

the fix is to change the file name
the thing u said didn't work 😭 unfortunately

#

I changed it to App.h and App.cpp

ashen kelp
#

But why does that work

earnest thistle
ashen kelp
#

Thats usually the case yes

#

There is no sense in declaring the main function