简体   繁体   English

Mac Os Visual Studio 代码 C++ Opengl Glad Glew

[英]Mac Os Visual Studio Code C++ Opengl Glad Glew

Link Project https://github.com/nio74/templateGLad链接项目https://github.com/nio74/templateGLad

Good day, I try Run Opengl app with glew and glad in Visual Studio Code(I wanted to use this Ide because it is multi platform but if you have any good suggestions it is welcome), but have this error:美好的一天,我在 Visual Studio Code 中尝试使用 glew 运行 Opengl 应用程序并很高兴(我想使用这个 Ide 因为它是多平台的,但如果你有任何好的建议,欢迎它),但是有这个错误:

 > Executing task: C/C++: clang++ build active file <

Starting build...
Build finished with error:

Undefined symbols for architecture x86_64:
  "_gladLoadGLLoader", referenced from:
      _main in HelloWorld-22d65f.o 

My tasks.json:我的任务.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-g",
                "${workspaceFolder}/src/HelloWorld.cpp",
                "-o",
                "${workspaceFolder}",
                "-I", "${workspaceFolder}/include/",
                //"${workspaceFolder}/glad.c",
                "-lglfw",
                "-lglew"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/clang++"
        }
    ]
}

Updating, doing various research I managed to make it work, but I have some things to understand:更新,做各种研究我设法让它工作,但我有一些事情要理解:

I can't understand the variables in tasks.Json我无法理解 tasks.Json 中的变量

(

"--include-directory = include /",
"--include-directory = build /",
"--include = include / glad.c",

) )

I tried to replace them with those suggested by the official guide (我试图用官方指南建议的替换它们(

"$ {workspaceFolder} / include",
"$ {workspaceFolder} / build",
"$ {fileDirname} /include/glad.c",

) but they don't work. ) 但它们不起作用。

tasks.json:任务.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "HelloWorld",
            "type": "che",
            "command": "clang++",
            "args": [
            
                
                "-std=c++17",
                "-stdlib=libc++",
                "-lglfw",
                "-lglew",
                "--include-directory=include/",
                "--include-directory=build/",
                "--include=include/glad.c",
                //"${workspaceFolder}/include",
                //"${workspaceFolder}/build",
                //"${fileDirname}/include/glad.c",
                
                "-framework",
                "OpenGL",
                "-framework",
                "IOKit",
                "-framework",
                "Cocoa",
                "src/helloworld.cpp",
                "-o",
                "build/helloworld",
                "--debug"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]

}

launch.json启动.json

    "version": "0.2.0",
    "configurations": [
               
        {
            "name": "(lldb) Launch",
            "preLaunchTask": "HelloWorld",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/helloworld",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
                "externalConsole": true,
                "MIMode": "lldb",
                
        }
    ]
}

c_cpp_properties.json c_cpp_properties.json

    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/src/",
                "${workspaceFolder}/include/",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x86",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "compilerArgs": [
                "-lglfw",
                "-lglew"
            ]
        }
    ],
    "version": 4
}

Git: Git:

https://github.com/nio74/templateGLad https://github.com/nio74/templateGLad

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM