Libs ,DLLs and .h files - c++

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.

Related

Adding AdditionalIncludeDirectories makes project unable to import from standard library

I have a project in Visual Studio that is set up with the following architecture:
src
main.cpp
math.cpp
include
math.h
math.h contains function prototypes for the functions found in math.cpp. When using #include "math.h" after adding include\ to the project's C/C++ Additional Include Directories, I find the compiler is not able to find the standard library. I get several errors like this:
...
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(261,18): error C2039: 'sinhf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(261,23): error C3861: 'sinhf': identifier not found
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(265,18): error C2039: 'sqrtf': is not a member of '`global namespace''
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cmath(265,23): fatal error C1003: error count exceeds 100; stopping compilation
Of course, I can successfully include include\ by using #include "..\include\math.h" but I know there must be a way to tell Visual Studio to look in \include for files to include. Any ideas on what I am doing incorrectly?

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++.

Moving C++ project, errors in atlplus.h

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).

syntax error : missing ';' before identifier 'PVOID64' when compiling winnt.h

I've recently got the source-code on a application. When im trying to build the solution, I get an error in all parts where winnt.h is included. The error codes differs a bit, but they always point to these lines in winnt.h:
typedef void *PVOID;
typedef void * POINTER_64 PVOID64;
and
struct {
DWORD crc;
BYTE rgbReserved[14];
} CRC;
So, what could be the cause of this? winnt.h is a standard header and has not been modified. Does it has something to do with me using VS 2010, or me using 64-bit windows? or is it some sort of configuration which is needed?
EDIT:
Here's the exact error-codes:
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2238: unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2238: unexpected token(s) preceding ';'
You need to include windows.h rather than winnt.h. When you include windows.h it will, in turn, include winnt.h. You need to do it this way for the necessary macros to be in place that are needed to compile winnt.h.
In this case, POINTER_64 is defined in BaseTsd.h like this:
#define POINTER_64 __ptr64
But if you include winnt.h before including windows.h then POINTER_64 is not defined.
If you are using DirectX SDK, try changing the VC++ Directories for include and lib to be searched last.
It looks like your configuration of the Windows SDK is invalid.
This error is caused by the fact that the compiler is unable to recognize the 'POINTER_64' statement.
You may workaround this problem by replacing 'POINTER_64' with '__ptr64'.
I had the same issue recently. Then I've reinstalled the latest version of the Windows SDK and this fixed the problem.
UPDATE
#David Heffernan, correctly points to the fact that one should include windows.h instead of winnt.h
Try to remove DirectX SDK if you have one.
Here bug is accepted:
http://connect.microsoft.com/VisualStudio/feedback/details/508204/vc10-0-errors-while-compiling-winnt-h
Corrected manually syntax in winnt.h :
typedef void * POINTER_64 PVOID64; => typedef void * POINTER_64, * PVOID64;
If you are using librdkafka, you will get this error whenever "Windows.h" included.
I fixed it by rename "librdkafka/include/basetsd.h" to a different name, or access
this library header via sub path!
I think the author of this library made this file to deal with OS platform compatibility. But with the same file name "basetsd.h" as Windows Core, it just confusing Visual Studio.

Error building legacy code with VS 2005

Trying to build a legacy code in VS2005 and get errors in VC header files.
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2065: '_Sb' : undeclared identifier
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C3861: '_Strbuf': identifier not found
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2061: syntax error : identifier '_Sb'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2097) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2143: syntax error : missing ';' before '{'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : fatal error C1075: end of file found before the left brace '{' at 'd:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(15)' was matched
I find the legacy code uses a vector and if I comment out those variables then the code compiles without any errors.
I get these errors even if I just include vector header without defining any variable.
All the files in the project are cpp files.
Do I need to add some preprocessor directives or compiler settings to get this working?
You may find that running the pre-process phase on one of the files might show if any macros are being expanded that conflict with vector or _Strbuf. See my post on how to do this:
Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile
You probably need to remove some conflicting predefined macros. Leading underscores followed by uppercase letters, as in _Sb are reserved for the implementation. If you have that defined as something else, you'll get such errors. It's also possible the errors are because you've defined _Strbuf ot _Got.