Compile problems in VC7.1

in Help Center
Hello gents,
I've been trying to port a small ICE app to windows, using vs7.1. But I ran into some problems... the program(s) still compile fine on linux, but I get the following errors in the compile log:
I think there's basically two problems here, the duplicate definitions/declarations errors and the 'TryEnterCriticalSection': identifier not found errors.
The former change when I comment my headers around in my server.cpp file (not main, that's in server_main.cpp) so here they are:
Any ideas? Tell me if you need more code..
Thanks in advance,
Alex
I've been trying to port a small ICE app to windows, using vs7.1. But I ran into some problems... the program(s) still compile fine on linux, but I get the following errors in the compile log:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(341): error C2084: function 'std::_Scalar_ptr_iterator_tag std::_Ptr_cat(const std::_Bool *,std::_Bool *)' already has a body
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(335): error C2084: function 'std::_Scalar_ptr_iterator_tag std::_Ptr_cat(std::_Bool *,std::_Bool *)' already has a body
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(228): error C2535: 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)' : member function already defined or declared
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(228): error C2535: 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)' : member function already defined or declared
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(228): error C2535: 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)' : member function already defined or declared
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\Ice-2.0.0\include\Ice\BasicStream.h(146): error C2535: 'void IceInternal::BasicStream::read(BOOL &)' : member function already defined or declared
c:\Ice-2.0.0\include\Ice\BasicStream.h(147): error C2535: 'void IceInternal::BasicStream::read(std::vector<_Ty,_Ax> &)' : member function already defined or declared
with
[
_Ty=BOOL,
_Ax=std::allocator<BOOL>
]
c:\Ice-2.0.0\include\Ice\BasicStream.h(144): error C2535: 'void IceInternal::BasicStream::write(BOOL)' : member function already defined or declared
c:\Ice-2.0.0\include\Ice\BasicStream.h(145): error C2535: 'void IceInternal::BasicStream::write(const std::vector<_Ty,_Ax> &)' : member function already defined or declared
with
[
_Ty=BOOL,
_Ax=std::allocator<BOOL>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(168): error C2766: explicit specialization; 'std::iterator_traits<std::_Bool>' has already been defined
c:\Ice-2.0.0\include\IceUtil\Mutex.h(141): error C3861: 'TryEnterCriticalSection': identifier not found, even with argument-dependent lookup
c:\Ice-2.0.0\include\IceUtil\Mutex.h(141): error C3861: 'TryEnterCriticalSection': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(604): fatal error C1903: unable to recover from previous error(s); stopping compilation
e:\Src\swccg\SWCCG\ICE\src\server_main.cpp(28): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
e:\Src\swccg\SWCCG\ICE\src\client.cpp(228): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
I think there's basically two problems here, the duplicate definitions/declarations errors and the 'TryEnterCriticalSection': identifier not found errors.
The former change when I comment my headers around in my server.cpp file (not main, that's in server_main.cpp) so here they are:
#ifdef WIN32 #include "my_global.h" #include <windows.h> #include <wtypes.h> #endif #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; #include "mysql.h" #include "message.h" #include "server.h" #include <IceUtil/Mutex.h>
Any ideas? Tell me if you need more code..
Thanks in advance,
Alex
0
Comments
Welcome to our forums!
The 'TryEnterCriticalSection' error is quite simple:
old versions of Windows (before NT 4.0) did not support the system call TryEnterCriticalSection on CriticalSection objects. A default Visual C++ build is compatible with old Windows releases, so it does not provide TryEnterCriticalSection: you need to define _WIN32_WINNT to 0x0400 (or greater) to see this function call.
In your code, you include windows.h before IceUtil/Config.h, so you get:
// _WIN32_WINNT not defined, so no TryEnterCriticalSection declaration
#include <windows.h>
// In IceUtil/Config.h
#define _WIN32_WINNT 0x0400
#include <windows.h> // does nothing
// In IceUtil/Mutex.h
# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
// use critical sections and TryEnterCritical section
#endif
The solution is to define _WIN32_WINNT to 0x400 before the first inclusion of windows.h. You can do this explicitely, by including any Ice header first in your translation unit, or by adding _WIN32_WINNT=0x400 as a preprocessor definition in your project.
I don't know for the second error; does it work if you include a Ice header first?
Cheers,
Bernard
(but it still gives me the same errors..)
But you are talking about including in 'my translation unit' and adding as a preprocessor definition, which is fuzzy to me (and/so I probably did it wrong), could you plz elaborate?
Thanks again!
PS. Buildlogs are here and here
Do you define WIN32?
If not, I'd recommend to use #ifdef _WIN32, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_predir_predefined_macros.asp.
Cheers,
Bernard
The rest of the errors have changed slightly while screwing around with it after the first post, so here is an update (pretty much the same I guess..)
Do you think they are related?
Thanks. Alex.
Note: I've also tried Ice 2.1.1, same errors.
I suspect your problem is coming from the inclusion of "wtypes.h" and some macros which aren't defined. In the wtypes.h file there's the following for instance:
It sounds like for some reasons _WIN32 wouldn't be defined... (but it's supposed to always be defined for Win32 applications).
Did you try to compile the Ice demos to see if this works?
Btw, you should also enable "Run-Time Type Info" for your project (from the build log you provided /GR is missing). You can enable this in the project settings -> C/C++ -> Language options.
Benoit.
I'll try to compile the demo app(s).
Thanks for the RTTI tip
by doing so you make sure the define is set for all files in your project.
project settings -> C/C++ -> preprocessor
add _WIN32_WINNT=0x0500 to the preprocessor definitions
cu tom
Now for the read() and write() declared/defined errors...?
I don't have them in my own code, except for __write and __read duplicates (with underscores) in my slice2cpp generated files... but those don't conflict, right?
what i can see from the old build logs:
these errors only occur on compilation of client.cpp and server.cpp.
can you post the includes of these files?
Headers used in the above buildlogs:
client.cpp:
server.cpp:
if you have a look at the header/lines you find:
line 124: void write(bool v)
line 144: void write(Ice::Int);
this means somewhere in your headers BOOL is defined to the same native type as Ice::Int
can you show us "my_globals.h"
http://www.jpipes.com/mysqldox/html/d0/d77/my__global_8h-source.html
That link is pretty much the version (file) I have..
Lines of interest (maybe?):
first ice includes - last mysql includes
should look like:
that way we can find a solution easier
DeepDiver: I'll admit I'm allways a bit ashamed when someone else has to debug my code, but here it is for you to dive deep into (hahah... :eek: )
Zip contains the server too btw..
please zip includes and libs and post them as well
Here's the deps..
as suspencted: switch the order of the includes and it compiles.
after adding #ifndef to console.h and client.h compilation was successfull.
i leave resolving the linker problems to you
Some link errors were due to missing windows default includes (and quickly fixed), but others were due to missing slice2cpp generated .cpp and .h files
So I added them but now I get 10 errors about "definition of dllimport static data member not allowed" and loads of "inconsistent dll linkage" warnings. :rolleyes:
e.g.:
fyi, the libs I link to are: iced.lib iceutild.lib mysqlclient.lib libmysql.lib wsock32.lib msvcprtd.lib msvcrtd.lib libcpmtd.lib libcmtd.lib
Of which the first two I've also compiled myself (2.1.1) but the errors stay the same when I use those..
Any help would be greatly appreciated 'cause those errors make little sense to me even after google, msdn and ice docs skim...
Thanks,
Alex
That'd be me
Well I thought before header files would be a nice place for a using namespace to reinforce it into all the header files that come after... Guess not then... They should be in the header files themselves?
Now, that's cluttered up if you ask me... But okay, I'll try to practise that...
Anyone?
I recommend you to take a closer look at the Ice demo projects to see the difference between your project settings.
Benoit.
hi alex,
1.) ignore the second #include "client.h" - it has no meaning - you can also remove this line.
2.) you should not link mysqlclient.lib[static linkage] but libmysql.lib[dll linkage]
3.) turn the c/c++ option 'ignore standard libs' off and remove these libs: msvcprtd.lib msvcrtd.lib libcpmtd.lib libcmtd.lib
i attached the project. i only worked on the client.
cu tom