Include paths for nvcc on windows - windows

I'm trying to compile a CUDA C code in Windows command line. I've already installed cuda toolkit and nvcc works fine. But the code includes png.h and I'd like to know what is the proper way to provide it.
Specifically, I want to learn what are the default directories in which nvcc looks for headers and .dlls. And how should I install such standard C libraries: do I necessarily have to use MinGW and somehow add C:\MinGW\include and C:\MinGW\bin to the PATH?
Currently my solution looks in the following way:
$ nvcc mandelbrot-dynamic.cu -O3 -arch=sm_35 -rdc=true -lcudadevrt -Xcompiler -fopenmp -Ic:/mingw/include/ -o dynamic
And the result is:
cl : Command line warning D9002 : ignoring unknown option '-fopenmp' mandelbrot-dynamic.cu
c:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/amd64/../../../VC/INCLUDE\yvals.h(472) : warning C4005: '_EXTERN_C' : macro redefinition
c:/mingw/include/_mingw.h(258) : see previous definition of '_EXTERN_C'
c:/mingw/include/float.h(38) : fatal error C1021: invalid preprocessor command 'include_next'
It doesn't complain about png.h but there is conflict between MSVC and MingW. Plus, nvcc doesn't accept a preprocessor command from a mingw header.

Related

How do I cross-compile scons (with gcc) on Windows with Visual Studio installed?

I have an existing makefile project that I am migrating to scons.
The makefile builds several Windows executables with gcc and g++.
However, I also have Visual Studio installed for C# development.
It appears that scons is trying to use the Visual Studio tools rather than the gcc ones:
cl /Fofoo\bar.o /c foo\bar.c /nologo -g -mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs /D-DUNIT_TESTS /I. <more includes follow...>
cl : Command line warning D9002 : ignoring unknown option '-g'
I have read several answers and have tried adding:
env["CC"] = "gcc"
env["CXX"] = "g++"
env["LINK"] = "g++"
in my Sconstruct file. This has the effect of correctly changing the tool, but not the command syntax:
gcc /Fofoo\bar.o /c foo\bar.c /nologo -g -mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs /D-DUNIT_TESTS /I. <more includes follow...>
gcc: error: /Fofoo\bar.o: No such file or directory
How can I ensure that scons uses my desired tools and also uses the correct syntax for the command line options (e.g. -I instead of /I)?
If I have to guess the issue your SConstruct is something like this:
env=Environment()
env["CC"] = "gcc"
env["CXX"] = "g++"
env["LINK"] = "g++"
env['CCFLAGS']='-mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs'
env['CPPDEFINES']=['-DUNIT_TESTS']
env['CPPPATH'] = ['.']
Given that the default list of tools to configure on Windows is the following in order and it will stop configuring tools once it finds one of these and then it sets up the flags which should work for such tools.
c_compilers = ['msvc', 'mingw', 'gcc', 'intelc', 'icl', 'icc', 'cc', 'bcc32']
You'll need to explicitly list the tools you want initialized (And not allow SCons to add the default tools) and the PATH they will be found in. Also your CPPDEFINES should be ['UNIT_TESTS'] and not ['-DUNIT_TESTS'] SCons will add the appropriate flags. Note you may need to add other tools if you are using them in your build.
env=Environment(tools=[])
env.AppendENVPath('PATH', PATH_TO_YOUR_COMPILERS)
for tool in ['gcc','gnulink','ar']:
env.Tool(tool)
env['CCFLAGS']='-mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs'
env['CPPDEFINES']=['UNIT_TESTS']
env['CPPPATH'] = ['.']

Can't compile restbed on Windows 7

