Creating a c++ framework in XCode... problems with stl

Discussion in 'Mac Programming' started by oldio, May 13, 2009.

  1. oldio macrumors newbie

    Joined:
    Mar 30, 2008
    Location:
    Montreal, Canada
    #1
    I created a custom c++ framework using XCode and overall it works like a charm. Except recently i've been having a problem with the stl library which is kind of a major drawback. So i'm wondering if anyone has ever encountered this before and has a solution for it.

    Details of the implementation of a class in the framework :

    Code:
    namespace Odd
    {
        namespace Utils
        {
            class CRandomUtils
            {
            public:
                
                ... ( other methods )...
    
                static void GenerateUnitVectors( vector<CVector3>& Samples, const int NbSamples ); 
                
            private:
                CRandomUtils( void )                {}
                ~CRandomUtils( void )               {}
            };
        }
    }
    
    CRandomUtils is a class with alot of static helper fonctions to generate different sorts of noise ( perlin, poisson, gaussian ) maps.
    The code in an application using this class :

    Code:
    #include <vector>
    #include <Odd/Vector3.h>
    #include <Odd/OGLTexture2D.h>
    #include <Odd/RandomUtils.h>
    
    using namespace std;
    using namespace Odd::Math;
    using namespace Odd::OpenGL;
    using namespace Odd::Utils;
    
    ...
    
        vector<CVector3> NoiseMap;
        
        CRandomUtils::GenerateUnitVectors( NoiseMap, 64 * 64 );
        
        CVar::m_TextureNoise = new COGLTexture2D();
        CVar::m_TextureNoise->Load( &NoiseMap[ 0 ], GL_RGB, GL_FLOAT, 64, 64, GL_LINEAR, GL_LINEAR );
    
    
    
    The compiling error :

    Code:
    
        cd /Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions
        setenv MACOSX_DEPLOYMENT_TARGET 10.5
        /Developer/usr/bin/g++-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -L/Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions/build/Debug -L/opt/local/lib -F/Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions/build/Debug -F/Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions/../Odd/build/Debug -filelist /Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions/build/ScreenSpaceAmbientOcclusions.build/Debug/ScreenSpaceAmbientOcclusions.build/Objects-normal/i386/ScreenSpaceAmbientOcclusions.LinkFileList -mmacosx-version-min=10.5 -framework OpenGL -framework GLUT -lglew -lfreeimage -framework Odd -o /Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions/build/Debug/ScreenSpaceAmbientOcclusions
    ld warning: std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)has different visibility (hidden) in /opt/local/lib/libfreeimage.a(PluginEXR.o-i386) and (default) in /Users/Olivier/Dev/C++/ScreenSpaceAmbientOcclusions/build/ScreenSpaceAmbientOcclusions.build/Debug/ScreenSpaceAmbientOcclusions.build/Objects-normal/i386/Main.o
    Undefined symbols:
      "Odd::Utils::CRandomUtils::GenerateUnitVectors(__gnu_debug_def::vector<Odd::Math::CVector3, std::allocator<Odd::Math::CVector3> >&, int)", referenced from:
          Initialize()     in Main.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    	  "Odd::Utils::CRandomUtils::GenerateUnitVectors(__gnu_debug_def::vector<Odd::Math::CVector3, std::allocator<Odd::Math::CVector3> >&, int)", referenced from:
    	      Initialize()     in Main.o
    	ld: symbol(s) not found
    	collect2: ld returned 1 exit status
    
    
    I can however change the declaration of the method to use raw pointers and it all works fine except I would really like to use the stl library to do this stuff.

    Did anyone ever encounter this ? What was your solution ?

    Thanks for the help
     
  2. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    At some point the compiler decided that vector<>, in the declaration of GenerateUnitVectors(), belongs to the __gnu_debug_def namespace, whereas what you expected std.

    Try being explicit in the declaration and definition of GenerateUnitVectors() -- use std::vector<>, etc.

    You might still get an error, if something is out-of-whack with the namespaces, but hopefully it will be a clearer message.
     
  3. oldio thread starter macrumors newbie

    Joined:
    Mar 30, 2008
    Location:
    Montreal, Canada
    #3
    @iSee

    Thanks for the reply. I tried what you suggested and added the modification to the method in the framework. Here is the new error message.

    Code:
      "Odd::Utils::CRandomUtils::GenerateUnitVectors(__gnu_debug_def::vector<Odd::Math::CVector3, std::allocator<Odd::Math::CVector3> >&, int)", referenced from:
          Initialize()     in Main.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    
    
    For some reason it still uses the __gnu_debug_def namespace. However, compiling the app in release mode works fine.

    Do you know of anyway to force the namespace to std in debug mode ?
     
  4. oldio thread starter macrumors newbie

    Joined:
    Mar 30, 2008
    Location:
    Montreal, Canada
    #4
    Ok, had some time to look more into this problem and found a way to fix it... thanks to iSee's help :) !

    It seems that by default XCode v3 will define the following in debug mode :

    _GLIBCXX_DEBUG=1
    _GLIBCXX_DEBUG_PEDANTIC=1

    Which will force your app to use the __gnu_debug_def namespace for any stl containers. In release mode they will not be defined and the stl namespace will be used.

    However when creating a framework in debug mode, the previous defines are not present. So after adding them to the project settings everything worked normally.
     

Share This Page