How to locate C, C++, and Fortran compilers on my win7x64 machine? - c++

I'm trying to build binary files of the LAPACK 3.7.0 using CMAKE based on what is told here. In order to use them in my Visual Studio 2013 C++ project.
But I really don't know which option should I choose here?
And also which compilers should I choose in the following?
Because I can't find them in the suggested directories within Program Files or Program File(x86) folders.
my machine uses a dual-core Intel(R) Core(TM) 2 Duo CPU

When using Visual Studio < 2015, a common solution is to run CMake GUI from Visual Studio Command line.
Use windows start menu to run "Visual Studio Command Prompt"
Run cmake-gui from command line. If the folder is in your path, simply launch cmake-gui. If not, launch it using the full path
Locate the source folder of your project (the folder containing the top-level CMakeLists.txt) and create a new build folder (ex c:/my-project/build_32). Generating an environment in the source folder is discouraged)
Generate your project selecting the right MSVC version. In your case, it will be "Visual Studio 12 2013". In my case, this is MSVC 2010.
That's all. Click on finish button and it should generate the compilation environment, solutions, projetcs, etc.
This will generate environment for compiling x86 application. If you also need to compile a x64 version of your project, simply follow again that process, generating in a new build folder and selection "Visual Studio 12 2013 Win64".
By default, if you have a paid version of Visual Studio you have both x86 and Win64 compiler installed. If you have the express version, you only have the x86 compiler (so generation using MSVC Win64 will fail).

Related

SCons detects Visual C++ v14.2 (2019) but not v14.1 (2017)

I need to build a dependency that uses SCons, and I need to build it with VC++2017, because another dependency I have cannot be built with VC++2019.
SCons successfully detects VC++2019 (v14.2), but not VC++2017 (v14.1):
c:\Python27\Scripts\scons [...] --msvc-version=14.1 [...]
scons: Reading SConscript files ...
scons version: 3.1.1
python version: 2 7 13 'final' 0
scons: warning: VC version 14.1 not installed. C/C++ compilers are most likely not set correctly.
Installed versions are: ['14.2', '14.0', '11.0']
[...]
C++ compiler $CC does not work
I have installed Visual Studio 2019 Enterprise as well as Visual Studio 2019 Build Tools, and for both, I have installed the platform tools / compiler for v14.1 and x86/x64. Compiling with the VC++2017 platform tools works fine in Visual Studio 2019 as well as using MSBuild, so the problem seems to be with SCons only.
How does SCons detect VC++2017 and VC++2019 and where should I start looking for the problem?
(There are old threads about this, but most of them are about people wondering why the "classic" detection/config methods using registry and vcvars.bat no longer work, so these are not helpful)
For current scons, it will believe what it gets back from vswhere.exe for the versions where that tool is considered definitive - 2017 and 2019. You can try seeing what that gives you.
vswhere -products * -property installationPath
That information is used to help locate the desired vars.bat file which imports the seetings needed.
I have found a perfect and simple solution:
Open file MSCommon/vc.py, find line: vc_pdir = os.path.join(vsdir[0], 'VC')
Change [0] to [1]
Re-build, the python will use vs2017
The reason is: if you install multi vs versions, the vsdir[0] is the highest one
Update: This is still (2021-09-16) an issue, and a simple workaround may be this answer - My answer also has a workaround, but it is more complicated and mostly for educational purposes on how recent versions of VC++ compilers can be detected and are (not properly) detected by SCons. You may also want to use my workaround if you are creating a build script for a build server or multiple development machines with varying setups.
The current version of SCons does not support selecting MSVC v14.1 (aka "Visual C++ 2017") if Visual Studio 2019 is installed, but Visual Studio 2017 is not. I confirmed this by looking at the code of SCons (see below).
An alternative approach is to use the --msvc-script option instead of --msvc-version.
In the MSVC installation folder, typically c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\, you will find a file called vcvarsall.bat. If you run this without arguments, you will see that you can give it arguments for target platform and tools version, e.g.,
vcvarsall.bat x86 10.0.17763.0 -vcvars_ver=14.1
to compile for x86 (32-bit), Windows SDK version 10.0.17763.0 and tools version 14.1 (Visual C++ 2017).
Once you have found a command line for vcvarsall.bat that suits you, put it into a new BAT file that you create, say myvcconfig.bat (You have to use the complete path to vcvarsall.bat), then use the following command-line switch to SCons: --msvc-script=myvcconfig.bat.
*** Notes ***
Some parameters to SCons are redundant and will not work with --msvc-script, for example --32. SCons will tell you about them, so just remove them from the command-line.
The installation path of Visual Studio may be different from the one I provided above. You can find the installation path using Microsoft's own VSWhere tool. See also Locate Visual Studio
Visual Studio 2019 and Visual Studio Build Tools 2019 are separate installations with separate build tools. You can detect and use the vcvarsall.bat files of either ones. For example, if you are setting up a toolchain for a build server, you may want to use Visual Studio Build Tools 2019. If you just want to build one library one time (as in my case), just use the Visual Studio that is installed on your dev machine.
In case you are interested in how SCons detects MSVC and why it doesn't work, you can look at the source code in SCons/Tool/MSCommon/vc.py. You can clone the SCons GIT repository.
UPDATE: The following comment in vc.py (as of 2021-09-16) shows why this is still an issue in SCons and why this workaround is needed if you have both VC2017 and VC2019 compilers installed:
# make sure the cl.exe exists meaning the tool is installed
if ver_num > 14:
# 2017 and newer allowed multiple versions of the VC toolset to be
# installed at the same time. This changes the layout.
# Just get the default tool version for now
#TODO: support setting a specific minor VC version
Direct link (valid at time of writing)

