So, I try to use the SDL2 library in a C++ project (on Visual Studio Code). I use Mingw to compilate, but I keep having error :
D:\Path/View/View.cpp:20: undefined reference to `SDL_Init'
D:\Path/View/View.cpp:21: undefined reference to `SDL_CreateWindow'
D:\Path/View/View.cpp:22: undefined reference to `SDL_CreateRenderer'
D:\Path/View/View.cpp:25: undefined reference to `SDL_GetError'
l:/common/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
I have the following task to build my project (With the SDL library include in mingw folder):
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-Wall",
"-g","main.cpp",
"-o","main.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc"
}
]
}
I also try the following :
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-Wall",
"-I","D:/Path/SDL2-2.0.8/i686-w64-mingw32/include",
"-L","D:/Path/SDL2-2.0.8/i686-w64-mingw32/lib",
"-lSDL2main",
"-lSDL2",
"-g","main.cpp",
"-o","main.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc"
}
]
}
Intellisense work fine with the include path : "D:/Path/SDL2-2.0.8/i686-w64-mingw32/include". I dont see where I miss something :I