syntax error in VC xtree internal header with Qt/boost project - c++

I'm using Boost with a Qt project.
I added these lines to my .pro file.
INCLUDEPATH += C:/local/boost_1_62_0/
LIBS += "-LC:/local/boost_1_62_0/lib64-msvc-12.0/"
I'm linking against boost, as I use a the libICP library, that includes boost/multi_array and boost/array.
When I compile, I get a lot of errors :
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:20: error: C2143: syntax error : missing ',' before '<'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:21: error: C2518: keyword 'typename' illegal in base class list; ignored
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:22: error: C2518: keyword 'typename' illegal in base class list; ignored
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree:132: error: C2065: '_Iterator_base0' : undeclared identifier
I suspect xtree is used by the implementation of multi_array or array, but I don't really know where to go from here.

Ok, so I found the solution (I was working on this issue since yesterday...)
In case someone else has a similar issue, it was just a case of unbalanced } at the end of the file ICP_Registration.h, that includes libICP.

Related

CMake uses C-style precompiled headers instead of C++ version of the precompiled header

My project directory is as follows:
<PROJECT-ROOT>:
- build
- MyProject:
- src:
- main.cpp
- hello.h (basic file that contains a simple function that prints something using iostream)
- pch.h (precompiled header)
- CMakeLists.txt
And CMakeLists.txt file is as follows:
cmake_minimum_required(VERSION 3.16)
project(MyProject)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++11")
endif()
include_directories(
MyProject
MyProject/src
)
add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/MyProject/pch.h
${CMAKE_SOURCE_DIR}/MyProject/src/main.cpp
${CMAKE_SOURCE_DIR}/MyProject/src/hello.h)
target_precompile_headers(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/MyProject/pch.h)
As expected, CMake generates the following precompiled header files in build/CMakeFiles/MyProject.dir/ :
cmake_pch.c
cmake_pch.cxx
cmake_pch.cxx.obj
cmake_pch_cxx.pch
cmake_pch.h
cmake_pch.hxx
I am using this CMake project in Visual Studio 2019, and when I try to run main.cpp, Visual Studio gives me a bunch of errors, such as:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(23): error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(23): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(23): error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(25): error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(31): error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(31): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(31): error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\cstdlib(33): error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xtr1common(19): error C2061: syntax error: identifier 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xtr1common(19): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xtr1common(19): error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xtr1common(235): error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\iosfwd(175): warning C4157: pragma was ignored by C compiler
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\iosfwd(180): warning C4157: pragma was ignored by C compiler
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(307): error C4233: nonstandard extension used: '__is_union' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(310): error C4233: nonstandard extension used: '__is_union' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(313): error C4233: nonstandard extension used: '__is_class' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(316): error C4233: nonstandard extension used: '__is_class' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(325): error C4233: nonstandard extension used: '__is_convertible_to' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(330): error C4233: nonstandard extension used: '__is_convertible_to' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(359): error C4233: nonstandard extension used: '__is_enum' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(362): error C4233: nonstandard extension used: '__is_enum' keyword only supported in C++, not C
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits(499): error C4233: nonstandard extension used: '__is_pod' keyword only supported in C++, not C
When I searched error code C4233 online, I learned that it is because a C code is trying to be compiled as a C++ code. Also, build process from Visual Studio (I guess uses ninja) shows that:
[1/33] Building C object CMakeFiles\MyProject.dir\cmake_pch.c.obj
Hence, I guess it tries to build my precompiled header as a c source, instead it is a C++ source. I also tried to change the pch extension to .hpp but it didn't work either. How can I specify CMake to mark precompiled header as C++ (or I guess CXX) source instead of pure C?
EDIT: When I disable the target_precompile_headers the program runs fine, hence I am certain that this is a precompiled header issue.
Thanks to #drescherjm, adding target_precompile_headers(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/MyProject/pch.h>" got rid of the errors.

Multiple errors when including Windows Media SDK libs

