So I downloaded raylib-4.2.0_win64_mingw-w64.zip and used some C VS Code template and changed somethings on the tasks.json
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "DEBUG-build",
"command": "g++",
"args": [
"-g",
"-std=c++17",
"-m64",
"-O0",
"-Wall",
"${workspaceFolder}/src/*.cpp",
"-o",
"${workspaceFolder}/build/game.exe",
"-I./src",
"-I./src/include",
"-IC:/raylib-mingw64/include",
"-static-libgcc",
"-LC:/raylib-mingw64/lib",
"-lraylib",
"-lopengl32",
"-lgdi32",
"-lwinmm",
"-static-libgcc"
],
"options": {
"cwd": "${workspaceFolder}"
},
"type": "shell",
"group": "build",
"problemMatcher": [],
"dependsOrder": "sequence",
"dependsOn": [
"debug-dir-check",
"DEBUG-quick-clean"
]
},
{
"label": "RELEASE-build",
"command": "g++",
"args": [
"-std=c++17",
"-m64",
"-Ofast",
"${workspaceFolder}/src/*.cpp",
"${workspaceFolder}/src/my.o",
"-o",
"${workspaceFolder}/build/game.exe",
"-I./src",
"-I./src/include",
"-IC:/raylib-mingw64/include",
"-LC:/raylib-mingw64/lib",
"-lraylib",
"-lopengl32",
"-lgdi32",
"-lwinmm",
"-static-libgcc"
],
"options": {
"cwd": "${workspaceFolder}"
},
"type": "shell",
"group": "build",
"problemMatcher": [],
"dependsOrder": "sequence",
"dependsOn": [
"release-dir-check",
"RELEASE-quick-clean",
"MY-RC-build"
]
},
{
"label": "DEBUG-quick-clean",
"command": "del ${workspaceFolder}/build/*.exe ; del ${workspaceFolder}/src/*.o",
"type": "shell",
"group": "build"
},
{
"label": "DEBUG-clean-dist-copy",
"command": "robocopy ${workspaceFolder}/dist ${workspaceFolder}/build *.* /MIR /XF .gitignore ; exit 0",
"type": "shell",
"group": "build"
},
{
"label": "RELEASE-quick-clean",
"command": "del ${workspaceFolder}/build/*.exe ; del ${workspaceFolder}/src/*.o",
"type": "shell",
"group": "build"
},
{
"label": "RELEASE-clean-dist-copy",
"command": "robocopy ${workspaceFolder}/dist ${workspaceFolder}/build *.* /MIR /XF .gitignore ; exit 0",
"type": "shell",
"group": "build"
},
{
"label": "MY-RC-build",
"command": "windres ${workspaceFolder}/src/my.rc ${workspaceFolder}/src/my.o",
"type": "shell",
"group": "build"
},
{
"label": "debug-dir-check",
"command": "cmd",
"args": ["/C", "if not exist ${workspaceFolder}\\build mkdir ${workspaceFolder}\\build"],
"group": "build"
},
{
"label": "release-dir-check",
"command": "cmd",
"args": ["/C", "if not exist ${workspaceFolder}\\build mkdir ${workspaceFolder}\\build"],
"group": "build"
},
]
}
I tried removing "-static-libgcc" and changing the "-std=" version and other stuff.
I basically expeted it to run and create a window not error this:
C:/raylib-mingw64/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x2b1e): undefined reference to `__imp__wassert'
C:/raylib-mingw64/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x2ca7): undefined reference to `__imp__wassert'
C:/raylib-mingw64/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x2ceb): undefined reference to `__imp__wassert'
C:/raylib-mingw64/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x2d73): undefined reference to `__imp__wassert'
C:/raylib-mingw64/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x2dad): undefined reference to `__imp__wassert'
C:/raylib-mingw64/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x364f): more undefined references to `__imp__wassert' follow
collect2.exe: error: ld returned 1 exit status
+Node: It doesn't happen when I don't use raylib functions.
Related
The following error is received while using empty braces to initialise variables:
error: expected ';' at end of declaration
int b{};
^
;
The code being used is:
#include<iostream>
int main(){
int a{};
std::cout<<"hello"<<std::endl;
return 0;
}
I'm using the latest version of Microsoft VS Code on an M1 based Macbook Air. Extensions being used are C/C++ Intellisense and Code Runner.
Same error is displayed when running the file in terminal.
The tasks.json file looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}
int a={4}; works fine while int a={}; throws an error error: scalar initializer cannot be empty
As a person who is habituated of using braced initialisation, this issue is giving me quite some trouble. Any fix for this issue would be appreciated.
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 have a simple HelloWorld.cpp file and I want to run it with the following steps, each is run one after the other as follows.
Compile
Clear Integrated Terminal
Run the produced executable.
Unfortunately I fails to setup the second step (clearing the console window). What is the correct setup?
{
"version": "2.0.0",
"tasks": [
{
"label": "COMPILE",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${fileBasenameNoExtension}.exe",
"${file}",
"/std:c++latest"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "CLEAN",
"command": "cmd.exe /c cls",
"dependsOn": "COMPILE"
},
{
"label": "RUN",
"command": "${fileBasenameNoExtension}.exe",
"dependsOn": "CLEAN",
"options": {
"cwd": "${fileDirname}"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
there is a vscode setting with workbench.action.terminal.clear you'll find related settings there,
or in File >Preferences >Keyboard shortcuts. search for Terminal:clear and assign the key
Aha. I found the solution: Add "type": "shell" to the CLEAN step as follows.
{
"type": "shell",
"label": "CLEAN",
"command": "cls",
"dependsOn": "COMPILE"
}
The complete tasks.json.
{
"version": "2.0.0",
"tasks": [
{
"label": "COMPILE",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${fileBasenameNoExtension}.exe",
"${file}",
"/std:c++latest"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$msCompile"
]
},
{
"type": "shell",
"label": "CLEAN",
"command": "cls",
"dependsOn": "COMPILE"
},
{
"label": "RUN",
"command": "${fileBasenameNoExtension}.exe",
"dependsOn": "CLEAN",
"options": {
"cwd": "${fileDirname}"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
I am using Visual Studio Code on Mac OS X to build and run a very basic vector program. Here is
the code
#include <iostream>
#include <vector>
using namespace std;
int main(){
// Demo vector
vector<int> arr = { 1,2,3,4,55};
cout<<arr.size()<<endl;
return 0;
}
The below code on running gives following error
vectors.cpp:8:17: error: non-aggregate type 'vector' cannot be
initialized with an initializer list
vector arr = { 1,2,3,4,55};
^ ~~~~~~~~~~~~~ 1 error generated.
I also added "-std=c++11", in tasks.json, restarted and visual studio code, but the error remains the same. Here is the tasks.json for reference
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": "build",
"label": "tsc: build - tsconfig.json"
},
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": [
"$tsc-watch"
],
"group": "build",
"label": "tsc: watch - tsconfig.json"
},
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"-std=c++11",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang"
}
]
}
this is the command being built by Visual Studio Code
cd "/Users/XXX/PROJECTS/Algorithms/" && g++ vectors.cpp -o vectors &&
"/Users/XXX/PROJECTS/Algorithms/"vectors
Can some one suggest a way to run this program within Visual Studio Code editor?
Thanks!
I still could not use the Visual studio code run button to run the program, so I ended up running via command prompt using below command
$ g++ -std=c++11 -o test test.cpp
If someone can share their task.json, it will be good to see. Here is mine
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g++",
"--std=c++11",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: /usr/bin/g++"
}
]
}
I want to build and run c++ source code. And then delete all except source code.
{
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"&",
"${fileDirname}/${fileBasenameNoExtension}",
"&",
"rm ",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
I except they build and run and then delete worthless files, but it is not working.
Taking a look at VScode tasks parameters, you see that we can chain them with dependsOn. Note that the required command can contain the full path to where your tool is located when it's not included in your OS path variable, but options.cwd should contain the path to where your tool should run, i.e. ${fileDirname}. Also you should study the presentation parameter and adjust it for the way you want to see errors.
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"presentation": {
"reveal": "silent",
"panel": "shared"
},
"options": {
"cwd": "${fileDirname}"
},
},
{
"label": "cpp-run",
"type": "process",
"command": "${fileDirname}/${fileBasenameNoExtension}",
"dependsOn": [
"g++ build active file"
],
"presentation": {
"reveal": "always",
"panel": "shared"
},
"options": {
"cwd": "${fileDirname}"
},
},
{
"label": "cpp-test",
"type": "process",
"command": "rm",
"args": [
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"cpp-run"
],
"presentation": {
"reveal": "never",
"panel": "shared"
},
"options": {
"cwd": "${fileDirname}"
},
}
],
}