I am trying to compile a simple PETSc program (Which works when compiled in Cygwin) in Visual Studio 2019. But I am unable to compile it in VS2019 even after linking all the necessary library files. I have given below the options I have used in VS2019 for compiling petsc program. I see that the compiler is not able to identify the Petsc variables which leads me to believe that I have not done the library linking part properly.
My guide for linking the files is from compiling the program in cygwin using the following command (compiles and run perfectly):
/home/snarayanan1/petsc-release/lib/petsc/bin/win32fe/win32fe.exe ifort -MT -O3 -fpp -I/home/snarayanan1/petsc-release/include -I/home/snarayanan1/petsc-release/arch-ci-mswin-opt-impi/include -I/cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/2021.5.0/include petsc_solver.F90 Test_petsc.F90 -L/cygdrive/c/cygwin64/home/snarayanan1/petsc-release/arch-ci-mswin-opt-impi/lib -L/cygdrive/c/PROGRA~2/Intel/oneAPI/mkl/2022.0.0/lib/intel64 -lpetsc mkl_intel_lp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib /cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/2021.5.0/lib/release/impi.lib Gdi32.lib User32.lib Advapi32.lib Kernel32.lib Ws2_32.lib -o Test_petsc
Fortran -> General -> Additional Include Directories:
C:/cygwin64/home/snarayanan1/petsc-release/include; C:/cygwin64/home/snarayanan1/petsc-release/arch-ci-mswin-opt-impi/include; C:/Program Files (x86)/Intel/oneAPI/mpi/2021.5.0/include
Linker -> General -> Additional Library Directories:
C:/cygwin64/home/snarayanan1/petsc-release/arch-ci-mswin-opt-impi/lib; C:/Program Files (x86)/Intel/oneAPI/mkl/2022.0.0/lib/intel64; C:/Program Files (x86)/Intel/oneAPI/mpi/2021.5.0/lib/release
Linker -> Input -> Additional Dependencies:
libpetsc.lib mkl_intel_lp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib C:/Program Files (x86)/Intel/oneAPI/mpi/2021.5.0/lib/release/impi.lib Gdi32.lib User32.lib Advapi32.lib Kernel32.lib Ws2_32.lib
This image shows the errors I get
Can someone let me know where I am going wrong (or) direct me to documentation that talks about linking PETSc to visual Studio in detail?
Thank You.
The configurations that you have done look fine to me. The issue you ran into arises from other places.
Try
Fortran Tab:
• Preprocessor | Preprocess source files | Yes
Related
We have a large cmake based C++ project for Linux where we build boost ourselves via cmake exernal project.
The project used to build also on Windows for the classical Intel compiler. But I have no access to this old running configuration.
I use Intel oneAPI 2023.0 with LLVM based icx compiler (clang 15?) and a current MSVC community edition.
I built boost (1.81.0) without a target (as I still struggle with openAPI target) with --layout=system, hence lib names like libboost_atomic.a
In our C++ we do not let CMake search for boost but add the boost libs via target_link_libraries().
When I compile our application with icx I get a link error
Linking CXX executable ....\bin\cfs.exe LINK: command
"C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin\icx.exe /nologo
#CMakeFiles\cfs.dir\objects1 /Qoption,link, /machine:x64
/INCREMENTAL:NO /Qoption,link,/subsystem:console -Qiopenmp
/Qoption,link,/LIBPATH:C:\PROGRA~2\Intel\oneAPI\compile
r\latest\windows\bin\intel64\ifort.exe
/Qoption,link,/LIBPATH:C:\Users\fabia\code\master\release_icx\lib
[....] ....\lib\libboost_log_setup.lib
....\lib\libboost_serialization.lib [.....] /link
/out:....\bin\cfs.exe /implib:. ...\bin\cfs.lib
/pdb:C:\Users\fabia\code\master\release_icx\bin\cfs.pdb /version:0.0
/MANIFEST /MANIFESTFILE:....\bin\cfs.exe .manifest"
I get
fatal error LNK1104: file
"libboost_serialization-clangw16-mt-x64-1_81.lib" not found.
I have no idea where the string clangw16-mt-x64-1_81 comes from.
You can link the libraries present in the boost library path to your project either from the Command Prompt or within the Visual Studio IDE. Please refer to the below link for more details.
https://www.boost.org/doc/libs/1_81_0/more/getting_started/windows.html
If you do not find any binaries, you can add the macro BOOST_ALL_NO_LIB which tells the config system not to automatically select which libraries to link. Please refer to the below link for more details.
https://www.boost.org/doc/libs/1_81_0/libs/config/doc/html/index.html
Or
You can use the target Boost::disable_autolinking to disable automatic linking. Please refer to the below link for more details.
https://cmake.org/cmake/help/latest/module/FindBoost.html
I am running CMake from under CLion and when identifying CUDA compiler, it apperently uses too long paths, and fails (according to CMakeError.log file):
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
Build flags:
Id flags: --keep;--keep-dir;tmp -v
The output was:
1
D:\TESTS\CUDA_CLion\test01\cmake-build-debug\CMakeFiles\3.19.1\CompilerIdCUDA>call "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat"
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.2
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
The input line is too long.
The syntax of the command is incorrect.
#$ C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat
nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'
...
The command it runs is (according to CMake pane of CLion):
D:\Apps\CMake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug --debug-output -G "CodeBlocks - NMake Makefiles" D:\TESTS\CUDA_CLion\test01
If I run this command from CLI, it also fails, but with different error:
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
Build flags:
Id flags: --keep;--keep-dir;tmp -v
The output was:
1
nvcc fatal : Cannot find compiler 'cl.exe' in PATH
And finally, if I just run
cmake ..
from CLI it works: it finds itself Ok with long paths, it finds cl.exe, everything.
The question is: how to fix everything OR how to force CLion just to use only CMake without imagination?
Did your script invoke vcvarsall.bat or vcvars64.bat multiple times?
It could be solved by reduce them
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.
Build messages:
ld.exe cannot find -lSDLmain
ld.exe cannot find -lSDL
Build log:
c:/program files
(x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe:
cannot find -lSDLmain
c:/program files
(x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe:
cannot find -lSDL
Please help.
Its not letting me run any of my previous or new projects.(All console applications/projects)
I have checked
settings - global variables
the include and lib paths are correct as well as the base directory.
I recently tried to setup SDL2 but then I uninstalled Code::blocks completely.
Why is it trying to find -lSDLmain and -lSDL?
Also tried reinstalling code::blocks and the Rebuild other than just Build, still
does not work.
I checked this post: Cannot find -lSDLmain and -lSDL when compiling simple SDL program with g++
but the answer talks about letting your MinGW know where your SDL libraries are.
But I'm not even working with SDL.
Using GNU GCC compiler.