所以, 我尝试在C ++项目(在 Visual Studio代码中)上使用 SDL2库。我使用 Mingw 进行编译,但仍然出现错误:
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
我有以下任务来构建我的项目(在mingw文件夹中包含SDL库):
{
// 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"
}
]
}
我也尝试以下方法:
{
// 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在 include路径中正常工作:“ D:/Path/SDL2-2.0.8/i686-w64-mingw32/include”。 我看不到我在哪里想念什么:I
答案 0 :(得分:0)
我遇到了问题,显然 mingw 标志的顺序很重要(未找到为什么要思考):
"args": [
"-Wall",
"-g","main.cpp",
"-o","main.exe",
"-lmingw32",
"-lSDL2main",
"-lSDL2"
],
或带有路径(-I表示include,-L表示库)