My project needs to use both Micorsoft Visual C++ math.h and Intel MKL math.h.
Building with verbose details, I get:
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\cmath
1> Note: including file: E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdefs.h
1> E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h(1577): warning C4005: 'HUGE_VALF' : macro redefinition
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h(104) : see previous definition of 'HUGE_VALF'
1> E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h(1579): warning C4005: 'HUGE_VALL' : macro redefinition
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h(105) : see previous definition of 'HUGE_VALL'
1> E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h(1581): warning C4005: 'HUGE_VAL' : macro redefinition
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h(96) : see previous definition of 'HUGE_VAL'
The "'HUGE_VALF' : macro redefinition" message is the one that made me be suspicious.
At first I just disabled that warning, but considering that this option would only mask a potential problem, I am looking for an alternative solution.
From lines 1 and 2, you can see that Visual Studio's cmath does not include Visual Studio's math.h, as it should, but MKL's file with the same name.
How can I set my CMakeLists.txt file so that the compiler can pick the right include files?
Just wrap one library.
For example, create header file:
#pragma once
namespace imath {
double sin(double a);
}
And in cpp
#include "Wrapper.h"
#include <intel/math.h>
namespace imath {
double sin(double a) {
return ::sin(a);
}
}
Do this for every symbol you need to use in common source.
And do not include C version of math.h you are using C++ so #include <cmath>.
Related
Every time I build my project my Build output window is filled (one instance for every cpp file) with
1>d:\program files\microsoft sdks\windows\v7.1\include\sal_supp.h(57): warning C4005: '__useHeader' : macro redefinition
1> d:\program files\microsoft visual studio 12.0\vc\include\sal.h(2886) : see previous definition of '__useHeader'
1>d:\program files\microsoft sdks\windows\v7.1\include\specstrings_supp.h(77): warning C4005: '__on_failure' : macro redefinition
1> d:\program files\microsoft visual studio 12.0\vc\include\sal.h(2896) : see previous definition of '__on_failure'
It's not really a problem except that it makes it hard to parse the actual build errors when I break something. How can I fix the root of this error? Or at least silence it?
From a comment under the original question:
VS2012 C++ warning C4005: '__useHeader': macro redefinition
Long story short, its a bug in VS, with no real workarounds.
I have chosen to just silence the specific warning code, which does silence all instances of macro re-definitions. But now I can actually read my build output so whatever I guess.
http://msdn.microsoft.com/en-us/library/jj715718.aspx
According to http://clang.llvm.org/get_started.html
I did the ALL_BUILD on Windows with Visual Studio 2010 and added the built stuff to my system path with $PATH=...ClangSourcBuildPath...\build\bin\Release
I now can compile the following file on the console with:
$> clang file_c.c
//file_c.c
#include <stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
But if I do the same for the following file ($> clang file_cpp.cpp):
//file_cpp.cpp
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}
I get the following errors:
In file included from file_cpp.cpp:1:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\iostream:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\istream:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\ostream:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\ios:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\streambuf:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xlocnum:13:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xiosbase:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xlocale:11:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\stdexcept:10:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xstring:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xmemory:15:
C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:81:10:
error: missing 'typename' prior to dependent type name '_It::iterator_category' typedef _It::iterator_category iterator_category;
C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:82:10:
error: missing 'typename' prior to dependent type name '_It::value_type' typedef _It::value_type value_type;
C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:83:10:
error: missing 'typename' prior to dependent type name '_It::distance_type' typedef _It::distance_type distance_type;
C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:224:32:
error: template parameter redefines default argument
template < class _E, class _Tr = char_traits< _E > >
...
I also tried:
$> clang++ file_cpp.cpp
$> clang -x c++ file_cpp.cpp
But I still get the same errors.
Can someone explain me what's wrong?
There are certain flags (I think it was -fms-extensions, not quite sure of the exact option) that are required to get clang to parse the VC++ headers.
The next problem you'll encounter is that the resulting executable cannot be linked. This is due to the fact that clang uses a different name mangling than MSVC, and will result in undefined references.
If you want to use Clang on Windows (which is currently possible with MinGW-w64), you can use my prebuilt packages, you'll need
Clang 3.2
GCC 4.6
Extracted to the same directory. GCC is in this case only used to call the linker. Clang can be used to compile everything.
There is currently no way to use clang for C++ with the Visual Studio headers+libs. C should work, but I haven't tested and there may be other ABI problems preventing this from working.
While playing around with the C++11 features of Visual Studio 2012, I encountered strange errors when including the "ppltasks.h" header file (which is included via the "future" header file:
Main.cpp
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\ppltasks.h(3306): error C2512: 'Concurrency::details::_PPLTaskHandle<Concurrency::details::_NormalizeVoidToUnitType<void>::_Type,Concurrency::task<std::pair<Concurrency::details::_Unit_type,Concurrency::details::_CancellationTokenState *>>::_ContinuationTaskHandle<_InternalReturnType,_TaskType,_Function,Concurrency::details::_FunctionTypeTraits<_Function,_ReturnType>::_Takes_task,Concurrency::details::_TaskTypeTraits<void,false>::_AsyncKind>,Concurrency::details::_ContinuationTaskHandleBase>' : no appropriate default constructor available
1> with
1> [
1> _InternalReturnType=std::pair<Concurrency::details::_Unit_type,Concurrency::details::_CancellationTokenState *>
1> , _Function=Concurrency::||::<lambda_06496b162c644bf2f90c850c3dfa7d5c>
1> , _ReturnType=std::pair<Concurrency::details::_Unit_type,Concurrency::details::_CancellationTokenState *>
1> ]
The error is longer, but you get the gist of it. Has anybody else encountered such an error message from simply including the "future" header, and is there a known solution? Thanks.
Turns out that the Project Settings must have language extensions enabled for the header to compile correctly (as of now).
I am new to windows development world. I am having Visual Studio 2010 and windows SDK 7.0a installed on my machine. Any win32 application (even the skeleton generated using the wizard) is giving me this compilation error repeated hundreds of times:
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\swprintf.inl
2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Windows.h
2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sdkddkver.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdarg.h
2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\windef.h
2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h
2> Note: including file: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\specstrings.h
*2> Note: including file: c:\program files\microsoft sdks\windows\v7.0a\include\sal_supp.h*
*2> Note: including file: c:\program files\microsoft sdks\windows\v7.0a\include\specstrings_supp.h*
*2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\specstrings_strict.h*
*2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\specstrings_undef.h*
2> Note: including file: C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h
*2> Note: including file: c:\program files\microsoft sdks\windows\v7.0a\include\sdv_driverspecs.h*
2>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h(356): error C3861: 'SAL_functionClass': identifier not found
2>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h(356): error C2059: syntax error : ')'
2>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h(374): error C2144: syntax error : 'char' should be preceded by ')'
2>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h(374): error C3861: 'SAL_acquire': identifier not found
Please advise. Thanks.
Take a look at your VS include paths. If you installed more SDKS (ie, Windows 7.1 or others) then the order may have gotten screwed up. Or perhaps you modified the paths to add some of your own.
Go to Project->Properties->Configuration Properties->VC++ Directories->Include Directories. Mine looks like this:
Include Directories =$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;
I'd suggest making them look like the default and seeing if you still have the problem. You may have to fix your Library Directories if it doesn't link after it compiles. Mine looks like this:
Library Directories =$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib
I am having some trouble converting an old project from VS6 to VS2005. At one place in the code it uses the type variant_t so it includes comdef.h for this purpose. comdef.h then includes comutil.h which generates these errors for me:
c:\program files\microsoft visual studio 8\vc\include\comutil.h(978) : error C2535: '_variant_t::_variant_t(int) throw()' : member function already defined or declared
c:\program files\microsoft visual studio 8\vc\include\comutil.h(970) : see declaration of '_variant_t::_variant_t'
c:\program files\microsoft visual studio 8\vc\include\comutil.h(1007) : error C2535: '_variant_t::operator int(void) const' : member function already defined or declared
c:\program files\microsoft visual studio 8\vc\include\comutil.h(998) : see declaration of '_variant_t::operator int'
c:\program files\microsoft visual studio 8\vc\include\comutil.h(1037) : error C2535: '_variant_t &_variant_t::operator =(int)' : member function already defined or declared
c:\program files\microsoft visual studio 8\vc\include\comutil.h(1029) : see declaration of '_variant_t::operator ='
c:\program files\microsoft visual studio 8\vc\include\comutil.h(1331) : error C2084: function '_variant_t::_variant_t(int) throw()' already has a body
c:\program files\microsoft visual studio 8\vc\include\comutil.h(970) : see previous definition of '{ctor}'
c:\program files\microsoft visual studio 8\vc\include\comutil.h(1588) : error C2084: function '_variant_t::operator int(void) const' already has a body
c:\program files\microsoft visual studio 8\vc\include\comutil.h(998) : see previous definition of '.H'
c:\program files\microsoft visual studio 8\vc\include\comutil.h(2006) : error C2084: function '_variant_t &_variant_t::operator =(int)' already has a body
c:\program files\microsoft visual studio 8\vc\include\comutil.h(1029) : see previous definition of '='
There is probably some configuration that is incorrect, some define missing or some include file I should have included but I can't seem to find the problem. Any pointers in the right direction is much appreciated
This looks like one of two things, an include order problem or as you stated something not getting defined but I am leaning towards the first one. You might want to check msdn and make sure there are no restrictions on when comutil.h can be included (I know this is an issue if you include winsock2.h before windows.h). There is also an option under C/C++ > Advanced to Show Includes (/showIncludes option from the command-line) which is generally helpful when trying to track issues like this down.
Does your own code do something like this:
#define long int