How to use tr1 with Visual Studio 2010 (tr1::function)? - c++

How does one start using the tr1 features of Visual Studio 2010? For a more specific case, I require the std::tr1::function. I tried including #include <tr1/functional> which reports as missing, while #include <functional> includes fine, but when I set this:
std::tr1::function<void(void)> callback;
I get:
1>d:\marmalade\projects\core\src\button.h(21): error C3083: 'tr1': the symbol to the left of a '::' must be a type
1>d:\marmalade\projects\core\src\button.h(21): error C2039: 'function' : is not a member of '_STL'
1>d:\marmalade\projects\core\src\button.h(21): error C2143: syntax error : missing ';' before '<'
1>d:\marmalade\projects\core\src\button.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\marmalade\projects\core\src\button.h(21): error C2238: unexpected token(s) preceding ';'
If I use boost, it works fine, but for this project, because of using a specific framework I'd require the Visual Studio tr1 version.
As suggested, skipping the tr1, still returns the same result:
std::function<void(void)> callback;
1>d:\marmalade\projects\core\src\button.h(20): error C2039: 'function' : is not a member of '_STL'
1>d:\marmalade\projects\core\src\button.h(20): error C2143: syntax error : missing ';' before '<'
1>d:\marmalade\projects\core\src\button.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\marmalade\projects\core\src\button.h(20): error C2238: unexpected token(s) preceding ';'

Based on your comments, and on this page, I think that Marmalade comes with it's own STL implementation, that appears out of date. This page verifies that they use a version of STLPort, that does not support the TR1 that came out in 2005, much less anything newer. Your options are:
1) Copy/write those yourself
2) Do without
3) Download a newer version of STLPort. It doesn't seem to have been updated in the last two years, so no C++11, but they do mention having functional, but aren't clear as to if it's in the std or std::tr1 namespace. However, this might not work with Marmalade, so make backups and be careful.

Visual Studio 2010 ships with C++11 enabled by default (or at least what is implemented). You need to use std::function<void(void)>.
For a complete table see here.
As an aside: You shouldn't use anything from TR1 nowadays. It has been integrated into the new standard.

Related

How to fix compile errors when including emscripten headers?

I'm trying to use emscripten Embind to bind C++ functions to JavaScript. Unfortunately I already get compile errors when including the specific header file with #include <emscripten/bind.h>.
I checked my emscripten environment and set an additonal Include Directory in VS2013 to the absolute path of the installation folder (also tried $(EMSCRIPTEN); and adapted the inlcude statement).
When compiling my project, I get 20+ compile errors:
17>d:\program files\emscripten\emscripten\1.25.0\system\include\emscripten\wire.h(24): error C2144: syntax error : 'bool' should be preceded by ';'
17>d:\program files\emscripten\emscripten\1.25.0\system\include\emscripten\wire.h(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
17>d:\program files\emscripten\emscripten\1.25.0\system\include\emscripten\wire.h(39): error C2146: syntax error : missing ';' before identifier 'TYPEID'
17> d:\program files\emscripten\emscripten\1.25.0\system\include\emscripten\wire.h(42) : see reference to class template instantiation 'emscripten::internal::CanonicalizedID<T>' being compiled
17>d:\program files\emscripten\emscripten\1.25.0\system\include\emscripten\wire.h(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
17>d:\program files\emscripten\emscripten\1.25.0\system\include\emscripten\wire.h(54): error C2146: syntax error : missing ';' before identifier 'TYPEID'
...
I tried emscripten 1.22.0 and 1.25.0 and verified my emscripten environment following those instructions. What am I missing?
As far as I know, of the MS Visual Studio editions, only VS2010 is supported in Emscripten.
http://kripken.github.io/emscripten-site/docs/getting_started/getting_started_with_emscripten_and_vs2010.html#getting-started-emscripten-from-visual-studio

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?

openGl - 143 errors from the includes

I'm working on windows XP with Visual C++ 2008 Express Eition.
Im trying to include:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
and getting alot of errors like:
1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(1152) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(1152) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(1152) : error C2146: syntax error : missing ';' before identifier 'glAccum'
1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(1152) : error C2182: 'APIENTRY' : illegal use of type 'void'
etc.
My question is: can i use those includes or do i need to get those libraries from somewhere at first?
Thanks.
For reasons known to Microsoft only, the OpenGL headers provided with the various Windows SDKs require that you
#include <windows.h>
before.
You are probably trying to compile it as C++ instead of C, or something along those lines.
Why are you using SDKs named 'v6.0a' with VC++2K8? Are you sure that's the latest OpenGL headers you have? You should be using latest Platform SDK and OpenGL headers whenever possible.

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.

Compiliation errors on boost files

I'm getting a lot of errors compiling code using the boost libraries, mainly when I'm using Spirit namespace. The errors are syntax errors on boost files like:
boost/spirit/home/classic/dynamic/lazy.hpp(33) : error C2143: syntax error : missing ';' before '<'
or
boost/spirit/home/classic/dynamic/lazy.hpp(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
or
boost/spirit/home/classic/utility/grammar_def.hpp(104)
: error C2039: 'nil_t' : is not a
member of 'boost::phoenix'
I am migrating from Visual Studio 6 to Visual Studio 2008 Express and from one of the oldest versions of boost to the lastest.
I'd like to know what's the problem. I'm thinking the problem can't be in the boost library.
My guess, like Timi Geusch, is an errant #define.
I've never used VS, but if there is an option to see the code after it has been passed through the preprocessor, you might be able to figure out what causing the problem.
The problem was resolved just including phoenix1 the old version of phoenix.