【问题标题】:Mingw and SDL2 include (VS code)Mingw 和 SDL2 包括(VS 代码)
【发布时间】:2018-07-23 11:24:44
【问题描述】:

所以, 我尝试在 C++ 项目中使用 SDL2 库(在 Visual Studio Code 上)。我使用 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

我有以下任务构建我的项目(SDL 库包含在 mingw 文件夹中):

{
    // 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 与 包含路径 一起工作正常:“D:/Path/SDL2-2.0.8/i686-w64-mingw32/include”。 我没有看到我错过了什么:我

【问题讨论】:

    标签: c++ visual-studio-code mingw


    【解决方案1】:

    我得到了问题,显然 mingw 标志的顺序很重要(不知道为什么想):

    "args": [
        "-Wall",
        "-g","main.cpp",
        "-o","main.exe",
        "-lmingw32",
        "-lSDL2main",
        "-lSDL2"
    ],
    

    或者使用路径(-I 表示包含,-L 表示库)

    【讨论】:

      猜你喜欢
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      相关资源
      最近更新 更多