Configure QtPackage for Visual Studio by command line - c++

I'm trying to build a project which uses qt on an CI service for windows.
I already managed to install the QtPackage for Visual Studio by command line.
Now I'm stuck at the following step:
Launch VS2015 for configuring Qt5Package
QT5 > Qt Options > Add
Version name: Qt 5.6.22Win32
Path: C:\build\libs\qt5_6_2\qtbase
Default Qt/Win version: Qt 5.6.2 Win32 – OK - You may need to restart Visual Studio for this to take effect.
Is is possible to do this from the command line? If not, how can I work around this problem?

If you are willing to modify such global setting (for all projects), I'm sorry but there is no way to do it from command line in current public versions of the QtVSTools, nor in the latest version from the repository head (https://code.qt.io/cgit/qt-labs/vstools.git/ # 2018-01-09).
On the other hand, if you use msbuild to compile the project, you can override the Qt version to be used during that compilation (project files are not modified).
To do so, change the QTDIR project property (using the /property option) and indicate the path to the directory of Qt version you want to use:
msbuild your_solution.sln /property:QTDIR="C:\build\libs\qt5_6_2\qtbase"
Hope this helps.

Related

Visual studio Python extension mixed mode debugging on CMake project

I'm trying to create a C++ Python extension using pybind11 and CMake, and would like to take advantage of visual studio's mixed mode debugging (see) for developing the extension.
I tried following the MSDN guide, and was able to create an extension and debug it using visual studio solution configurations. However, trying to recreate the project with CMake and debug it, breakpoints inside the C++ code are not triggered. I tried recreating the project twice:
a full CMake project (i.e. first create a folder with a CMake file then open it in VS).
a Python solution with a CMake subproject (adding the build folder to python search paths to access the extension).
In both methods C++ breakpoints are not triggered. Is there any way to make this work? Something I'm missing? I know there is a VSCode plugin which enables something similar. I'm currently using it, however I'd like to know if it is possible in Visual Studio proper.
Versions:
Visual Studio 2022
CMake 3.18
Python 3.8 (with debug symbols installed), however this is not the Python distributed with Visual Studio

Compiling libjpeg

