Boost C++ libraries generating strange errors - c++

I recently tried to write a c++ program, where I used the build in socket tools you can find in the Boost library. First of all, I tried to make a client/server based program, where the server just sends a message and the client receives it. It worked just fine.
Then I wrote another program, where I used a Xbox 360 kinect, to control my movement. The idea of creating the first program, was the get the code for the socket creating, so I can connect with, i.e. my Samsung tv, to control the tv, using my kinect.
The problem arises, when I copy my code from the first program, into my second program with the kinect. All of sudden, the program gives 100+ error, when compiling the boost library.
I triple checked the including libraries and all, but the problem still arises. Some of the errors are posted below:
1>C:\boost_1_55_0b1\boost/asio/detail/socket_types.hpp(96): error C2143: syntax error : missing ';' before '.'
1>C:\boost_1_55_0b1\boost/asio/detail/socket_types.hpp(96): error C2238: unexpected token(s) preceding ';'
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2224): error C2653: 'Windows' : is not a class or namespace name
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2224): error C2871: 'Collections' : a namespace with this name does not exist
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2225): error C2653: 'Windows' : is not a class or namespace name
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2225): error C2871: 'Networking' : a namespace with this name does not exist
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2226): error C2653: 'Windows' : is not a class or namespace name
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2226): error C2871: 'Connectivity' : a namespace with this name does not exist
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2227): error C2065: 'IVectorView' : undeclared identifier
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2227): error C2065: 'HostName' : undeclared identifier
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2227): error C2059: syntax error : '>'
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2227): error C2653: 'NetworkInformation' : is not a class or namespace name
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2228): error C2065: 'hostnames' : undeclared identifier
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2228): error C2227: left of '->Size' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>C:\boost_1_55_0b1\boost/asio/detail/impl/socket_ops.ipp(2230): error C2065: 'HostName' : undeclared identifier
And many many others. I know by the fact, that the libraries work. It worked in the first program, so I just can't figure out what's causing the problem.
Other includes are the SDL and SDK for Kinect libraries for c++.

I just came across this too. I found by adding the "/P" option to the C++ compiler options in Visual Studio and recompiling the file that failed, that s_addr was indeed getting #defined.
The offending header was part of the Windows SDK inaddr.h, which is included in the header chain of winsock.h.
The offending line in the header was:
#define s_addr S_un.S_addr
More information about this header is on MSDN here.
The fix I found was to #undef s_addr just before the #include of the BOOST ASIO header.

Related

Errors building Freetype application with Visual Studio

I've been going bonkers the last week on this problem.
Microsoft Visual Studio Community 2013
Freetype 2.5.5
Windows 8.1
Building as C++ application
I've been trying to build against a static library for Freetype, I've tried after building the lib using the included VC2010 project and also downloading a pre-built library with no luck. I always get the same errors below. I've tried with multiple examples and the same. I'm able to successfully compile and link against the lib using gcc (after building a .a library), this problem seems to be isolated to Visual Studio..
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2143: syntax error : missing '}' before '('
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2143: syntax error : missing ';' before '<L_TYPE_raw>'
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2059: syntax error : '<L_TYPE_raw>'
1>f:\audio\libs\header\freetype\fterrors.h(164): error C2143: syntax error : missing ';' before '}'
1>f:\audio\libs\header\freetype\fterrors.h(177): error C2059: syntax error : '}'
1>f:\audio\libs\header\freetype\fterrors.h(177): error C2143: syntax error : missing ';' before '}'
1>f:\audio\libs\header\freetype\freetype.h(38): error C2143: syntax error : missing ';' before '{'
1>f:\audio\libs\header\freetype\freetype.h(38): error C2447: '{' : missing function header (old-style formal list?)
Example code that can cause this error:
#include <windows.h>
#include <ft2build.h>
#include FT_FREETYPE_H
int main(int argc, char **argv)
{
return 0;
}
I had the same issue while building FreeType2 in VS2013 with VS2013 toolset (SDK). No Google results seem to have answer to this so far so I thought I'd share even though the thread is bit old (but the problem is still recent! FreeType ver. 2.6 still suffers from the same problem).
For reference, this can be reproduced by minimal example:
#include <ft2build.h>
#include FT_FREETYPE_H
FT_Library library;
So the problem and solution is quite simple but was unfortunately buried in output log and wasn't that obvious at first glimpse so it needed some investigation.
There is a clash with header names between FreeType2 library and Windows SDK, namely with the fttypes.h file which gets dragged in from:
C:\Program Files (x86)\Windows Kits\8.1\Include\shared\fttypes.h
Instead, VS should include FT2 header that is located in:
your_FT2_root\include\fttypes.h
This is easy to workaround - in your Project Properties (Alt+F7) rearrange header search paths so FreeType2 path is first (for me bringing FT2 at the top worked like a charm).
Hope this helps!
Cheers,
Henryk