The build tools for Visual Studio 2008 (Platform Toolset = 'v90') cannot be found

I'm trying to build project c++ on vs2017 but there error appear:
"The build tools for Visual Studio 2008 (Platform Toolset = 'v90') cannot be found " after navigation, I must download VS 2008 I have installed it, but problem still exist .
any Suggestion ?
You need:
An MSVC 9.0 compiler toolchain
https://wiki.python.org/moin/WindowsCompilers lists the products that have it:
VS 2008, "Visual C++" feature and "x64 compilers and tools" subfeature
Express edition only has x86 compilers
Do install SP1 on top of VS2008 -- in vanilla VS2008 installer, installation for many features, including x64 compilers, is broken
WinSDK 6.1
WinSDK 7.0
"Visual C++ Compiler for Python 2.7" package
MsBuild 4.0 toolset configuration files for the above toolchain. (These are the directories c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\<arch>\PlatformToolsets\v90\ with .props and .targets files in them)
The only product I know that has this package is VS 2010 ("Visual C++" feature and "x64 compilers and tools" subfeature).
(WinSDK 7.1 technically has it, too, but its setup is riddled with bugs and broken on an x64 system.)
(You can bypass the buggy installer though if you install <GRMSDK_EN_DVD.iso>\Setup\vc_stdx86\vc_stdx86.msi directly. Despite the name, it has toolset files for all 3 platforms.)
"Visual C++ Compiler for Python 2.7" package is not supported by these toolset configuration files. So if you use it, you'll need to either manually specify its location in one of registry values specified in .props, or modify .props to also look in HKLM\Software\Microsoft\DevDiv\VCForPython.
The projects are targeting the v90 platform toolset. The solution is to either open the .sln file with VS2008 (i.e. use the right tool), or spend some time updating the projects to target the latest platform toolset (i.e. VS2017). To do that, just right click each project, and go to Properties, then look at General | Windows SDK Version. You may have to fix compilation / linker errors following the project upgrade.
It is possible to upgrade the project file from the command line without opening it in Visual Studio. I was running into the same issue, and found another solution in the Microsoft documentation for Visual Studio (https://learn.microsoft.com/en-us/visualstudio/ide/reference/upgrade-devenv-exe?view=vs-2017).
Here are the steps:
Open the developer command prompt for you version of Visual Studio, e.g. 'Developer Command Prompt for VS 2017'.
Navigate to the directory of your project file.
Execute the following command: devenv myproject.sln /upgrade

How to build on TFS a c++ native project targeting Win10 platform

A migrated VS2013 c++ native project to vs2015 targeting Windows 10 (instead of Win 8.1) gives me some issues on the TFS Build Server. I use TFS2013 and the Release12 Build Process Template.
The TFS2013 is installed on a Win10 machine with VS2015 installed on it.
When I run the build the build throws an exception in one of the tasks from the target files saying that it can't compare the numeric number 10.0.4 ... something, because that is the Target Platform set in the native project file. Obviously this is not a number with it's two dots in the version number.
Am I doing something wrong? The TF Build uses MS Build v12 by the way and not the MS Build v14 that ships with VS2015. Do I need to change to MSBuild v14 to make this work? If yes, how can I actually change the used MSBuild version?
Can you provide more information about your exception and build file?
I'm not sure is it realed to MSBuild V14.
If You want to amend the build templates to point to MS Build version 14.0. You can folow below steps :
Use the Default Template (TfvcTemplate.12.xaml) in Visual Studio
Open the template and find the Run MSBuild for Project MSBuild activity.
Set ToolVersion to "14.0".
Set ToolPath to target to MSBuild14 (by default: "C:\Program Files (x86)\MSBuild\14.0\Bin").
Check in this build process template and re-queue the build.
If you still have the same problem after you use MSBuild V14.0.
There is a realted version with 10.0.4... in VS2015. MinimumVisualStudioVersion = 10.0.40219.1 .It means the minimum visual studio version supported in VS2015. Maybe you build a file that created by a visual studio which version is earlier than the version10.0.40219.

'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/