VSCode c++ configuring for vc toolchain - c++

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.

Related

Configure kit for Qt automatically

SO!
Let's say I have a number of settings (GCC compiler 9.3.0 built from source, as the distribution I have to use has a very old one, along with environment setup) for a new Kit in QtCreator.
I have managed to setup an environment for compilation and execution of compiled binaries, and made a script to make it work (like qmake -nocache -recursive/make/sudo make install, direct execution of g++, and other stuff).
One thing that script can't do at the moment, is that it cannot create a kit for QtCreator with new compilers and environment being set as required, so after running a script, its user has to go through setting it up himself through GUI, which is bad, because this can cause misconfiguration.
This thing I'm trying to create is going to be used by around ~200 people in my company, so leaving readme.txt with instructions just doesn't go well enough for me - I don't want running around fixing missing "{" and "}" in Environment description in created Kits, and other stuff.
Are there ways to create Kits for QtCreator automatically from command line? Maybe, there's some files to edit?
I've looked into this one a few years back (I wanted to do something similar for registering Buildroot toolchains automatically in QtCreator), and I was unable to find an off the shelf solution. So i think there are 2 ways to implement this:
a) Implementing a command line utility the manipulate the ~/.config/QtProject/qtcreator/{toolchains,profiles}.xml files. Maybe by (re)using the existing C++ implementation within QtCreator, or just re-implement it ie. in Python. Back than I didn't start to work on this as there was no real business need.
b) Switching to qbs, as qbs has support for setting up toolchains from the command line ( see: https://doc.qt.io/qbs/cli-setup-toolchains.html)
If you decide to go with solution a), please let me know and maybe we can partner up to implement it.
Check out the command line sdktool bundled with QtCreator:
The SDK tool can be used to set up Qt versions, tool chains, devices
and kits in Qt Creator.
There still is a lot of knowledge about Qt Creator internals required
to use this tool!
I haven't tried it yet, but I did find the executable under Tools/QtCreator/libexec/qtcreator subdirectory of the Qt Creator installation directory. ./sdktool --help works for me under Linux.

VS2017 - How to configure project for remote debugging

I want to create an MP3 player on my Raspberry Pi (OS: Raspbian). The problem is, that i don't have any experience with Linux programming, and I'm having a huge problem with project configuration, becouse of cross platform compiling. I want to add two liblaries:
mpg123
libao
I'm able to compile the code on linux machine with gcc -O2 test.cpp -lmpg123, but I can't force Visual Studio to make see those libs.
I'm also having a problem with using wiringPi lib while I'm trying to remote debugging my program, since I have to run it as root for GPIO configuration. Is there any way for any way to force Visual Studio to run my compiled code with root privilages?
Personally I come from a long history of C/C++/MFC/Windows programming with no Linux experience at all. I started programming for the Raspberry a year or so ago, when I got one from my son for my birthday. With a C/C++ history it's really not that hard, but you just have to read in a bit because on Linux a lot is the same, and a lot isn't :). Just read and read and in time, you're an experienced Linux programmer! It takes some time I'm afraid.
So, I'm sort of an experienced newbie on this I think :). I found a lot of info on www.die.net (and other Linux man pages). If you search there for a function, say printf(), look at the (3) pages - they explain how you should use 'm.
But although VS2017 does a really good job on this, it's not always going as smooth as you would like. Sometimes it's just necessary to reboot your Raspberry, restart VS and try again. The Linux cross-compiling is quite new in VS and isn't perfect yet.
A few tips:
Use a Raspberry with a fresh Stretch image to start with. Of course after a sudo apt-get update && sudo apt-get -y upgrade.
Set the debugger in Visual Studio to gdb instead of gdbserver. This will prevent certain debugging problems.
Place all your source files (.h and .cpp) in the main folder of your project alongside the main.cpp. If you place them in different directories and then include in your project, you can debug your program but you won't be able to step through.
Start simple and debug your program often when you're developing. Don't add too much code before your next check. In a cross-compile setup there are just a lot more things than normal that can (and will) go wrong.
VS2017 has default Linux include files in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include. If you need others, place them in a folder of you own and include the path.
With cross-compiling VS itself doesn't do any compiling, you use it to maintain your project. When the project has to be compiled, all necessary files are copied to the Raspberry and the compiler and linker there are invoked by VS.
On your question how to configure a project for remote debugging: it's probably best to start with the Blink example in Visual Studio 2017 (File, New, Project, Installed, Visual C++, Cross Platform, Linux => Blink). It should run without problems. From there, you can build further on your project.
In the Blink example, they use wiringPiSetupSys() and the remote command gpio export 17 out to run your program without sudo. I've found that changing that to wiringPiSetup() and disabling the remote command, it still is possible to run and debug the program. On the Raspberry I can run the program from it's folder by issuing ./[programname]. If that doesn't work for you, you could run the program by issuing sudo ./[programname].

