Link Project
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:
> 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:
{
"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
(
"--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:
{
"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
"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
Related
I'm the beginner of C++. I set development environment in vscode in Mac.
But I trapped in variable initialization.
Copy initialization and direct initialization are ok, but uniform initialization doesn't work.
#include <iostream>
int main() {
int a(0);
int b = 0;
int c{0};
int d = {0};
int e;
std::cout << "Hello World";
return 0;
}
In this code, int c{0}; doesn't work. It failed to build.
It printed error: expected ';' at end of declaration
What can I try to solve this problem??
I don't know if it helps, but I'll upload ".vscode".
// c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": ["${workspaceFolder}/**"],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
// launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"&&",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: clang++ 활성 파일 빌드",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "디버거에서 생성된 작업입니다."
}
]
}
Every time i want to run my c++ code it show unable to debugging and not implemented.
please help to solve my problems
it seems error in launch.jsons / task.jsons / c_cpp_properties.jsons
please help me to resolve these error . I am new in coding and i am stuck in this from 4 days .
launch.jsons
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "C:\\Users\\Sumit\\Desktop\\vs code Projects\\CPP Projects\\hello_world.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\MinGW\\bin",
"environment": [],
"console": "externalTerminal"
}
]
}
task.jsons
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
c_cpp_properties.jsons
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}
I plan to use opencv in vscode on macos.
I have configured my c_cpp_properties.json,launch.json and task.json
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/Cellar/opencv/4.5.3_2/include/opencv4/**",
"/usr/local/Cellar/opencv/4.5.3_2/lib"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/usr/local/opt/opencv/include/opencv4",
"-L/usr/local/opt/opencv/lib",
"-lopencv_core"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
And the editor also has smart completion when I enter the include path
But I still get the file not found error, what should I do?
The issue I'm having is that when I run "C++ run/debug active file" the the code executes but doesn't stop at the breakpoints I set. I don't know a lot about how debuggers work but I'm guessing the the debugger isn't listening to the correct process? Or why would this happen?
In all honesty, I've been struggling to get all my dependencies correct and in the process may have broke intended functionality so it could be that I set up the scripts in a way that breaks it's intended use.
tasks.json looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"main.cc",
"-o",
"main",
"-std=c++17",
"-I/usr/local/include/cairomm-1.16",
"-I/usr/local/lib/cairomm-1.16/include",
"-I/usr/include/cairo",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I/usr/include/pixman-1",
"-I/usr/include/uuid",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/sigc++-3.0",
"-I/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++-9 build active file",
"command": "/usr/bin/g++-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
launch.json looks like this:
{
"version": "0.0.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
c_cpp_properties.json looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"main.cc",
"-o",
"main",
"-std=c++17",
"-I/usr/local/include/cairomm-1.16",
"-I/usr/local/lib/cairomm-1.16/include",
"-I/usr/include/cairo",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I/usr/include/pixman-1",
"-I/usr/include/uuid",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/sigc++-3.0",
"-I/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++-9 build active file",
"command": "/usr/bin/g++-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
I reworked it and went slower this time. I don't have a launch file but
Here's tasks:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/usr/local/include/cairomm-1.16",
"-I/usr/local/lib/cairomm-1.16/include",
"-I/usr/include/cairo",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I/usr/include/pixman-1",
"-I/usr/include/uuid",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/sigc++-3.0",
"-I/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
And here's c_cpp_properties
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/lib",
"/usr/local/lib/cairomm-1.16/include",
"/usr/local/include/cairomm-1.16",
"/usr/include/sigc++-3.0",
"/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"/usr/include/cairo",
"/usr/include/freetype2"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++20",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
I think there are a lot of unnecessary code in your tasks.json , try this out I am successfully able to set breakpoints during debugging .
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
I'm running VS Code on MacOS, and I'm using clang to compile a simple "Hello World!" program in C++. However, when I try to run my program, VS Code gives me the following error message: Undefined symbols for architecture arm64: followed by dozens of references to the std library. At the bottom of the terminal, it says:
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 terminated with exit code: -1.
(a) What does this mean? and (b) how can I fix it?
HelloWorld.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "clang - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/HelloWorld.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang build active file"
}
]
}
Thanks!
If you have multiple CPP files in the project then you need to add "${fileDirname}/*.cpp"
tasks.json
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${fileDirname}/*.cpp",
// "${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
If you're having a vector; error from vscode also add the c_cpp_properties.json file in .vscode directory :
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"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-x64"
}
],
"version": 4
}