0

The problem seems to come from the failure of the executable to be linked to libglfw.3.3.dylib file. I downloaded glfw via homebrew and included the directory path (/opt/homebrew/lib) for the file in c_cpp_properties.json and tasks.json as the following: c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
                "/opt/homebrew/include",
                "/opt/homebrew/lib",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm"
        }
    ],
    "version": 4
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-g",
                "${file}",
                "-I/opt/homebrew/include", 
                "-L/opt/homebrew/lib",               
                "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
                "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include",
                "-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
                "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
                "-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
                "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
        
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

but could not get rid of the problem. Thanks for your help!

Update (error message and .zshrc)

Starting build...
/usr/bin/clang++ -g /Users/xiliu/Desktop/c++/ray_tracing/main.cpp -I/opt/homebrew/include -L/opt/homebrew/lib -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers -o /Users/xiliu/Desktop/c++/ray_tracing/bullshit
Undefined symbols for architecture arm64:
  "_glfwCreateWindow", referenced from:
      HelloWorld::initWindow() in bullshit-675519.o
  "_glfwDestroyWindow", referenced from:
      HelloWorld::cleanup() in bullshit-675519.o
  "_glfwPollEvents", referenced from:
      HelloWorld::mainLoop() in bullshit-675519.o
  "_glfwTerminate", referenced from:
      HelloWorld::cleanup() in bullshit-675519.o
  "_glfwWindowHint", referenced from:
      HelloWorld::initWindow() in bullshit-675519.o
  "_glfwWindowShouldClose", referenced from:
      HelloWorld::mainLoop() in bullshit-675519.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Build finished with error(s).
The terminal process failed to launch (exit code: -1).

.zshrc

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib
export CPPPATH=/opt/homebrew/include
export DYLD_LIBRARY_PATH=/opt/homebrew/lib
Xi Liu
  • 559
  • 9
  • 18

0 Answers0