I am trying to migrate a C++ project to VS Code and I found tasks to be very annoying in the fact that they don't close automatically (and I haven't found a way to do that through the settings). Thing is, my project has a shell script that builds everything and I would like to have that available with a keyboard shortcut as a single run task... just like a normal IDE builds projects.
Is there any way to have tasks auto-terminate when the script finishes?
Related
I am using VS Code with the CMake Tools extension, and I would like to run a simple MPI program. Everything compiles just fine, and I can run my code in the terminal using
mpiexec -n 6 "path-to-my-workspace\build\my-executable.exe"
However, I would like to set things up so that this gets executed automatically when I press Control + Shift + P > "CMake: Run Without Debugging" (or Shift F5).
I read in the CMake Tools documentation that I could create new launch targets in a launch.json file. However, the VS Code documentation states that
The launch.json file is used to configure the debugger in Visual Studio Code.
I want this for debug, but also for release. Should I still use a launch.json file? I had the same problem in the past when I needed to pass arguments to my main function. What is the right way to do that in VS Code with CMake Tools?
This sounds like two cases of terminology-related confusion.
In VS Code, there are actions to "Run Code" and "Run Without Debugging". You can find more about the distinction between the two in this question. In a nutshell, "Run Code" runs the program inside a debugger program (like gdb), and and "Run Without Debugging" also runs the program, but doesn' run it inside a debugger program.
The two most common build modes are "debug" and "release", where debug includes debugging symbols that enable running in a debugger, and release does not and instead is built with more optimizations. VS Code can run both types of builds without debugging, and can run debug builds in a debugger. For release builds, it can only run outside a debugger.
You specify that you only care to run outside a debugger.
To answer your question "Should I still use a launch.json file?", yes, you can still use a launch.json file.
Also, note:
Tip: The Run action is always available, but not all debugger extensions support 'Run'. In this case, 'Run' will be the same as 'Debug'.
Another note: If the program you wanted to run wasn't a build output of your project, then you would instead probably want to be using tasks.json.
I recently started to putter around with C++ projects in Eclipse. It's definitely a tad trickier than working with Java but I managed to figure out most things.
However, at least one issue is escaping my ability to resolve. I wanted Eclipse to not bother trying to run an executable if a clean build failed.
Currently it pops up an annoying dialog box if the build fails because it appears to be blindly trying to launch. At least my clean build prevents the IDE from launching a stale executable but it would be nice to also get rid of the dialog box.
Any tips out there from Eclipse experts?
I'm trying to start a work in vscode , latest C++ plugin version supports ms debugger, so as I'm mostly working under windows it was a signal to try this.
c++ tools plugin from MS and cmake tools were installed.
my test project was however not built . the problem is clear , but I need an advice from experienced vscode users how to solve this right.
cmake doesn't see vc compiler.
(after using QtCreator) I expected that vscode could detect vc installation... however that's not so. ok, I have a two ways:
fill environment variables INCLUDE/LIB/PATH with a headers, libs and binaries
just run vcvarsall.bat x64
Second way is a simple and reliable. so final question is:
how to run .bat at the begining of vscode start?
(I don't mean write another bat/cmd, prepare the environment and run vscode inside the same script after that)
Although the question is fairly old, I'll try to give a useful answer, in case others stumble across, just like I did.
I believe what you are trying to achieve is not possible. Code inherits the environment it was started with. If you did not launch it from a developer command prompt, you will not be able build and debug. (Building might be possible if every task first starts the vcvarsall.bat, but that slows things down by a lot. Debugging I think will still not work.)
If you are willing to, you can check out vector-of-bools CMake Tools extension which does build automation as well as automatic MSVC detection. It builds using CMake (thus you need to write your build scripts using CMake), but it will take care of building just by pressing F7, like what most VS users are familiar with.
I have a custom shell that I can run C++ applications in. I start the shell from a bash prompt and then run my C++ code. I want to emulate this behavior with Eclipse, particularly for debugging. I can't seem to figure this out.
I could write a simple bash script that kicks off the custom shell and runs my application but Eclipse does not let me debug when I do this.
Is there a way to achieve this functionality?
Please keep in mind eclipse can set environment variables for running/debugging job.
If your shell is more complicated than that, please provide more details about your shell.
But I'm not optimistic about it.
Btw, you can always attach an existing process for debugging.
I have a project which I created in Eclipse c++. The project invokes a function that does a lot of loops (Thousands) to calculate the result.
When I run it in Eclipse it takes 1 minute (~70 seconds).
I wanted to add a GUI to the project so I opened a WinForm (Win32) project in VisualStudio2010 and moved all files of the project from the eclipse directory to the new directory (created for VS2010).
Now, when I run the form, the function takes 4-5 minutes. I tried to cancel the progress bar but it wasn't the problem, so I understood that long time is not because of the GUI.
I think the problem is in the compilation in VS2010. I tried to change some Optimizations properties, but the project couldn't be compiled...
How can I reduce the run time?
Thanks!
Basically you answered your own question:
I think the problem is in the compilation in VS2010. I tried to change
some Optimizations properties, but the project couldn't be compiled...
however, it's hard to answer it, since there is a lot of optimization options in both of compilers, it's hard to tell what option makes it much faster/slower. It's also possible (and most probably is) that MS compiler just cant produce exactly the same or similar code to that of Eclipse's compiler.
Your options is to "play" with optimization switches of the VS compiler and see if it helps. You can try to compare it's options to ones of the Eclipse to find differences, but most likely they will be just too different.
As #Zuljin correctly mentioned also check you selected Win32 project, not CLR (Windows Forms) application. If you are using CLR project, then it's natural it will possibly run slower than Native program type.
My bet would be the debugger in VS2010
Build with your optimized settings but then start the generated file from the explorer, not from Visual Studio. You can also deactivate the debugger attachment in the project settings.
See if the run time is any different.