Moving C++ project, errors in atlplus.h - c++

I am trying to move an old C++ project to VS2010.
The last version of VS to compile it was VS2005, as far as I know. I already fixed a bunch of errors but now I am stuck,
since I am getting errors in atlplus.h, which is a VC10 header file.
Error 1 error C2065: 'CStringW' : undeclared identifier C:\Program
Files (x86)\Microsoft Visual Studio
10.0\VC\atlmfc\include\atlplus.h 692 1
Error 2 error C2146: syntax error : missing ';' before
identifier 'strW' C:\Program Files
(x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlplus.h 692 1
Error 3 error C3861: 'strW': identifier not found
C:\Program Files
(x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlplus.h 692 1
Error 4 error C2065: 'strW' : undeclared identifier C:\Program Files
(x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlplus.h 693 1
Does anyone have any idea? I've been stuck here since last week.

You need to include atlstr.h before any headers that use CString.
CString has been moved to the atlstr.h header file.

I met the similar problem. please try to include atlbase.h instead of atlstr.h.
You can see a comment line in file atlplus.h:
//Avoid using <atlstr.h> except in the registry templates (for circular dependencies).

Related

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

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.

Error in windows file mfreadwrite.h

I have a project where I have to use the functions of "mfreadwrite.h", but when I try to compile my project I get these errors:
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(260): error C2065: 'IMFMediaSource': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(260): error C2065: 'pMediaSource': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(261): error C2065: 'pAttributes': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(261): error C2275: 'IMFAttributes': illegal use of this type as an expression
5> c:\program files (x86)\windows kits\8.1\include\um\mfobjects.h(310): note: see declaration of 'IMFAttributes'
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(262): error C2065: 'ppSourceReader': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(262): error C2275: 'IMFSourceReader': illegal use of this type as an expression
5> C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(52): note: see declaration of 'IMFSourceReader'
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(262): warning C4229: anachronism used: modifiers on data are ignored
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(1000): error C2065: 'IMFMediaSink': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(1000): error C2065: 'pMediaSink': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(1001): error C2065: 'pAttributes': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(1001): error C2275: 'IMFAttributes': illegal use of this type as an expression
5> c:\program files (x86)\windows kits\8.1\include\um\mfobjects.h(310): note: see declaration of 'IMFAttributes'
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(1002): error C2065: 'ppSinkWriter': undeclared identifier
5>C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(1002): error C2275: 'IMFSinkWriter': illegal use of this type as an expression
5> C:\Program Files (x86)\Windows Kits\8.1\Include\um\mfreadwrite.h(73): note: see declaration of 'IMFSinkWriter'
can anyone help me please?
ps:
I tried cleaning and rebuilding my project a couple of times but I still get the errors.
I had a similar problem recently and the solution for me was including mfidl.h before every mfreadwrite.h include directives.
It can be tricky, because the compiler output might be misleading when the file causing the problem is included into another file.
The easiest way I found to track the problem back to the source was showing the included files in the compile output window. (Project / Properties / Configuration Properties / C/C++ / Advanced / Show Includes <- set it to Yes)
I started going back from the first error message and checked the custom headers and source files (the ones I wrote).
Environment: Windows 8.1/64b, Visual Studio 2015 Express for Windows Desktop.
I had a case where I was trying to get a project to compile in Visual Studio 2010 that used the IMFSinkWriter. It compiled fine with Visual Studio 2013, but for 2010 I had to place the following in the stdafx.h file:
#define WINVER 0x0601
#define _WIN32_WINNT 0X0601

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.

VS2012 mixing C and Cpp, library clash

I am trying to combine some C and C++ code in a project, and before I had no issues with this, but I'm now trying out VS2012 for the first time and I get a lot of errors from a TR1 header that I didn't include explicitely.
I'm thinking it might be a mixup because it's trying to compile my c code with this cpp header. It looks like a C compiler error trying to understand C++ template code. Where can I figure this out from the VS2012 interface? Do I need to do something to my c and cpp files to make the compiler treat them properly?
Error 1 error C2143: syntax error : missing '{' before '<' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtr1common 15 1 example~
Error 2 error C2059: syntax error : '<' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtr1common 15 1 example~
Error 3 error C2143: syntax error : missing '{' before '<' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtr1common 20 1 example~
Error 4 error C2059: syntax error : '<' C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtr1common 20 1 example~
Error 5 error C2016: C requires that a struct or union has at least one member C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtr1common 28 1 example~
Never mind. It has been a while since I've used VS and forgot that it doesn't necessarily treat cpp files as c++. I had to set the "compile as" option to c++.

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.