为什么vscode中的F5命令不能用OpenGL库编译C程序

问题描述 投票:0回答:0

我可以使用命令“g++ -o test -Wall test.c -mwindows glut32.lib -lopengl32 -lglu32”编译程序,但前提是所有存档都在项目文件夹中。我想使用 F5 命令编译程序,所以我尝试编辑 tasks.json 文件,但我可能搞砸了一些东西。

文件夹中的GLUT文件: 过剩32.dll, glut32.lib

C代码:

#include <windows.h>
#include "GL/glut.h"

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POLYGON);

glVertex2f(-0.3, -0.3);

glVertex2f(-0.3, 0.3);

glVertex2f(0.3, 0.3);

glVertex2f(0.3, -0.3);

glEnd();

glFlush();

}

int main(void) {

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutCreateWindow("Test");

glutDisplayFunc(display);

glutMainLoop();

}

task.json 文件:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:/MinGW/bin/gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "-Wall",
                "${file}",              
                "-o",
                "-mwindows",
                "-I${workspaceFolder}/glut32.lib",
                "-lopengl32",
                "-lglu32",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:/MinGW/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "compiler: C:/MinGW/bin/gcc.exe"
        }
    ]
}

如果有人知道如何正确设置它,请告诉我

c visual-studio-code opengl mingw glut
© www.soinside.com 2019 - 2024. All rights reserved.