I've got a problem that's bothering me for a long time. I use VScode on macOS with standart clang compiller. Almost all error messages produced by the "gcc" are cut, and don't help me at all. I do not know is it a VScode thing or my compilling settings are wrong. Also, if someone could say why just using "usr/bin/clang++" in command parameter is not working, it'll be excellent...
Settings
Problem
The problem matcher of the task shows only the first line of error messages. GCC and Clang wrap error messages on multiple lines resulting truncated errors in the VSCode "Problems" panel and tooltips.
Pass the option -fmessage-length=0 to the compiler to direct it to not wrap lines. Modify "args" in your config.
"args": [
"-fmessage-length=0",
"-Wall",
"-Wextra",
"-std=c++17",
"-g",
"${fileDirname}/**.cpp",
"-o",
"${fileDirname}"/${fileBasenameNoExtension}"
],
I'm not sure what it means that error messages "are cut", does that mean they are deleted? It looks like from your picture that they are still showing. If you are getting error messages that you fixed, sometimes another build is required for phantom errors to go away.
Addressing the second part, if you moved the bin directory from XcodeDefault.XcodeToolChain/ straight to the usr/ directory, then you could set the command to
"command": "usr/bin/clang++"
I doubt that clang installed directly to your user folder, however, and it is probably not good practice to move it there since other programs and tasks may still depend on the old location.
Related
I'm currently trying to debug a C++ code using VSCode. I have been able to successfully debug Python code many times by putting in my inputs and then debugging the code, but for some reason C++ does not let me debug my code in the built in terminal. The error message looks like this:
The Message I'm getting in Terminal - Image
I've looked at a lot of different Stack overflow posts, but none of them seem to work. Here are some things I've tried:
In my launch.json, I tried making "externalConsole": true, but this doesn't seem to fix anything. I have included a picture of my launch.json as well.
Picture of my Launch.json
In my tasks.json, I tried adding an "Open Terminal" line which I got online, but this doesn't seem to work.
Picture of my Tasks.json
I added "code-runner.runInTerminal": true, to my settings.json, but this doesn't seem to work.
Picture of my Settings.json
I've also included my configurations
Picture of Cpp_properties.json
Right now, I'm just clicking on the little "debug" button at the top and then clicking on "Debug C/C++ Code", but this doesn't seem to work. I've tried downloading other extensions to run my code that way but that also doesn't work.
I'm using MacOS, and I think I'm using Clang as my C++ compiler, though I'm not too sure about this.
Whenever I try doing something basic as like running the code (e.g. cout << "Hello World"), this works, but for some reason the cin code doesn't work? Like I'm not able to give my code ANY input. I need to be able to give my code input for USACO...
I'm complety despairing compiling my C++ program using Gtkmm3..
I read about 30 different Stackoverflow, Microsoft and other forum entries but nothing works.
The problems were:
Using vcpkg doesn't work since I need Gtkmm3 not 4.
Using VS Studio fails to generate the cache.
Using VS Code doesn't find gtkmm.h (see error message in the title) although I did EVERYTHING this page told me to do: https://wiki.gnome.org/Projects/gtkmm/MSWindows several times in several folders. And of course I have set the right Path in the Windows settings.
The compiler used (terminal told me) is in: D:\msys64\mingw64\bin\g++.exe
I also edited the launch.json with:
{
"version": "0.2.1",
"tasks": [
{
"taskName": "build-all",
"appliesTo": "example.cpp",
"contextType": "build",
"type": "launch",
"command": "${env.comspec}",
"args": [
"g++ -std=c++17 -o example.exe -g example.cpp simple `pkg-config gtkmm-3.0 --cflags --libs`"
]
}
]
}
I also tried compiling the .exe with Clion with standard CMakeLists.txt I wrote but that doesn't work as well cause Clion can't find either pkgConfig or gtkmm.h.
I tried CodeBlocks with specific Path setting to MinGW.
Someone on StackOverflow wrote a script for installing Gtkmm3 using MinGW in the terminal (Can't find the link for now sorry)... But of course: It didn't work!
So after almost infinity attemps, 4-5 days of trying I gave up now. Hopefully someone can help me here having the same problem.
I need to pass the arg -Wl,-Bstatic,--whole-archive to g++.
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "shell: g++.exe build active file",
"command": "C:\\MinGW\\x86\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-Wl,-Bstatic,--whole-archive",
"-Xlinker",
"-Map=${fileDirname}\\${fileBasenameNoExtension}.map",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\x86\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
It gives me in output this in the terminal.
Executing task: C:\MinGW\x86\bin\g++.exe -g 'c:\Users\remi\Desktop\OK - VSCode\loaderstack.cpp' -Wl,-Bstatic,--whole-archive -Xlinker '-Map=c:\Users\remi\Desktop\OK - VSCode\loaderstack.map' -o 'c:\Users\remi\Desktop\OK - VSCode\loaderstack.exe' <
At line:1 char:84
+ ... e -g 'c:\Users\remi\Desktop\OK - VSCode\loaderstack.cpp' -Wl,-Bstatic ...
+ ~
Missing argument in parameter list.
At line:1 char:93
+ ... Users\remi\Desktop\OK - VSCode\loaderstack.cpp' -Wl,-Bstatic,--whole- ...
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument
Is there anyway to build inside VSCode with these comma-separated args ?
I originally answered this question (like a dumb dumb) as if you were using Linux, so I deleted that answer and included a new one for PowerShell.
This is sort of a common problem when dev's use GCC with Powershell. The problem is that PowerShell is very programmatic in the way it implements its interface, and the way that it executes commands. With Linux, CLI's are all written opensource (mostly) and are developed by the developers, where powershell is created by a company that dictates how every little detail works (there are benefits, and downsides to both). PowerShell has aspects/features (or w/e you want to call them) that just feel like somthing a programming language has, for example PowerShell has scopes, and what you pass to powershell gets parsed according to the context (or scope) that your currently in. The problem you are dealing with is that your command, that your handing GCC through your VS Code v2 Task is not being parsed properly due to the context in which the task is handing it to Power-shell.
YOU HAVE 2 OPTIONS
Option #1
The first option is to use a scope where the parser will correctly interoperate the command.
Remember, your using a VSCode task, powershell & gcc, to make sure communication succeeds across all three, you need to include the scope to use in what you are communicating. To do that we want to make use of the...
Call Operator &
To use the call operator just format the initial command to execute as shown in the code block bellow:
"command": "& C:\\MinGW\\x86\\bin\\g++.exe",
Where I know that this is a valid solution to your problem, I am currently on a Linux System, I have windows dual booted, but I am too lazy to switch over to it, so just in-case something needs to be tweaked, use the link for the Call Operator I posted above, MS documentation is very good, and very specific about how to implement its software-technologies
Option #2
Your second option takes a totally different route than the first.
Instead of dealing with the scope being the problem, your gonna deal with Power-shell's inability to parse the MingW GCC Command.
To deal with Power-shell's parsing issue, we will tell it to stop parsing the command, henceforth, the...
stop-parsing flag --%
(For the semantics police-type of developers: I think its technically a token, not a flag)
Using the flag looks like this: gcc %--
So the whole command should look somthing like this:
"args": [
"--%"
"-g",
"${file}",
"-Wl,-Bstatic,--whole-archive",
"-Xlinker",
"-Map=${fileDirname}\\${fileBasenameNoExtension}.map",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
Again, I included the link to the docs for the stop-parsing token above, just in-case something needs to be tweaked.
The example I showed above is somthing I had to use on a project that I worked on for a very long time, because of that experiance, I perfer to use the no
Somthing else that I don't know much about, by I read about when I DDG'd the links to Microsoft-site that might, maybe work is using the Arguments mode, which seems to be similar to the stop parsing command?
Anyhow, here is the link if you want to read about it.
I should say that I have not tried this approach, but I think it will work.
I suggest that you escape , in powershell using `. Try it in your config file like this:
"-Wl`,-Bstatic`,--whole-archive",
I'm not sure if it works, but since it worked for echo hell`,o`,o, I guess everything will be fine. Please let me know if this approach works.
I have a minimal Rust/OpenGL app on Windows. I'm using Visual Studio Code, LLDB, and Glutin (a library resembling GLFW).
Launching via cargo run opens an empty window, but when launching via LLDB, no window opens. I've confirmed both in LLDB and with println! that the context-creation functions are being called and the main loop is executing. In other words, I've verified that all lines of code are reached. The same holds true whether running from within VSCode or not.
I'm using a 32-bit Rust toolchain, stable-i686-pc-windows-gnu, because LLDB doesn't fully support 64-bit Windows. Aside from this issue, LLDB seems to be working as expected.
Below is main.rs, which is adapted from the Glutin readme. (Glutin is a Rust library similar to GLFW.) I've deleted all but the essentials necessary to open a window.
Desired behavior: The window opens when the program launches from LLDB, the same as it does when the program launches from outside LLDB.
Actual behavior: The window doesn't open when the program launches from LLDB.
Question: What could explain this difference in behavior? I.e. why would the window not open from LLDB when it does from the terminal?
extern crate gl;
extern crate glutin;
fn main() {
let events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new();
let context = glutin::ContextBuilder::new();
// When running outside LLDB, this line causes the window to appear.
// The let binding is necessary because without it, the value will be dropped
// and the window will close before the loop starts.
let gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap();
// Normally, we'd make the window current here. But it's not necessary
// to reproduce the problem.
loop {
// This is where we'd swap the buffers and clear. But it's not necessary
// to reproduce the problem.
}
}
Partial answer: As a workaround, you can attach LLDB to a running process instead of launching the process from LLDB. In VSCode, you can do this with: Add Configuration -> LLDB: Attach by Name. With this workflow, the OpenGL window opens just like it would if LLDB weren't involved. Unfortunately, attaching is significantly less ergonomic.
Update: I prefer to launch with the debugger rather than attach. I've found that Rust's MSVC x64 toolchain along with Microsoft's C/C++ debugger works well for this use case. The steps that work for me are:
If necessary, install MSVC toolchain: rustup install stable-x86_64-pc-windows-msvc
Set the MSVC toolchain as default: rustup default stable-x86_64-pc-windows-msvc
Update Rust: rustup update
Install Microsoft's C/C++ extension for Visual Studio Code. The extension includes a debugger that's compatible with the MSVC binaries that Rust compiles.
Add a debug configuration to Visual Studio Code. I started by adding the default configuration but had to modify it. Ultimately, this is what I had in .vs-code/launch.json--note that the string rust-test is unique to the project:
-
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/rust-test.exe",
"args": [],
"symbolSearchPath": "${workspaceFolder}/target/debug/rust-test.pdb",
"stopAtEntry": false,
"cwd": "${workspaceFolder}/target/debug",
"environment": [],
"externalConsole": true
}
I'd still be grateful if anyone has any thoughts about the LLDB issue. Although the MSVC toolchain solves my problem for now, there may be others out there who really want to use LLDB and come across this question.
#include<iostream>
using namespace std;
int main()
{
cout<<"hi"<<endl;
return 0;
}
I am using Sublime text 3, and I am getting this error:
error-
'g++' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.0s]
Try to set g++ to your system path.
You can refer to this:
http://stephencoakley.com/2015/01/21/guide-setting-up-a-simple-c-development-environment-on-windows
I faced the same problem while running the code from command line. And found out that I messed up with MinGW installation. So I reinstalled it,
Do this while installing MinGW ----
After downloading, install MinGW and wait for the “MinGW Installation Manager” to show up.
When the “MinGW Installation Manager” shows up, click on mingw32-gcc-g++ then select “Mark for Installation”
In the menu at the top left corner, click on “Installation > Apply Changes”
Wait and allow to install completely. Ensure you have a stable internet connection during this process.
when it is done, then edit the environment 'Path' Variable as stated in other answer.
In short I followed this
For me, it's easily fixed by two steps, as below:
Set the environment variable:
C:/MinGW/bin
Paste the following code in the "launch.json":
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Compiler",
"type": "cppvsdbg",
"request": "launch",
"program": "C:/MinGW/bin",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true
},
]
}
Open mingw-w64 folder
click on mingw32->i686-w64-mingw32->bin
copy this path and set this path in your system environment variables
If you keep getting this error, make sure you set up MinGW in Path variable, not separated user\system variables: pic link on imgur here
The best thing to do is first of all ensure you have download minGW properly you can refer from this site https://www.msys2.org/ , Be sure to follow all the steps inorder for it to install completely (ps:it takes a while),, after that you can go to environment system variables via settings and a new path C:\msys64\mingw64\bin or wherever your msys64 file might be stored. Hope this helps
Check if you have installed g++ by typing g++ --version. If you already have g++ compiler installed, just hit ctrl + S to save the changes you made, then run the code.