I'm a the end with 16 hours of configure, installing, deleting, modifying and hit my keyboard many times....
I want to use restbed for plattform independent C++ programming, but I can't get build this stuff. I have Cygwin (download at 2017/04/24) installed (think for git or whatever creepy things), Code::Blocks with MinGW (16.01) and at least a seperate MinGW (also downloaded 2017/04/24) installation. Also I've Visual Studio 2012 Pro, 2015 and 2017 (long story) on a Windows 7 x64 Pro.
This is what I try and the results:
cloning recursivly with git in empty directory and following the instructions.
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=NO -DBUILD_SHARED=YES ..
Uhh.. success. I seems it using the gcc/g++ from Cygwin.
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
:
:
-- Configuring done
-- Generating done
-- Build files have been written to: /cygdrive/d/Entwicklung/C++/restbed/restbed/build
Nice! Now follows:
make -j install
After 7% working, it gives a bunch of warnings and failed:
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:755:5: warning: #warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. [-Wcpp]
# warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
^
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:756:5: warning: #warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line. [-Wcpp]
# warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line.
^
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:757:5: warning: #warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target). [-Wcpp]
# warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
^
/cygdrive/{my_path_to}/restbed/restbed/dependency/asio/asio/include/asio/detail/config.hpp:781:5: error: #error You must add -D__USE_W32_SOCKETS to your compiler options.
I modifing config.hpp and add
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
The 'define bla' warnings dissapear, but now I should set '-D__USE_W32_SOCKETS'.
BUT WHERE?
After researching google I try to set a enviroment variable CPPFLAGS=-D__USE_W32_SOCKETS, but this change nothing!
OK, now I want give MinGW a chance, but how get I rid of this penetrant Cygwin, without deinstalling and get mess with other software?
Cool, should I set some enviroment variables....
Clean up the build-Directory and set CC and CXX as mentioned in cmake output.
SET CC=D:/MinGW/bin/gcc.exe
SET CXX=D:/MinGW/bin/g++.exe
Checking my PATH variable and adding ";D:\MinGW\mysys\1.0\bin;D:\MinGW\bin"
Now use cmake bla.. again...but... but... WHAT?
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
CMake Error at CMakeLists.txt:4 (project):
The CMAKE_C_COMPILER:
D:/MinGW/bin/gcc.exe
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:4 (project):
The CMAKE_CXX_COMPILER:
D:/MinGW/bin/g++.exe
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/cygdrive/{my_path_to}/restbed/restbed/build/CMakeFiles/CMakeOutput.log".
With Cygwin cmake says, I use gcc/g++ in version GNU 5.4.0. On the other hand, it detects the correct MinGW version as 5.3.0, but can't find it? Hu?
What can I do to get this library work under Windows 7?
EDIT BEGIN
To build makefiles for Code::Blocks, the -G parameter doesn't work. I try some combinations, but always say:
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=NO -DBUILD_SHARED=YES -G "CodeBlocks" ..
CMake Error: Could not create named generator CodeBlocks
Generators
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
:
:
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=NO -DBUILD_SHARED=YES -G "CodeBlocks - Ninja" ..
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Now this (many censored words) thing want to know the cmake-make?
My fault.... don't think about, what I've installed.
"CodeBlocks - Unix Makefiles" works as expected for generating project file, but can't compile under Code::Blocks. I changed compiler for project in 'Build options' to Cygwin, but says:
Execution of '/usr/bin/make.exe -j8 -f "/cygdrive/d/{my_path_to}/restbed/restbed/build/Makefile" VERBOSE=1 all' in 'D:\{my_path_to}\restbed\restbed\build' failed.
...and nothing more. Think it has to do with "Unix Makefile" under Windows.
EDIT END
I'm out of knowledge what to do, what to set, to delete, to modify, configure, aaaargh.
My last hope is, that someone has the big hint, a good idea or a workaround.
Thanks in advance.
Restbed can build with Visual Studio 2015/2017, why not use the native toolchain for that platform?

Cmake Error During Installation of dlib on Windows?

I am trying to install dlib-19.2 in Window 7.But during the building process of dlib I get these errors.
Configuring cmake ...
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error in CMakeLists.txt:
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error in CMakeLists.txt:
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/dlib-19.2/tools/python/build/CMakeFiles/CMakeOutput.log".
See also "C:/dlib-19.2/tools/python/build/CMakeFiles/CMakeError.log".
error: cmake configuration failed!
Can anyone explain me the reason of the error and how to avoid it.Cmake GUI seems to work perfectly fine.
Had the same problem, installing Visual C++ 2015 Build Tools solved it for me:
http://landinghub.visualstudio.com/visual-cpp-build-tools

