簡體   English   中英

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

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

鏈接項目https://github.com/nio74/templateGLad

美好的一天,我在 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 

我的任務.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++"
        }
    ]
}

更新,做各種研究我設法讓它工作,但我有一些事情要理解:

我無法理解 tasks.Json 中的變量

(

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

)

我試圖用官方指南建議的替換它們(

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

) 但它們不起作用。

任務.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": []
        }
    ]

}

啟動.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

    "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:

https://github.com/nio74/templateGLad

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM