Currently, I am using the command:
clang++ -o hello.exe hello.cpp
Is there any way to set the target platform, for example if I wanted to build targeting x86 or ARM on my x64 computer. In visual studio, you can easily set this under configurations. I am using clang front end and LLVM back end.
Related
In the project properties page of CUDA project in visual studio, there seems to be the option to custom the host compiler. But after I selected the intel C++ compiler, the -ccbin option still points to the cl.exe.
selecting intel C++ compiler as the platform toolset
the -ccbin option still points to cl.exe
I do understand that under windows environment, the default host compiler for CUDA project is cl.exe and the following posts confirmed that cl.exe was the only option on windwos. But these were quite some time ago, I'd like to ask again if this is still the case or we use a different host compiler now?
Intel C++ Composer and CUDA
Specify compiler NVCC uses to compile host-code
It's still the case. The only supported environments are listed in the installation guide for windows. The intel compiler is not listed.
By comparison, the corresponding section of the linux installation guide shows that a certain version of the intel compiler (ICC) is supported for the host compiler.
In the future, you should be able to refer to the corresponding documents published with newer CUDA toolkits to determine compiler support.
I often find myself using Intel C++ together with CUDA for fluid simulations, and I may be able to help if you are still interested in an answer.
You have not specified which version of Visual Studio you are referring to, but I imply that you are talking about Visual Studio Professional/Enterprise or any of that line of fully featured IDEs.
While I haven't extensively used any of those, there is a way of using Intel C++ (and by extension, any compiler) with CUDA, in Visual Studio Code. If you decide to go this route, and since you mentioned Windows, here is the procedure:
To make things simple, download the C++ tutorial build from here. If you want to make the build yourself, instructions are found on MSDN here.
After the download, you should have a build.bat file in the project directory. Open the file to edit it.
Replace everything inside the build.bat file as follows:
#echo off
call "Path\to\compilervars.bat" intel64
call "Path\to\vcvarsall.bat" x64
set compilerflags=/Zi /EHsc -I"%MKLROOT%"\include
set linkerflags= mkl_intel_ilp64.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib
icl.exe /Foobj\helloworld /Fdobj\ -c -I. -I"%CUDA_PATH%"\include %compilerflags% helloworld.cpp /link %linkerflags%
"Path\to\nvcc.exe" -gencode=arch=compute_61,code=\"sm_61,compute_61\" -IPath\to\CUDA\include -G -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN64 -DNDEBUG -D_CONSOLE -Xcompiler "/EHsc /W3 /nologo /Od /FS /Fdobj\ /Zi /RTC1 /MD /MP" -o obj\hello2.obj "hello.cu"
icl.exe -o bin\hello.exe /Fdobj\ obj\hello2.obj obj\helloworld.obj "%CUDA_PATH%"\lib\x64\cudart.lib %compilerflags% /link %linkerflags%
In other words, we tell the build process to:
Look for the compilervars.bat file (found in Intel C++ compiler /bin folder) and set Intel specific macros and variables for the build process
Look for the vcvarsall.bat file (found in Visual C++ compiler /VC folder) and set Visual C++ specific macros and variables for the build process
Set the Compiler and Linker Flags for the Intel C++ compiler.
IMPORTANT: Call the Intel C++ compiler to generate an Obj file from all the non-CUDA (i.e. .cpp files of the project - In this case, helloworld.cpp) and also include the CUDA headers if you need them. Make sure no CUDA kernel calls (functions with <<< >>>) happen here.
THEN: Call the CUDA compiler to generate an Obj file from all the CUDA files (i.e. the .cu extensions - In this case, hello.cu), in this case, I call the Obj file hello2.obj (I explicitly renamed it to show you how to do that).
FINALLY Call the C++ Compiler to generate the executable file by mentioning both Obj files as well as the cudart library for static linking.
Note that CUDA still needs VC++ so we allow it to access VC++ for only the part where it compiles CUDA files (which is why we had to initialize vcvarsall.bat), and stick to Intel C++ for the rest.
In the project properties page of CUDA project in visual studio, there seems to be the option to custom the host compiler. But after I selected the intel C++ compiler, the -ccbin option still points to the cl.exe.
selecting intel C++ compiler as the platform toolset
the -ccbin option still points to cl.exe
I do understand that under windows environment, the default host compiler for CUDA project is cl.exe and the following posts confirmed that cl.exe was the only option on windwos. But these were quite some time ago, I'd like to ask again if this is still the case or we use a different host compiler now?
Intel C++ Composer and CUDA
Specify compiler NVCC uses to compile host-code
It's still the case. The only supported environments are listed in the installation guide for windows. The intel compiler is not listed.
By comparison, the corresponding section of the linux installation guide shows that a certain version of the intel compiler (ICC) is supported for the host compiler.
In the future, you should be able to refer to the corresponding documents published with newer CUDA toolkits to determine compiler support.
I often find myself using Intel C++ together with CUDA for fluid simulations, and I may be able to help if you are still interested in an answer.
You have not specified which version of Visual Studio you are referring to, but I imply that you are talking about Visual Studio Professional/Enterprise or any of that line of fully featured IDEs.
While I haven't extensively used any of those, there is a way of using Intel C++ (and by extension, any compiler) with CUDA, in Visual Studio Code. If you decide to go this route, and since you mentioned Windows, here is the procedure:
To make things simple, download the C++ tutorial build from here. If you want to make the build yourself, instructions are found on MSDN here.
After the download, you should have a build.bat file in the project directory. Open the file to edit it.
Replace everything inside the build.bat file as follows:
#echo off
call "Path\to\compilervars.bat" intel64
call "Path\to\vcvarsall.bat" x64
set compilerflags=/Zi /EHsc -I"%MKLROOT%"\include
set linkerflags= mkl_intel_ilp64.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib
icl.exe /Foobj\helloworld /Fdobj\ -c -I. -I"%CUDA_PATH%"\include %compilerflags% helloworld.cpp /link %linkerflags%
"Path\to\nvcc.exe" -gencode=arch=compute_61,code=\"sm_61,compute_61\" -IPath\to\CUDA\include -G -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN64 -DNDEBUG -D_CONSOLE -Xcompiler "/EHsc /W3 /nologo /Od /FS /Fdobj\ /Zi /RTC1 /MD /MP" -o obj\hello2.obj "hello.cu"
icl.exe -o bin\hello.exe /Fdobj\ obj\hello2.obj obj\helloworld.obj "%CUDA_PATH%"\lib\x64\cudart.lib %compilerflags% /link %linkerflags%
In other words, we tell the build process to:
Look for the compilervars.bat file (found in Intel C++ compiler /bin folder) and set Intel specific macros and variables for the build process
Look for the vcvarsall.bat file (found in Visual C++ compiler /VC folder) and set Visual C++ specific macros and variables for the build process
Set the Compiler and Linker Flags for the Intel C++ compiler.
IMPORTANT: Call the Intel C++ compiler to generate an Obj file from all the non-CUDA (i.e. .cpp files of the project - In this case, helloworld.cpp) and also include the CUDA headers if you need them. Make sure no CUDA kernel calls (functions with <<< >>>) happen here.
THEN: Call the CUDA compiler to generate an Obj file from all the CUDA files (i.e. the .cu extensions - In this case, hello.cu), in this case, I call the Obj file hello2.obj (I explicitly renamed it to show you how to do that).
FINALLY Call the C++ Compiler to generate the executable file by mentioning both Obj files as well as the cudart library for static linking.
Note that CUDA still needs VC++ so we allow it to access VC++ for only the part where it compiles CUDA files (which is why we had to initialize vcvarsall.bat), and stick to Intel C++ for the rest.
I have installed Qt 5.1.1 with MinGW 4.8 and QtCreator through Qt Online installer.
I launched Qt creator and made new project (Qt application Desktop) with MainWindow class based on QMainWindow (default). It works fine and popped up a mainwindow after compilation.
However, when I used C:\Qt\Qt5.1.1\Tools\QtCreator\bin\jom.exe instead of C:\Qt\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe , I got some output like below.
jom 1.0.13 - empower your cores
C:\Qt\Qt5.1.1\Tools\QtCreator\bin\jom.exe -f Makefile.Release
g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../foobar -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtWidgets' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtGui' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtCore' -I'release' -I'.' -I'.' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/mkspecs/win32-g++' -o release/main.o ../foobar/main.cpp
In file included from ../foobar/main.cpp:1:0:
../foobar/mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^
compilation terminated.
jom: D:\work\build-foobar-Desktop_Qt_5_1_1_MinGW_32bit-Release\Makefile.Release [release\main.o] Error 1
jom: D:\work\build-foobar-Desktop_Qt_5_1_1_MinGW_32bit-Release\Makefile [release] Error 2
15:17:38: Process "C:\Qt\Qt5.1.1\Tools\QtCreator\bin\jom.exe" stopped with code 2
Error while building/deploying project foobar (kit: Desktop Qt 5.1.1 MinGW 32bit)
During step 'Make'
15:17:38: Elapsed time: 00:00.
My .pro is like this.
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-08T15:16:13
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = foobar
TEMPLATE = app
SOURCES += main.cpp\ mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I think the line in .pro greaterThan(QT_MAJOR_VERSION, 4): QT += widgets and in the output during compilation -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtWidgets' looks fine, but failed.
How can I compile with Qt 5.1 and jom on Windows 7 (32 bit)?
Thanks in advance.
Jom is a replacement of nmake and not MinGW's make.
nmake is the Visual Studio command line tool used to compile makefiles. Unfortunately that tool is using only one core (Parallel builds are handled inside Visual Studio either directly or using MSBuild, I'm not really sure). That being said, Jörg Bornemann wrote a tool called jom that sort of adds the -j command to nmake. It will allow you to compile your code using the Visual C++ compiler across different threads.
MinGW on the other end contains (amongst other things) a port of the GNU GCC compiler for Windows. Being a port, not everything that is possible to do with GCC is possible with MinGW and I guess that -jN is one of these. However, MinGW do support the option -j that will spawn as many processes as it can (beware that if you use this option, you may not be able to use your computer whilst compiling).
In your case, you probably want to use MinGW as your Qt version is compiled with it. If you want to use Visual Studio, you will have to install it but also either:
recompile Qt (and all other library dependencies) or
download the binary corresponding to the Visual Studio version you just installed.
Using jom should just work with QtCreator once this is done.
In my case I fixed this error by overriding system environment PATH in project settings by adding only bin path to qt, mingw and qtcreator: "E:\Qt\4.8.1\bin;E:\qt\mingw-4.4.0\bin;E:\Qt\qtcreator-4.0.0\bin" and after Run qmake and Rebuild
I've downloaded MinGW from this link x64-4.8.1-posix-sjlj-rev1 but when I try to build for x86 target I've lots of linkage errors... seems that only x64 lib are installed...
I've need to build for x86 and x64 platforms on windows... Have I to download both x64 and x86 or are some simpler ways?
Edit I'm using eclipse keplero as IDE
I've tryed to build myself a simple hello world program with g++ -m32 -std=c++11 test.cpp -o test32.exe and g++ -m64 -std=c++11 test.cpp -o test64.exe. And all is ok... So the problem was with eclipse... After a little a discovered that I need to use MYSY ( set in PATH ) and set -m32 also in the c++ linkage options...
Now all is fine.
I've also tryed to use NetBeans C++ as IDE... seems a gread IDE!!!
It is not multilib enabled. That's why you are not able to compile 32-bit(x86) program. You can get multilib enabled toolchain from following link:
For 64-bit machine: 64-Bit
For 32-bit machine: 32-Bit
I have recently downloaded the mingw-w64 package under Fedora Linux in order to be able to cross compile targetting both win32 and "Windows 64". But I fail to understand how to specify what target I want to use. What flags do I need to supply to gcc and to the linker in order to choose my target architecture?
W32 and W64 are two different architectures, so you distinguish by compiler name. The debian mingw-w64 calls them i686-w64-mingw32-gcc for Win32 and x86_64-w64-mingw32-gcc for Win64.