Is there anyone who succeed to include libjpeg in some compiler? I tried everything: Dev C++, VS10, CodeBlocks, copy the headers and the lib by hand, add with the linker but nothing. Right now I am really confisued as there is not an official guide on how to compile it in any compiler. I would be really happy if someone could provide a tutorial on how the library can be compiled in any compiler.
Thank you in advance.
To compile libjpeg 9 in Visual Studio 2012, here are the steps (after unzipping the archive file):
Download the file WIN32.MAK (for example, from http://www.bvbcode.com/code/f2kivdrh-395674-down), and place a copy in the root source code directory (possibly C:\jpeg-9, but it depends where you unzipped it). I will refer to this directory as %jpegsrc% from now on. Having this file is important; otherwise step 3 will produce an error.
In the Visual Studio command prompt, open to %jpegsrc%:
cd %jpegsrc%
At the same command prompt, execute the following:
NMAKE /f makefile.vc setup-v10
This will create two Visual Studio 2010 solutions in %jpegsrc%: jpeg.sln and apps.sln.
Open each solution in Visual Studio 2012. Each one will prompt you to update all the projects to 2012 format. Click on “Update.” One time I did it, the prompt did not appear. In case that happens, right-click on the jpeg solution in the Solution Explorer, and choose “Update VC++ projects...,” which will produce the same prompt.
Save and build each solution as normal. (You have to build the jpeg.sln solution before apps.sln, since the latter depends on the former.)
Note: this process should work correctly in Visual Studio 2010, without the updating, but I have not tested it.
Update: This method still works in Visual Studio 2015 for libjpeg-9a.
Here is how I've built libjpeg using MinGW on Windows :
1. Get MinGW with MSYS
I've got a copy from http://sourceforge.net/projects/mingw/.
Quoting from www.mingw.org :
MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present.
We will need it to run the configure script that comes with libjpeg sources.
2. Get libjpeg sources
From http://www.ijg.org/, take the Unix format package (the Windows one won't work with this procedure). I took the jpeg_8d version.
3. Prepare a building directory
I've made a temporary directory named tmp in D:\, but you could choose whatever suits your needs. The thing that matters is the name of paths in MSYS. As it brings some * Unixity * to Windows, paths cannot be used in their original form.
In a nutshell:
C:\path\to\file becomes /c/path/to/file in MSYS land, an so
D:\tmp becomes /d/tmp.
Decompress the libjpeg sources in D:\tmp, so you have a jpeg-8d directory in there.
Create a jpeg-build directory inside D:\tmp, it will hold the built library.
Now everything is ready for the build.
4. ./configure, make, make install
That is the mantra of building in Unix land. An option should be added to redirect the install process to D:\tmp\jpeg-build.
Run the following commands in an MSYS shell (also named MinGW shell in Windows start menu):
cd /d/tmp/jpeg-8d
./configure --prefix=/d/tmp/jpeg-build
make
make install
As an additional step, you can run make test for safety.
These commands will build both static and shared versions of libjpeg.
5. Take the goods, delete the temporaries
If everything runs fine, you can delete the D:\tmp\jpeg-8d directory, but keep the jpeg-build one. It contains:
an include directory, containing libjpeg headers. You can move them to your compiler's headers directory.
a lib directory, with .a file to pass to the linker. You can move them to your compiler's library directory.
a bin directory, holding the libjpeg shared library libjpeg-8.dll and jpeg tools.
a share directory, containing man pages for the jpeg tools.
You can now build your program and link it against libjpeg by indicating the right include and library paths.
You can find many details about the libjpeg building and installation process in install.txt inside the source package.
I hope this will be useful.
It is really simple to build jpeg.lib with VS10.
First, download the libjpeg source code in zip format. At the time I'm writing this you can find it here.
Then extract the contents of the zip file to your disk.
Then open a VS2010 command prompt shell (or call vcvarsall.bat on any command prompt window), cd to the jpeg source directory (jpeg-8d in the download referenced above) and type the following:
nmake -f makefile.win setup-v10
This will generate two VS2010 solutions, and a bunch of project files. The solutions are:
jpeg.sln, which builds jpeg.lib
apps.sln, which builds the sample applications.
Good luck!
If you don't happen to have Visual Studio 2010 installed, here is what works on Visual Studio 2017:
Basic / Common steps:
Download the latest version of libjpeg from: http://www.ijg.org/ (zip version) and extract it to a folder
Open the "Developer Command Prompt for VS2017"
Change directory (cd) to where you extracted the library source
VS 2017 Approach:
Include the Windows SDK v7.1A directory (required for Win32.Mak by nmake later on) by running: set INCLUDE=%INCLUDE%;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
Run nmake /f makefile.win setup-v15 (note the v15 for VS2017 here)
From here on follow what #AthanasiusOfAlex explained to upgrade the Visual Studio 2010 solution to the Visual Studio version you are running. If you want the Debug configuration, follow what #SteveEng explained.
Errors you might stumble across:
If nmake fails and tells you it doesn't know how to make
jconfig.h, manually rename the file jconfig.vc to jconfig.h
If nmake fails and tells you Win32.Mak cannot be found, manually copy it from the SDK dir mentioned in step #4 to the libjpeg source directory. If you don't happen to have that SDK version installed, download the file from a trustworthy resource.
If nmake fails and tells you it doesn't know how to make setup-v15, trial and error your way through starting with setup-v10, setup-v11, etc... These are VS versions and one of them should work as long as you have any VS version later than VS 2008 installed.
Hope this helps people going through similar pain with this.
If you want debug mode as well in MSVC. Follow AthanasiusOfAlex's method, build the release, then:
Right-click on the project and select properties at the very
bottom
Click on configuration manager and on the active solution
configuration drop-down select -new-
Set the name to debug and on
the drop-down select copy configuration settings from release and
click OK
Close the dialog, go to general settings and under Target
Name add a d to the end so it looks like this: $(ProjectName)d
On Whole Program Optimization drop-down select: No Whole Program Optimization
Then click on the C/C++ under configuration properties on the left and on the Debug Information Format drop-down select C7 compatible (/Z7)
Under optimization select disabled and select NO for both Enable Fiber-Safe Optimizations and Whole Program Optimizations
Under preprocessor, preprocessor definitions, click on edit and use the following:
WIN32
_DEBUG
DEBUG
_LIB
_CRT_SECURE_NO_WARNINGS
Under code generation, under runtime library select Multi-threaded Debug DLL (/MDd)
Build and you're done!
This is for VS2019 with version number 16.0
Consider the Visual Studio Version name correctly like this for creating the .sln file.
Product name Code name Version number
Visual Studio 2019 Dev16 16.0
Visual Studio 2017 Dev15 15.0
Visual Studio 2015 Dev14 14.0
Visual Studio 2013 Dev12 12.0

How do I build boost with Visual Studio 2008 when I have multiple Visual Studio versions installed?

I know how to build boost with the latest visual studio on my machine (this question, for example)
However, I need to build the libs for Visual Studio 2008 (vc9)
I tried using toolset=vc9 but I get problems/no success.
How can I build the libs for vc9?
After I run boostrap I try running
b2 toolset=vc9
but the output is:
C:/Development/boost
50/boost_1_50_0/boost_1_50_0/tools/build/v2/build\toolset.jam:39: in
toolset.using rule vc9.init unknown in module toolset
C:/Development/boost
50/boost_1_50_0/boost_1_50_0/tools/build/v2\build-system.jam:481: in
process-explicit-toolset-requests
C:/Development/boost
50/boost_1_50_0/boost_1_50_0/tools/build/v2\build-system.jam:562: in
load
C:\Development\boost
50\boost_1_50_0\boost_1_50_0\tools\build\v2/kernel\modules.jam:283: in
import
C:\Development\boost
50\boost_1_50_0\boost_1_50_0\tools\build\v2/kernel/bootstrap.jam:142:
in boost-build
C:\Development\boost 50\boost_1_50_0\boost_1_50_0\boost-build.jam:17:
in module scope
toolset=msvc-9.0
I have VS2008-Pro and VS2010-Express installed. The default ran with VS2010. Setting toolset=msvc-9.0 caused the build to run with VS2008. Using Boost 1.51.0.
You'll need to dig into the How-To-Build-Boost documentation, and in particular see this;
but the part you need to specify a particular MSVC version is pointed to here. That suggests creating a user-config.jam, which probably would work, but I created a project-config.jam file instead.
I seem to be able to do this by running the top-level boost build (or meta build) script from different VC command lines. For example to build with VC2012, start a command line with vc 2012 vars. And for 2010, do the same. The automatically generated build scripts seem to do the right thing.
I am sure there are ways to do this by editing the build scripts myself or by setting the toolset, but I had no success with that.

'cl' is not recognized as an internal or external command,

I am trying to compile a hello world program in Qt Using Qt Creator.
I am getting 'cl' is not recognized as an internal or external command.
I am using Windows 7 and both VS 2008 and 2010 installed in it.
When I use Mingw it is compiling fine but if use vs 2008 it is giving this error.
After Setting Env Path = ..;..;C:\Program Files\Microsoft Visual Studio 9.0\VC\bin also it is showing the same error.
That error happens because cl isn't in your path. You need to add it there. The recommended way to do this is to launch a developer command prompt.
Quoting the article Use the Microsoft C++ toolset from the command line:
On the desktop, open the Windows Start menu. In Windows 11, choose the All apps button to open the list of installed apps. In Windows 10,
the list is open to the left. Scroll down the list to find and open
the folder (not the app) for your version of Visual Studio, for
example, Visual Studio 2022.
In the folder, choose the Developer Command Prompt for your version of Visual Studio. This shortcut starts a developer command
prompt window that uses the default build architecture of 32-bit,
x86-native tools to build 32-bit, x86-native code. If you prefer a
non-default build architecture, choose one of the native or cross
tools command prompts to specify the host and target architecture.
For an even faster way to open a developer command prompt, enter
developer command prompt in the desktop search box. Then choose the
result you want.
As the article notes, there are several different shortcuts for setting up different toolsets - you need to pick the suitable one.
If you already have a plain Command Prompt window open, you can run the batch file vcvarsall.bat with the appropriate argument to set up the environment variables. Quoting the same article:
At the command prompt, use the CD command to change to the Visual Studio installation directory. Then, use CD again to change to the
subdirectory that contains the configuration-specific command files.
For Visual Studio 2019 and Visual Studio 2017, use the
VC\Auxiliary\Build subdirectory. For Visual Studio 2015, use the VC
subdirectory.
Enter the command for your preferred developer environment. For example, to build ARM code for UWP on a 64-bit platform, using the
latest Windows SDK and Visual Studio compiler toolset, use this
command line:
vcvarsall.bat amd64_arm uwp
From the article, the possible values for the first argument are the following:
x86 (x86 32-bit native)
x86_amd64 or x86_x64 (x64 on x86 cross)
x86_arm (ARM on x86 cross)
x86_arm64 (ARM64 on x86 cross)
amd64 or x64 (x64 64-bit native)
amd64_x86 or x64_x86 (x86 on x64 cross)
amd64_arm or x64_arm (ARM on x64 cross)
amd64_arm64 or x64_arm64 (ARM64 on x64 cross)
I had the same problem.
Try to make a bat-file to start the Qt Creator. Add something like this to the bat-file:
call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
"C:\QTsdk\qtcreator\bin\qtcreator"
Now I can compile and get:
jom 1.0.8 - empower your cores
11:10:08: The process "C:\QTsdk\qtcreator\bin\jom.exe" exited normally.
Make sure you restart your computer after you install the Build Tools.
This was what was causing the error for me.
I had the same problem and I solved it by switching to MinGW from MSVC2010.
Select the Project Tab from your left pane. Then select the "Target". From there change Qt version to MinGW instead of VC++.
You will have to set environmental variables properly for each compiler. There are commands on your Program menu for each compiler that does that, while opening a command prompt.
Another option is of course to use the IDE for building your application.
I had this problem because I forgot to select "Visual C++" when I was installing Visual Studio.
To add it, see: https://stackoverflow.com/a/31568246/1054322
I had the same issue for a long time and I spent God knows how much on it until I accidentally figured what to do. This solution worked on windows 10. All you need to do is to add C:\WINDOWS\System32 to Path variable under User Variables in Environmental Variables... Note that if you add this to the system variables, it may also work. But, that didn't work for me.
You can use Command prompt for VS 2010 and then select the path that your boost located. Use "bootstrap.bat", you can successfully install it.
For me, this was related to the scenario described by Smi, with the difference being that vcvarsall.bat itself was failing due to an invalid path.
This was cause by line-breaks within the path, which meant vcvarsall.bat couldn't find the common tools directory for some reason.
I sometimes get this problem when changing from Debug to Release or vice-versa. Closing and reopening QtCreator and building again solves the problem for me.
Qt Creator 2.8.1; Qt 5.1.1 (MSVC2010, 32bit)
I faced this error too, checked that there are multiple versions of common tool variables for visual studio in my environment variables (VS120COMNTOOLS, VS110COMNTOOLS and so on) for different visual studio versions.
I removed the ones I did not need from the environmental variables and the issue was resolved.
I was facing the same issue and tried many solutions but nothing work ( I was using vscode 2017) . I just upgraded vscode to 2022 version and the problem is automatically

How to build Qt for Visual Studio 2010

I struggled finding a how-to which provides a stable solution for using Qt with Visual Studio 2010, so after collecting all the bits of information and some trial and error, I would like to write my solution into a guide.
The problem, or why is it not possible to use prebuilt binaries?
It seems that using binaries built for Visual Studio 2008 might work in some special cases, but I found them not to work. In my case they compiled OK, but they produce runtime errors, like this:
or when started from Visual Studio 2010:
Update: I found a blog post analysing why does it work for some people, while it does not for others. In one word, it depends on whether you have Visual Studio 2008 installed on the same machine, or not.
http://blog.paulnettleship.com/2010/11/11/troubleshooting-visual-studio-2010-and-qt-4-7-integration/
The most important thing (that I stupidly didn’t realize) was the fact that you CANNOT use the Visual Studio 2008 compiled libraries and dll’s (available on the Qt webpage) if you don’t have Visual Studio 2008 installed. The reason is because the Qt SDK you download is a debug build which is dependant on the VC9.0 DebugCRT, meaning it needs the Visual C++ 2008 Debug Runtime installed, which is NOT available as a redistributable installer. The only way to install the DebugCRT is to install the entirety of Visual Studio 2008.
First of all, it’s very important to understand that for using Qt with Visual Studio 2010, it's not possible to use the pre-built binaries which were made for Visual Studio 2008, but you have to compile it from source.
Downloading Qt
On https://www.qt.io/download/
Update 2017: the latest Qt 4.x branch (Qt 4.8.6) has 2 pre-built packages, which are now in the archive section:
http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2010-4.8.6.exe
http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2008-4.8.6.exe
You should not download Qt by clicking "Qt libraries 4.8.6 for Windows (Visual Studio 2008, 218 MB)", but by clicking on the "zip" link above it.
On that link, you get a big zip file like "qt-everywhere-opensource-src-4.8.6.zip". Unzip this into a folder and make its path something nice and small, for example "E:\Qt"
Visual Studio Command Prompt
Now that we have the sources, we need to build the binaries. To do it, open the Microsoft Visual Studio 2010\Visual Studio Tools\Visual Studio Command Prompt (2010) link from your start menu, or even pin it to the taskbar (a good idea). This is a special command prompt which has all the variables set for building with Visual Studio 2010 tools.
Once within the command prompt, navigate to your extracted Qt folder using old-school DOS way, which means you have to change drive letter by E:, enter directories by cd Qt and list dir contents by dir. You can use the tab key for helping you with the directory names. When you have arrived at the correct directory, a dir command should return something like this.
Building Qt
Now it’s time for configure and build. For configuring a minimalist Qt, I'm using the following flags with configure.exe. Just copy and paste it into the command line. Look in the Qt reference manual for what flag to use or not to use.
configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg
Once configure.exe has finished (it was 10 minutes for me), you'll need to start the build process. It will take about 20-30 minutes with the above flags. To start it, just type:
nmake
Setting environment variables
Basically, we are done. All you need to do is to set your environment variables (QTDIR and PATH), which tell programs where to find Qt. If you are on Windows 7, you can use the following command to set QTDIR to your installation dir.
setx QTDIR e:\Qt
For setting the PATH, I strongly recommend using Path Editor. Within Path Editor
add the directory of Qt\bin to your PATH
(it doesn't matter if it's in system path or user path)
If you prefer to use Control Panel\System\Environment Variables, then you can set these there, too.
Qt Visual Studio Add-in
Here you go, after a logoff-logon or a restart, all the Qt demo applications should start correctly (I recommend have a look at bin\qtdemo.exe). Now you can download and install the Visual Studio Add-in (qt-vs-addin-1.1.9.exe) from the Qt download page, it will work perfectly.
Appendix A: Official Instructions:
There is a page at the official wiki at the Qt website called Qt 4.8 Installing Qt for Windows, but I found it lacking important information.
References
Qt DevNet forums
Recommended flags for a minimalistic Qt build
Building Qt 4.5 with Visual C++ 2010
How to compile Qt as static
Qt 4.8: Configure options for Qt
Edit the PATH environment variable in
Windows without pain - op111.net
Qt V4.8.0 contains prebuilt binaries for Visual Studio 2010 so you don't need to do this anymore:
http://qt.nokia.com/downloads/windows-cpp-vs2010
Refer below link and it might be useful
1)https://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/Build_Instructions/Prerequisites/Qt#Windows_3
2)http://eecs.vanderbilt.edu/research/hmtl/wp/index.php/qt-vs/