I am trying to compile a Qt project with msvc2010 which uses the Windows Media SDK
When I try to include the wmsbuffer.h or wmsdkidl.h files, I get errors like these:
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : error C2146: syntax error : missing ';' before identifier 'INSSBuffer'
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : error C2146: syntax error : missing ';' before identifier 'INSSBuffer'
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : error C2086: 'int INSSBuffer' : redefinition
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\wmsbuffer.h(48) : see declaration of 'INSSBuffer'
I assumed that the problem was that I didn't have the right include or library paths in my .pro file, but even adding this doesn't help:
win32 {
INCLUDEPATH += "C:/Program Files/Microsoft SDKs/Windows/v7.1/Include"
DEPENDPATH += "C:/Program Files/Microsoft SDKs/Windows/v7.1/Include"
LIBS += -L"C:/Program Files/Microsoft SDKs/Windows/v7.1/lib" -lMscvrtd
LIBS += -L"C:/Program Files/Microsoft SDKs/Windows/v7.1/lib" -lWmvcore
}
The errors also look like something I'd get with circular inclusion, but I haven't found anything else to indicate that this might be the problem here.
Have I forgotten something really obvious?
Well, it turns out that the lines causing errors in wmsdkidl.h and wmsbuffer.h all look like this:
typedef interface IWMMediaProps IWMMediaProps;
But the header which defines interface (<objbase.h>) doesn't seem to be included in wmsbuffer.h etc.
Including objbase.h in my own header didn't help, so I've solved my problem with this duct-tape solution:
#define interface struct
#include <wmsdk.h>
Which gets rid of the errors, but generates a lot of warnings due to redefining this keyword...
I'm not entirely sure what is going on or why a library that uses interface doesn't include its definition, though, so if someone can offer a better explanation and/or solution, please feel free to!

Libs ,DLLs and .h files

Im a C# guy thats why I'm lost here, this project claims to have compiled that library for Windows https://soildgeo.codeplex.com/releases/view/108738
the folder comes with Include,Lib64 and Bin64 folders. If I'm not mistaken, I only need to copy .lib files to the VC/lib folder and the folders in include to VC/include folder, so that I can start coding against these APIs, they appear in the #include<> intellisense but then they don't compile. my questions are, are my assumptions on this whole process is right ? if not what are the right steps ? and lastly, do I need to use the Dlls found in Bin64 folder at any point ?
Im using VS2013
Thanks in advance
Edit
1>------ Build started: Project: PhysBAMTest, Configuration: Debug x64 ------
1> main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2146: syntax error : missing ';' before identifier 'attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cout' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2143: syntax error : missing ';' before '='
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2146: syntax error : missing ';' before identifier '__attribute__'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cerr' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2374: 'PhysBAM::LOG::anonymous-namespace'::__attribute__' : redefinition; multiple initialization
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163) : see declaration of 'PhysBAM::LOG::anonymous-namespace'::attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2143: syntax error : missing ';' before '='
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Edit
after adding the WIN32 macro based on an answer below , I got a linker error this time
Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl PhysBAM::LOG::cout_Helper(void)" (?cout_Helper#LOG#PhysBAM##YAAEAV?$basic_ostream#DU?$char_traits#D#std###std##XZ) referenced in function "void __cdecl PhysBAM::LOG::anonymous namespace'::dynamic initializer for 'cout''(void)" (??__Ecout#?A0x5bbeb782#LOG#PhysBAM##YAXXZ) C:\Users...\Documents\Visual Studio 2013\Projects\PhysBAMTest\PhysBAMTest\main.obj PhysBAMTest
All those attribute, unused, __attribute__ are what some call GNU-ishms, that is, features specific to the GCC compatible compilers (GCC itself, Clang, ICC and others). But MS VC does not aim for GCC compatibility, so they just don't work.
The people that did the port to Windows managed to remove these construct by using a few precompiler tricks, I think in the file Utilities/PHYSBAM_OVERRIDE.h. But for those to work you have to define the macro WIN32. Do that in the project "C/C++ Preprocessor Settings" page, not in the code, so it will be defined for all the source files at once.
Alternatively, and this IMO would be the correct solution, patch the sources, and replace every occurrence of #ifdef WIN32 or #if defined(WIN32) with #ifdef _WIN32. The macro _WIN32 is always predefined in Win32 and Win64, but the WIN32 is not.
Well, technically you'd have to differentiate each occurence if the issue is about being a Windows system or about being a MSVC compiler (there is a GCC compiler for Windows). And then use _WIN32 for the system dependencies and _MSC_VER for the compiler ones.
And then, if you feel like it, send a patch to the Codeplex project.
UPDATE
About the linker error, that should be easy to fix: just add the necessary "*.lib" file or files to the project. You can add them to the Linker Property Pageof the project.
Additionally what you did with .lib and .h, you need to keep .dll in either in, System32 dir, or in same dir where you have exe.
Answers to this question may help you understand better.

Why do I get errors when I #include curl.h?