C++/CX and Amazon Product Advertising API

Language: C++/CX & XAML
Environment: Visual Studio 2013 on Windows 8.1
I am trying to use the Amazon Product Advertising API in my Windows Store app. I have an Associates account so I am allowed to use this however I'm having problems implementing the .wsdl file after using wsutil.exe to create a .c and .h file for my project.
The .c and .h files both have errors pointing to identifiers that reside inside WebServices.h.
Since the .c and .h files have a combined length of more than 13k lines of code I'll write out steps to reproduce my problem.
-Navigate to http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl
-Save the file either in a project fold or on the desktop
-Open up a VS2013 command prompt and navigate to where the file resides
-Type "wsutil /wsdl:AWSECommerceService.wsdl"
This produces the .c and .h files that can be used in the project
-Add the .c and .h files to a VC++ Windows Store app project
since the environment language is C++/CX and wsutil gave us a .c file we need to tell the compiler to treat this file as a C++ file otherwise if you try to build like it is it throws an error saying:
Command line error D8048: cannot compile C file '....\New folder\AWSECommerceService.wsdl.c' with the /ZW option
My first attempt at trying to fix this was to remove the /ZW option.
This can be done by right clicking the .c file, click properties, under "General" you will will see "yes(/ZW)" which you can change to "no".
after doing this and trying to build it gives this error:
...\awsecommerceservice.wsdl.c : fatal error C1853: 'Debug\SimpleShop.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)
That wasn't the correct fix so I went back and added the /ZW option.
Next I decided to tell the compiler to treat the .c file as a .cpp file by adding the /TP option. You can find this by right clicking the .c file, clicking properties, click Advanced, click the drop down box next to "Compile as" and selected /TP.
Now when trying to build the project errors appear in both the .c and .h files for identifiers that reside in the WebServices.h file.
This is where I'm stuck at. I tried to #include "WebServices.h" into the .h file (which is oddly missing it whereas the .c file is not) and this does nothing to remove any of the errors.
I can find nothing about using the Amazon Product Advertising API inside a windows store app on the internet so all of the attempted fixes came from Win7 or WCF forums. The steps I'm trying to follow are from Amazon on they can be found here (focus on step 4):
http://docs.aws.amazon.com/AWSECommerceService/latest/GSG/GettingSetUp.html
these are the errors:
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1037): error C2371: '_RelatedItems::RelatedItemCount' : redefinition; different basic types
1> c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1034) : see declaration of '_RelatedItems::RelatedItemCount'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1576): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1604): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1632): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1660): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1688): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1716): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1744): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1772): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1800): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1828): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1856): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(2709): error C2146: syntax error : missing ';' before identifier 'AWSECommerceServiceBinding'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(2709): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.c(1159): error C2146: syntax error : missing ';' before identifier 'contractDesc'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.c(1159): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.c(6674): fatal error C1903: unable to recover from previous error(s); stopping compilation
There are several things going on here:
You need to include the header pch.h at the top of the generated .c file
This sounds like a genuine error in the generated header. Notice a member defined twice.
typedef struct _RelatedItems
{
enum _Relationship Relationship;
WCHAR* RelationshipType;
unsigned __int64 RelatedItemCount;
unsigned __int64 RelatedItemPageCount;
unsigned __int64 RelatedItemPage;
unsigned int RelatedItemCount;
_Field_size_(RelatedItemCount)struct _RelatedItem* RelatedItem;
} _RelatedItems;
The other errors are because the missing identifiers are actually not available for Windows Store apps. Both WS_SERVICE_SECURITY_CALLBACK and WS_CONTRACT_DESCRIPTION are conditionally defined in the SDK header WebServices.h only for Desktop apps
"if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"

Winbase.h doesn't support in creating DLL file

