Home Help Center

Compile problems in VC7.1

pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
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:
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

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Alex,

    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
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Yeah, I read that somewhere earlier today, so I changed my server_main.cpp header includes to:
    #ifdef WIN32
    	#ifndef _WIN32_WINNT
    		# define _WIN32_WINNT 0x400
    	#endif
    	#include <windows.h>
    	#include <wtypes.h>
    #endif
    
    extern "C" {
    #include <stdlib.h>
    }
    
    #include <Ice/Ice.h>
    #include "SWCCG.h"
    #include <iostream>
    #include <vector>
    #include <time.h>
    
    using namespace std;
    
    #include "server.h"
    #include "auth.h"
    
    (client_main.cpp is similar)
    (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
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Alex,

    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
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Thanks Bernard, I still get "c:\Ice-2.0.0\include\IceUtil\Mutex.h(141): error C3861: 'TryEnterCriticalSection': identifier not found, even with argument-dependent lookup" though :)

    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..)
    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(146): error C2535: 'void IceInternal::BasicStream::read(BOOL &)' : member function already defined or declared
    c:\Ice-2.0.0\include\Ice\BasicStream.h(129) : see declaration of 'IceInternal::BasicStream::read'
    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(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(137) : see declaration of 'IceInternal::BasicStream::read'
    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(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:\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:\Ice-2.0.0\include\Ice\BasicStream.h(128) : see declaration of 'IceInternal::BasicStream::write'
    c:\Ice-2.0.0\include\IceUtil\Mutex.h(141): error C3861: 'TryEnterCriticalSection': identifier not found, even with argument-dependent lookup

    Do you think they are related?

    Thanks. Alex.

    Note: I've also tried Ice 2.1.1, same errors.
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    It sounds like you've got some conflicts with the header files. Did you try to include <Ice/Ice.h> first? Something like the following:
    #include <Ice/Ice.h>
    #include "SWCCG.h"
    #include <iostream>
    #include <vector>
    #include <time.h>
    
    using namespace std;
    
    #include "server.h"
    #include "auth.h"
    

    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:
    #if !defined(_WIN32) && !defined(_MPPC_)
    // The following code if for Win16 only
    ...
    typedef long BOOL
    ...
    

    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.
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    wtypes and windows.h weren't part of the original code (which compiled with the same errors), I added them later, because it fixed some errors I had once in another project... Removing those includes doesn't make a difference. Putting the ICE includes at the top doesn't either :/

    I'll try to compile the demo app(s).

    Thanks for the RTTI tip
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    The hello and MFC demo-app compile fine
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    try to add the define to the project settings
    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
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Thanks DeepDriver, that took care of the 'TryEnterCriticalSection'-error!
    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?
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    can we see the build logs again??


    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?
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Not so nice for later reference, but I replaced the buildlogs here and here with newer ones.

    Headers used in the above buildlogs:
    client.cpp:
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    
    using namespace std;
    
    #ifdef _WIN32
    	#include "my_global.h"
    #endif
    
    #include "mysql.h"
    #include "client.h"
    #include "client_help.h"
    

    server.cpp:
    #include <IceUtil/Mutex.h>
    
    //#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"
    
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    from the build log
    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(124) : see declaration of 'IceInternal::BasicStream::write'
    

    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"
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    It's a mysql headerfile that needs to be included (in windows) before mysql.h is included.

    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?):
    00836 typedef char            my_bool; /* Small bool */
    00837 #if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
    00838 typedef char            bool;   /* Ordinary boolean values 0 1 */
    00839 #endif
    
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    try to re-arrange the includes in client.cpp

    first ice includes - last mysql includes
    should look like:
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    
    using namespace std;
    
    #include "client.h"
    #include "client_help.h"
    
    
    #ifdef _WIN32
    	#include "my_global.h"
    #endif
    
    #include "mysql.h"
    
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Putting the mysql includes below the client and client_help includes results in lots of unresolved symbols. The "read()/write() already defined/declared errors" also remain there all the time. :confused:
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    can you zip the client project and post it?

    that way we can find a solution easier
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    As an aside, you should never put a "using namespace std" before you include header files. This could cause all kinds of side effects.
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    marc: I agree! (I'll tell the other coder ;) )

    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..
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    what version of mysql?

    please zip includes and libs and post them as well
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    It's MySQL 4.1.12 here.

    Here's the deps..
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    client.cpp:
    //#ifdef _WIN32	
    //	#include <windows.h>
    //	#include <wtypes.h>
    //#endif
    
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    
    #include "client.h"
    
    #ifdef _WIN32	
    	#include "my_global.h"
    #endif
    
    #include "mysql.h"
    
    #include "client.h"
    #include "client_help.h"
    

    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
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Thanks alot deepdiver! Why '#include "client.h" ' twice though? Afaics the second one can be commented out..

    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.:
    e:\Src\swccg\SWCCG\ICE\vc7.1\ICE\client\SWCCG.cpp(1852): error C2491: 'SWCCG::Auth::__all' : definition of dllimport static data member not allowed

    ( ... )

    e:\Src\swccg\SWCCG\ICE\vc7.1\ICE\client\SWCCG.cpp(1471): warning C4273: 'IceDelegateD::SWCCG::Auth::create' : inconsistent dll linkage

    ( ... )

    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
  • cokecoke Member
    pokemoen wrote:
    marc: I agree! (I'll tell the other coder ;) )

    That'd be me :p (Been a while since I posted here...)

    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?
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    You should not have any "using namespace" statements at global scope in any header file, because this means that every other file that includes this header file will automatically inherit this statement as well. You should only use such statements in C++ source files, after all include statements, and never in header files at global scope. (This doesn't really have anything to do with Ice, this applies to all C++ programs.)
  • cokecoke Member
    So that means I'd have to use the namespaces for every type I want to use, as well? Like class stuff { std::string memberStr; }? :eek:

    Now, that's cluttered up if you ask me... But okay, I'll try to practise that... :D
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    Okay guys, could this be of any influence to the errors I'm getting? I don't think so... any other ideas? Wild guesses maybe?? :confused:
  • cokecoke Member
    Sorry dude, not a Windows coder myself... :p I think we agreed you'd do that part... ;) But yea, maybe someone else on this forum knows...
  • pokemoenpokemoen Member Alex ManOrganization: NoneProject: SWCCG
    np, just trying to stay on track... I just don't know what the VC compiler wants from me :/
    Anyone?
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Your linker options of your projects are suspicious. The code is compiled with /MDd and you link with the static and dynamic C and C++ libraries (libc.lib/mvsctr.lib and libcp.lib/msvpcrtd.lib). If you compile with /MDd, you should be linking with the dynamic C and C++ libraries: mvsctr.lib and msvpcrtd.lib (see this link for more information).

    I recommend you to take a closer look at the Ice demo projects to see the difference between your project settings.

    Benoit.
  • DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
    pokemoen wrote:
    Thanks alot deepdiver! Why '#include "client.h" ' twice though? Afaics the second one can be commented out..

    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

    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
Sign In or Register to comment.