I try to set up a make file to compile my SDL2 code, but I can't do the linking properly. I used SDL i686-w64-mingw32.
g++ version:
g++ --version
g++ (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
My compiler errors:
g++ -std=c++17 -Wall -lmingw32 -lSDL2main -lSDL2 -Iinclude -Llib src/main.cpp -o build/debug/game
C:\Users\alexa\AppData\Local\Temp\ccYmVMso.o:main.cpp:(.text+0xe): undefined reference to `SDL_Init'
C:\Users\alexa\AppData\Local\Temp\ccYmVMso.o:main.cpp:(.text+0x1c): undefined reference to `SDL_GetError'
collect2.exe: error: ld returned 1 exit status
Makefile:12: recipe for target 'all' failed
make: *** [all] Error 1
My make file
SRC_DIR = src
BUILD_DIR = build/debug
CC = g++
SRC_FILES = ${wildcard ${SRC_DIR}/*.cpp}
OBJ_NAME = game
INCLUDE_PATHS = -Iinclude
LIBRARY_PATHS = -Llib
COMPILER_FLAGS = -std=c++17 -Wall
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2
all:
$(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) -o $(BUILD_DIR)/$(OBJ_NAME)
My folder structure
D:.
├───.vscode
├───build
│ └───debug
├───gfx
│ ├───assets
│ └───particles
├───include
│ └───SDL2
├───lib
│ ├───cmake
│ │ └───SDL2
│ └───pkgconfig
└───src
My C++ code
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char** argv) {
if(SDL_Init(SDL_INIT_EVERYTHING) > 0) {
printf("[ERROR]: SDL initialization has failed (ERROR CODE: %s)", SDL_GetError());
return EXIT_FAILURE;
} else printf("[INFO]: SDL was initialized with success.\n");
return EXIT_SUCCESS;
}