Clang on WIndows finds VC headers instead of GCC

When I had Clang 3.7 installed it would find the STL headers from my GCC installation as long as only both those two directories in the path.
Now that I have installed Clang 3.8 the compiler keeps finding the Visual Studio headers despite the fact that it isn't even in the path
My path is as follows:
PATH=whatever;G:\Compilers\LLVM\bin;g:\compilers\Mingw64-64bit\bin
Edit 1
I've know idea what the correct include paths, but I tried a compilation in Codelite which found these:
"-IG:\\Compilers\\Mingw64-64bit\\x86_64-w64-mingw32\\include\\c++"
"-IG:\\Compilers\\Mingw64-64bit\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32"
"-IG:\\Compilers\\Mingw64-64bit\\lib\\gcc\\x86_64-w64-mingw32\\5.1.0\\include"
"-IG:\\Compilers\\Mingw64-64bit\\lib\\gcc\\x86_64-w64-mingw32\\5.1.0\\include-fixed" "-IG:\\Compilers\\Mingw64-64bit\\x86_64-w64-mingw32\\include"
"-IG:\\Compilers\\Mingw64-64bit\\x86_64-w64-mingw32\\include\\c++\\backward"
I'm also using the dialect flag --std=c++11
However a very simple program using the C++ library is giving me errors such as
G:\Compilers\Mingw64-64bit\x86_64-w64-mingw32\include\c++\bits/stringfwd.h:63:33: error: use of undeclared identifier 'char16_t'
template<> struct char_traits<char16_t>;
^
Edit 2
Now passing x86_64-w64-mingw32 as recommended by Martin, the autodiscovery process seems to work, however the produced executable just freezes.
I found the same when I tried to use the VS2015 Clang toolset
The code example I am using is this
#include <iostream>
int main()
{
int arr[] = {1, 2, 3, 4, 5};
for(auto el : arr)
{
std::cout << el << std::endl;
}
return 0;
}
I am now compiling with:
clang++ -v --target=x86_64-w64-mingw32 hello.cpp -o test.exe -std=c++14
I have looked at the executable produced with Dependency Walker and it is showing as a 64 bit compile and linking to "g:\Compilers\Mingw64-32Bit\bin\libstdc++-6.dll"
I think the next step would be to try compiling a 32 bit version, but I cannot seem to find the correct target name for that
I have just tried clang++ hello.cpp -o main.exe -std=c++14 --target=i686-pc-mingw32 -v
That seems to be producing a 32 bit executable, but again it just freezes
Note I updated the path to point to the 32 bit clang.
Edit 3
What I find confusing is that until I passed x86_64-w64-mingw32 as the target I got very similar errors both from passing the GCC paths, and from the default target of MSVC where both seemed to be related to char16_t and similar types
Seeing this I thought I would try if passing a target might fix the VC compiler errors
Whilst that sort of seems to work it just creates more problems, because it keeps asking for libs to link to and I don't know the correct ones
So I tried:
clang++ hello.cpp -o main-vc.exe -std=c++14 --target=x86_64-pc-windows-msvc19.0.0 -v
-Xlinker "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64\libcmt.lib"
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64\libcpmt.lib"
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64\libvcruntime.lib"
"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x64\libucrt.lib"
I have no idea what were the correct directories to pass.
I have a feeling that I need to pass another lib file as I am getting this error
libcmt.lib(thread_safe_statics.obj) : error LNK2019: unresolved external symbol __imp_CloseHandle
Did you change the target? VC is the new default. Use this (example) for x64, mingw:
clang++ --target=x86_64-w64-mingw32 test.cpp
Don't forget the linker as wel.

Unable to specify the compiler with CMake

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

Resources