I have been trying to set up SDL2 on a WSL (Ubuntu) and cross compile to windows using cmake and mingw. I ran into this problem where it fails trying to compile the library files themselves:
In file included from /usr/include/SDL2/SDL_stdinc.h:31,
from /usr/include/SDL2/SDL_main.h:25,
from /usr/include/SDL2/SDL.h:32,
from /mnt/c/users/user/repos/project/final.cpp:5:
/usr/include/SDL2/SDL_config.h:4:10: fatal error: SDL2/_real_SDL_config.h: No such file or directory
4 | #include <SDL2/_real_SDL_config.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Here is my CmakeLists.txt
cmake_minimum_required(VERSION 3.12.4) # CMake version check
project(name)
set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${name_SOURCE_DIR}/CMakePath")
SET(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)t
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(SOURCE_FILES final.cpp Soldier.cpp TilesEnum.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --static -std=c++0x -o test")
#add_executable(${PROJECT_NAME} src/test.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR})
target_link_libraries(name ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES})
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc")
My running theory so far is I installed the wrong library, but that doesn't explain why it wouldn't compile at all. I am very lost. I couldn't find anything with this specific problem, please link me to something similar if there is.
There are many things wrong with this CMake file with a lot of repeated code. Tsyvarev's comment helped fix this a lot.