Debugging fails with QtCreator on OSX

I have OSX Yosemite 10.10.5, QtCreator 4.1.0, Qt 5.7.0 and Xcode 7.2.1.
If I write any native C++ program in QtCreator (console, gui - anything) I am unable to debug that program from QtCreator. Breakpoints get ignored, the program executes without pause and runs to completion no matter what I try.
I have tried the Xcode's LLDb, system GDB and Homebrew GDB as debuggers. the versions of GDB fail to start. Homebrew GDB has been codesigned.
This all used to (a few year back) just work beautifully and I am at a loss as to what might have changed.
Curiously, if I generate an exception inside the program - like accessing through a null pointer, the debugger shows me where this happens in just the way I would expect so, presumably, the debugger is running but simply treating me with complete disdain.
I know there are many versions of this question but none seem to address the problem adequately or offer workable solutions, or they apply to much older versions of the products.
Any suggestions?
This version of qtCreator (4.1.0) saw the return of the warning about having the build directory at the same level as the project directory. In Windows, this is done automatically. My mac installation does not get it right. (I may have messed a while back - cannot remember).
So - if the build directory is inside the project directory, debugging fails. Move the build directory up to the same level as the project directory and everything seems to work fine.
You can set the default build directory in the preferences/Build & Run dialogue. The path should start with ../
You will need to think about the folder structure before setting up the project unless you want build folders appearing in awkward places. So, a project folder structure like this is OK:
But one like this is not:
If this was already obvious to you, great. I have been messing with this for ages.
Many thanks to those who replied and anyone else who took the time to read the question. What helped e find it was the suggestion by #AlexanderVX that his setup was the same as mine but his worked. The only bit of my setup he could not see in the screenshots was the start of the build path. So that was the clue.

Build C++ Universal App from command line without MSBuild

In the same spirit as the question Can I download the Visual C++ Command Line Compiler without Visual Studio? I would like to see if it is easy to bundle the appropriate part of Visual Studio to build Universal App written in C++. Following the answer by #Alek to the aforementioned question, I managed to create an archive where I can basically unzip and use. But this is for traditional desktop (I would say, command-line) programs. I tried to do similar thing for Universal App and there are a couple of issues
The official way (i.e. what Visual Studio does under the hood) is to use MSBuild. Unfortunately, I do not know what are and how to get all of its dependencies. It seems to require significant configuration effort as well.
There is no documentation on how to build resources (e.g. generate C++ source and headers from XAML), how to generate the .appx. If possible, a Makefile template is very much appreciated.
The reason to ask for this is because Visual Studio failed me so many times. For instance, the November Update messed up my entire system; the SDK installer fail at 96% and rolled back. Previously, the upgrade to VS2015 (from 2013) also messed me up entirely. It seems that the only solution to these problems is complete uninstall. Having a portable archive where I can just unzip and restore my production environment back to health is something I would say extremely desirable.
Note: I do not care about the IDE. I only need the ability to build apps from source code on the command prompt.

Building Qt cross compile from windows

[edit] Sorry, I out thought myself. I was using a .bat file to set environment variables that wasn't set up properly. When I went to a straight VS2005 command prompt, the configure ran fine. Sorry for the noise.[/edit]
I'm trying to compile qt-everywhere-opensource for embedded. I'm using MSVC2005. However, I guess I am confused on the process. I am getting compiler errors during the configure step. I thought the configure step was just trying to generate the needed makefiles, so I'm not sure what it is trying to compile.
I expected to modify the mkspec, but I'm not sure if during configure I should point to windows headers or sdk headers. I know during the build phase I should point to sdk headers, but I'm not getting that far.
I can change the errors by modifying INCPATH, there's also a QMAKE_INCDIR that seems to have an effect. It occurred to me that since I pulled the source, maybe configure needs to build the compiler tools, in which case I should point to MSVC headers. I also tried downloading the SDK and adding the path to it's bin folder to my path ahead of the -everywhere- source, but that didn't fix the problem and I don't want to jack up my system too much testing things.
Hope someone out there can help!
When you install Qt from source under Win32, you must:
Extend the PATH variable to include $(QTDIR)\bin, where $(QTDIR) is the directory where you installed Qt.
Open a Visual Studio command prompt in $(QTDIR); a plain old Windows command prompt won't do (unless you run vcvars.bat to load Visual Studio's environment variables; but opening a Visual Studio command prompt directly is better).
At this point, configure should run properly, after which you can run nmake.
I suggest that you clear your previous installation attempts from your system before you try these steps.