I'm trying to get libcurl to work with my C++ project.
I've added libcurl to my project.
I've also added the header files, preprocessor and linker configuration.
When adding #include to my project I get a lot of winnt.h errors:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : '('
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2090: function returns array
...
What is the reason to this problem?
Thanks.

Dependencies, Namespace, and Headers

I believe have dug myself into a hole. While breaking up my single file, couple thousand line chunk of code into multiple files I appear to have grossly screwed up the structure of the program.
I'm new to C++ and its header files and namespace management so I've been learning as I go.
I guess I don't fully understand how #include, using, and namespaces interrelate and what transfers over to other files, etc.
Reading through MSDN documentation I can see bits and pieces of my problem but the solution eludes me.
As of now I have four .cpp files and headers:
1) A Main File
2) A GameData .cpp and its header that is contained in the namespace pData
3) A GameSettings .cpp and its header that is contained in the namespace pSettings
4) A GeneralScreens .cpp and its header that is contained in the namespace pScreens
Upon compile the debugger spews over 100 of error like:
>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(454): error C2447: '{' : missing function header (old-style formal list?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(463): error C2039: 'pair' : is not a member of 'std'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(463): error C2955: 'pScreens::std::pair' : use of class template requires template argument list
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(173) : see declaration of 'pScreens::std::pair'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(33): error C2873: 'wcsrtombs' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(41): error C2039: 'wctob' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(41): error C2873: 'wctob' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemchr' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemchr' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemcmp' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemcmp' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2039: 'wmemcpy' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(42): error C2873: 'wmemcpy' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cwchar(43): error C2039: 'wmemmove' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C2039: 'nothrow_t' : is not a member of 'std'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(93): error C2143: syntax error : missing ',' before '&'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(99): error C2039: 'new_handler' : is not a member of 'std'
Are these errors indicative of something?
I'm assuming something is wrong with the way I'm referencing the std library though I have no idea how to pinpoint the error because all the errors are in library files.
Most likely you're missing a semicolon on the end if a class or struct definition in a header file. The compiler then treats every identifier it sees as an instance of that class instead of what you're expecting. Then the compiler complains because it has no idea what to do with the stray {}s it sees.
Check the header that's #included just before <utility> in your implementation file; that header is most likely where the fault lies.
Side note: To avoid this problem, always #include standard headers before your own headers in a .CPP file. For example, instead of
// MyGameThing.cpp
#include "MyGameThing.hpp"
#include <utility>
#include <string>
// code
do
// MyGameThing.cpp
#include <utility>
#include <string>
#include "MyGameThing.hpp"
// code
That way you won't get compile errors like this buried in the standard headers.
The first compiler error is going to be your best clue:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(454): error C2447: '{' : missing function header (old-style formal list?)
I'm guessing that what's happening here is you may have a class or struct declaration with no ending semicolon. So you have something like this:
struct Foo
{
} // <--- no semicolon here will generate funky errors
But overall, pay close & special attention to the first compiler error.
As #Billy mentions in the comments below, the rules for struct and class are the same. In either case, you need the semicolon. Also, old-school C code will often typedef structs like this:
typedef struct tag_Foo
{
} Foo; // <-- still need the semicolon
Here, you still need the semicolon.
If using Visual C++, open the first cpp file and press CTRL+F7, this will compile only the cpp file, check the first error and try to correct this. When fixed go to the next cpp file if the error persists.
Billy's attempt is a decent one, but the usual response to a missing ';' is for the compiler to say so. A missing '}' on the other hand can seriously confuse standard headers included afterward because all their content is within the scope of either the namespace or class that should have been closed. Also, ';' missing is more immediately detectable while a missing '}' isn't necessarily an error so the compiler just pisses a fit at the first thing that doesn't make sense in that scope.
Furthermore, at line 454 in utility for the 2010 compiler is the opening brace for a specialization of tuple_size for std::pair. Post preprocessor that definition would look like so:
template < ... >
struct tuple_size< ::std::pair<_Ty1, _Ty2> >
If you have forgotten a '}' closing a namespace then that's not where pair<> exists anymore. Instead, since it's declared like so:
namespace std { template < ... > struct pair ... }
Whatever scope wasn't closed is now where std is being declared and struct tuple_size< ::std::pair<...> > doesn't make any sense to the parser. Since it's not a valid name it tends to pretend it's not even there and then '{' at the global scope without anything of sense before it is pretty f'n confusing.
BTW, an often unspoken benefit of making minimal examples that cause the problem is that you end up FINDING the problem trying to make it happen.