I would like to create a project use to call c++ method using c#. So, I need to create a dll file for all of my c++ function. But when i get an error in y sqlite source code such as "AreFileApisASNSI undeclared identifier". So, i import winbase.h which is part of the mingw-w64 runtime package to my visual studio 2012 express DLL project. After import the file, I get many errors such as below:-
error c4430: missing type specifier - int assumed. Note: C++ does not support default - int
error C2143: syntax error : missing ';' before '_stdcall'
error c1003 error count exceeds 100; stopping compilation
error c2061: syntax error: identifier ' WINBOOL'
error c2086: 'int_CRT_INLINE' : redefinition
error c2143: syntax error: missing ';' before ''
error C2146: syntax error : missing ';' before identifier 'LONGLONG'
error C2146: syntax error : missing ';' before identifier 'PVOID'
any solution for those error? please help!!
The documentation for the function has this header requirement:
WinBase.h (include Windows.h)
This is telling you that the function is declared in WinBase.h, but that you should include Windows.h which in turn will include WinBase.h. So, you need to change your include to
#include <Windows.h>
I also wonder why you are talking about mingw considering that your compiler is MSVC. That compiler ships with a comprehensive Windows SDK. Why would you be using an SDK from mingw?

dirent.h casuing problems with ShellAPI.h

I have a function:
SHFileOperationFunc(string item1, string item2, int operation, CuTest *tc)
It is used to do operations (move, delete or copy) directories. It works fine. But i am now trying to use stuff from dirent.h. When I include the file it causes huge problems with stuff from ShellAPI.h I use in SHFileOperationFunc. I got dirent.h as per http://www.softagalleria.net/dirent.php.
After I include the file I get errors like:
error C2065: 'FO_DELETE' : undeclared identifier
error C2065: 'FO_COPY' : undeclared identifier
error C2065: 'FO_DELETE' : undeclared identifier
error C2065: 'FO_DELETE' : undeclared identifier
These are defined in ShellAPI.h. When I hover over them in VS it says the value they have so it is seeing them. Anyone know why including this file is having this effect?
Using dirent.h on a Windows machine is unadvisable, it is a Unix header. The file you downloaded screws up the rest of your #includes. Either put if after #include <windows.h> or edit the file and delete the #define for WIN32_LEAN_AND_MEAN. Putting that in a header is, well, mean. It causes a large number of declarations to be skipped in the Windows headers.

Compiling and using NTL c++ library for Windows

I have compiled the NTL inifite precision integer arithmetic library for c++, using Microsoft Visual Studio 2008. I did as explained, on this site, using the Visual Studio interface, rather than from the command prompt. Actually I would rather do it from the command prompt, but I was not sure how to.
Anyhow, I got the library compiled, and I now want to compile a program using the library, from the command prompt. The program I am trying to compile, has been tested on a linux system, where I compile it with the following
c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include mpqs.cpp main.cpp -o main -L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl -L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm
Nevermind the gmp stuff, I dont have that installed on Windows. It is purely an optional thing that will make the NTL run faster. Anyhow, this works fine on linux. Now on Windows I write the following
cl /EHsc /I D:\Downloads\WinNTL-5_5_2\include mpqs.cpp main.cpp /link /LIBPATH:"D:\Documents\Visual Studio 2008\Projects\ntl\Debug"
But this results in the following errors:
mpqs.cpp
mpqs.cpp(38) : error C2039: 'find_smooth_vals' : is not a member of 'QS'
d:\desktop\qs\mpqs.h(12) : see declaration of 'QS'
mpqs.cpp(41) : error C2065: 'M' : undeclared identifier
mpqs.cpp(41) : error C2065: 'n' : undeclared identifier
mpqs.cpp(42) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(42) : error C2228: left of '.size' must have class/struct/union
type is ''unknown-type''
mpqs.cpp(43) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(44) : error C2065: 'qx_table' : undeclared identifier
mpqs.cpp(44) : error C3861: 'test_smoothness': identifier not found
mpqs.cpp(45) : error C2065: 'smooth_indices' : undeclared identifier
mpqs.cpp(45) : error C2228: left of '.push_back' must have class/struct/union
type is ''unknown-type''
main.cpp
Generating Code...
It is as if, my mpqs.h file is not included into the compilation process? Also I dont understand why it complains about .push_back() for a vector type?
Help is much appreciated!
mpqs.h is definitely being included as the output asks you to refer to it.
Seeing as MPQS.h does not appear to be included in the NTL library ... did you write it? If so can you post the code up?
Also, shouldn't you included the library file somewhere on your build?
Edit: There is no function find_smooth_values so why should you expect MSVC to find it? I'm not sure why that compiles under GCC but its obviously missing. I'm guessing that the other errors are caused because of this one. The errors are telling you things. You should listen to them.
push_back is failing because it doesn't know what the type you are trying to push_back into is. This again is probably caused by the fact that find_smooth_values doesn't exist. Try adding the function prototype into the QS class. This may well fix all your problems.
As for the library it won't get to using the library until the compilation succeeds. So don't worry about that just now. Get in there and fix the errors that MSVC is reporting!