I'm running into some issues compiling one of our programs using boost 1_62_0 under VS2012. I've previously had this compiling under VS2015 I believe (however can't verify this).
I turned on /showIncludes to get an idea of where exactly its having the problem, and I've narrowed it down to inclusion of typeindex from the VS2012 includes:
Note: including file: C:\PROGRA~2\MICROS~3.0\VC\include\crtdefs.h^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/limits.hpp^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/limits.hpp^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/type_traits/is_enum.hpp^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/type_traits/is_integral.hpp^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/utility/enable_if.hpp^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/cstdint.hpp^M
Note: including file: C:\PROGRA~2\MICROS~3.0\VC\include\typeindex^M
\\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/functional/hash/hash.hpp(236) : error C2039: 'UINT64' : is not a member of 'boost'^M
\\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/functional/hash/hash.hpp(237) : error C2039: 'UINT64' : is not a member of 'boost'^M
Note: including file: \\COMPILESERVER\BASENT\dev\lib\src\third_party\boost\boost_latest_win64_vs2012\boost/functional/hash/extensions.hpp^M
Using #pragma message, I can verify that it has using ::uint64_t within the boost namespace in cstdint.hpp
Any ideas on how to fix this?
Indeed this smells like a MACRO.
You should find out which header defines something like
#define uint64_t UINT64
You can save the preprocessor output of the failing translation unit to find this.
Related
I had a piece of code that was including some Boost headers. Upon compilation I received errors like
/usr/local/include/boost/smart_ptr/shared_ptr.hpp:1041:9: error: use of undeclared identifier 'assert'
BOOST_ASSERT( deleter_.use_count() <= 1 );
^
/usr/local/include/boost/assert.hpp:60:29: note: expanded from macro 'BOOST_ASSERT'
# define BOOST_ASSERT(expr) assert(expr)
^
These errors however only occurred on Windows and macOS.
Explicitly including either <cassert> or <assert.h> before the Boost headers had no effect.
You need to #include <cassert> to bring in the assert implementation.
It's your job to define or not define NDEBUG accordingly.
I'm surprised Boost doesn't do that for you - are you using the Boost files correctly (i.e. including the files that you're supposed to)?
As it turned out I had a file called Assert.h in my include-path (a custom file of mine). On case-insensitive file systems as used by Windows and macOS, this would shadow the original assert.h header that actually defines the assert macro.
The solution therefore was simply to rename my assert-header file.
(I found the solution thanks to [Compilation Error] error: use of undeclared identifier 'assert' #15.)
While looking for best pratices regarding include order, I was stumbling over this thread:
C/C++ include file order/best practices [closed]
#squelart was stating, that it is better pratice to include from local to global, as this reduces the chance of hidden dependencies. I just tested this in a VS2015 project with the following code:
StrTest.h
#pragma once
class CStrTest
{
public:
CStrTest();
~CStrTest();
std::string test;
};
StrTest.cpp
#include <string>
#include "StrTest.h"
CStrTest::CStrTest()
{
}
CStrTest::~CStrTest()
{
}
I couldn't reproduce the stated behaviour (hidden dependencie duo including string first in StrTest.cpp). The compiler gives me mulitple errors. So is this something out of the past or did I overlook something?
EDIT: VS2015 Compiler errors:
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2039 'string': is not a member of 'std'
Error C3646 'test': unknown override specifier
So is this something out of the past
No, the hidden dependencies are the standard behaviour and do happen in modern compilers. I don't know of VS, but GCC and Clang do compile your shown program without any errors. Demo: https://wandbox.org/permlink/ATJndwrOwirpDgDd
The compiler gives me mulitple errors.
Although an "implicit" include is poor style, it is still technically well formed as far as the standard is concerned as long as the implicitly included file is guaranteed to be included by you or whoever wrote the header that includes it - standard headers have no such guarantees.
Therefore I would be against such compiler feature that considers implicit includes as errors. An explicitly enable-able warning would be much more suitable.
I think the point of hidden dependence problem discussed there is that typically each file includes several other files and if header is not self-contained then including it may work in cases when it's implicit dependences are included by some other header and break everything when those other headers change and / or get moved / removed. In short: use of headers with hidden dependencies lead to extremely fragile code.
// foo.hpp
#pragma once
#include <string> // if we remove this unrelated `StrTest.h` header will be broken
...
.
// main.cpp
#include "foo.hpp" // if we move this one line lower `StrTest.h` header will be broken
#include "StrTest.h" // accidentally works fine
...
I'm upgrading the libraries to MSVC 141 and moving to Visual Studio 2017.
I've downloaded the newest Boost libraries (boost_1_64_0_b2-msvc-14.1-64.exe). When building the code, I get this error:
...\boost\move\detail\type_traits.hpp(757): error C2187: syntax error:
')' was unexpected here ...\boost\move\detail\type_traits.hpp(763):
note: see reference to class template instantiation
'boost::move_detail::is_copy_constructible' being compiled
In the mentioned header, BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE is defined but the latest MSVC doesn't understand the enclosed code.
Undefining this macro helps, but it there a better solution to fix this? What's the reason here?
As suggested here, undefine macro U after each inclusion of cpprest headers or before inclusion of boost headers.
Example:
#include <cpprest/http_client.h>
#undef U
need include -
#define _TURN_OFF_PLATFORM_STRING
"#include <cpprest/details/basic_types.h>"
....
see:
https://github.com/Microsoft/vcpkg/issues/836
I am trying to integrate wwise into a test project. I have a project on windows 7 using ms visual studio 2010 and this is the error I get after I try and add a necassary cpp to the project. i dont get this build error on my machine at home with the same set up, what does it mean?
------ Build started: Project: wwise test, Configuration: Debug Win32 ------
AkFilePackageLUT.cpp
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.h(204): error C2065: 'NULL' : undeclared identifier
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.cpp(117) : see reference to function template instantiation 'const CAkFilePackageLUT::AkFileEntry<T_FILEID> *CAkFilePackageLUT::LookupFile<AkFileID>(T_FILEID,const CAkFilePackageLUT::FileLUT<T_FILEID> *,bool)' being compiled
with
[
T_FILEID=AkFileID
]
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.h(204): error C2065: 'NULL' : undeclared identifier
c:\program files (x86)\audiokinetic\wwise v2012.2.1 build 4427\sdk\samples\soundengine\common\akfilepackagelut.cpp(140) : see reference to function template instantiation 'const CAkFilePackageLUT::AkFileEntry<T_FILEID> *CAkFilePackageLUT::LookupFile<AkUInt64>(T_FILEID,const CAkFilePackageLUT::FileLUT<T_FILEID> *,bool)' being compiled
with
[
T_FILEID=AkUInt64
]
To me it looks on the first glance like you did not specify a template parameter .
Other possible causes:
You are compiling with a debug version of the C runtime, declaring a
Standard C++ Library iterator variable in a for loop, and then
trying to use that iterator variable outside the scope of the for
loop. Compiling Standard C++ Library code with a debug version of
the C runtime implies /Zc:forScope. See Debug Iterator Support for
more information.
You may be calling a function in an SDK header file that is
currently not supported in your build environment.
Omitting necessary include files, especially if you define
VC_EXTRALEAN, WIN32_LEAN_AND_MEAN, or WIN32_EXTRA_LEAN. These
symbols exclude some header files from windows.h and afxv_w32.h to
speed compiles. (Look in windows.h and afxv_w32.h for an up-to-date
description of what's excluded.)
Identifier name is misspelled.
Identifier uses the wrong uppercase and lowercase letters.
Missing closing quote after a string constant.
Improper namespace scope. To resolve ANSI C++ Standard Library
functions and operators, for example, you must specify the std
namespace with the using directive. The following example fails to
compile because the using directive is commented out and cout is
defined in the std namespace
This error message is saying the following:
in <path...>\akfilepackagelut.h there is a definition of a function template. In fact, it is a templated method of a class. Inside that definition, on line 204, the name NULL is used. NULL is defined in header <cstddef> of the C standard library, and normally you can include that definition by including one of a lot of C/C++ headers, because most of them somehow include <cstddef>. However, akfilepackagelut.h seems to include only headers that in the VS2012 installation you are using do not include that definition, so the compiler does not know what NULL means.
The whole rest of the error message is just template error gibberish, telling you that that function template we are talking about has been instantiated twice somewhere in AkFilePackageLUT.cpp, telling you the exact locations and the template parameters and so on.
What can you do?
Well, if you can not modify the source as you say (Why? You have the source) you can't do anything but perhaps file a bug for the project. If you can modify it would be best to #include <cstddef> in akfilepackagelut.h.
I'm trying to use iphlpapi (GetAdapterInfo) and am having trouble compiling the code. I have iphlpapi.h from SDK 7 and have added the appropriate path to the include files in visual studio.
I get the following error...
c:\program files\microsoft sdks\windows\v7.0\include\ifdef.h(154) : error C2146: syntax error : missing ';' before identifier 'NET_IFTYPE'
The lines in ifdef where this occurs are shown below.
typedef NET_LUID IF_LUID, *PIF_LUID;
typedef ULONG NET_IFINDEX, *PNET_IFINDEX; // Interface Index (ifIndex)
typedef UINT16 NET_IFTYPE, *PNET_IFTYPE; // Interface Type (IANA ifType)
I finally figured out how to get this to work so I'm putting this here for others who might stumble upon it.
First, I'm using visual c++ version 6.0 with the 2003 sdk. I added the sdk as the first choice using TOOLS->OPTIONS->DIRECTORIES. Adding the include winsock2.h caused about 60 redefinition errors. I found several sources telling me that the winsock2 include had to precede the windows.h include. My windows.h include was generated for me by VC++ in the precompiled header stdafx.h so I moved the winsock2.h include there. I now can compile and run my program!
According to this page, it looks as though you might need to make sure winsock2.h is included first. I'm guessing that it defines some of those types.
Also, the MSDN page for NET_LUID says it requires Vista at a minimum. Make sure that's true.