c++ in xcode compile errors

Discussion in 'Mac Programming' started by qwerty2k, Feb 23, 2008.

  1. macrumors regular

    Hi, i was previously coding a project in Linux using CodeBlocks, it is using boost, guichan gui library and sdl as a backend. Ive imported my project into XCode and put all the required libraries etc into the project.

    However im getting some compile errors.

    the errors are in the complex numbers standard c++ header:

    error: 'snprintf' is not a member of 'std'
    error: '__pow_helper' is not a member of 'std'

    Now these are standard c++ headers, i haven't altered any of them so i am at a loss as to why they won't compile.
  2. macrumors 65816


    Looks like it's namespace resolution related - your default namespace seems to be set to std (using namespace std) and the C functions are part of global namespace specified explicity by prefixing :: to the function.

    So try using ::snprintf and the like and see if that resolves the errors.
  3. macrumors regular

    how can i open the file as an admin because its in an area a normal user can't edit (also in the file there are lots of references to functions prefixed with std:: and it doesn't error out on any of them)
  4. macrumors 65816


    Ok, I missed the part about the error being in standard headers.

    Can you #include <cstring> *before* #including the standard header which gives you the snprintf error and see?
  5. macrumors regular

    didn't work, gave me even more errors, the fsprintf errors are now in c++locale.h in the following bit of code:

    #ifdef _GLIBCXX_USE_C99
    const int __ret = std::snprintf(__out, __size, __fmt, __prec, __v);
    const int __ret = std::sprintf(__out, __fmt, __prec, __v);

    i was thinking maybe its to do with gcc4? since iirc on ubuntu when i was coding i was compiling with gcc3?
  6. macrumors 65816


    Yeah - sounds like some weird gcc/libstdc++ bug. But before I give up I have one last thing for you to try - #include <cstdio> and #include <cstdarg> in the files where you use snprintf - that _should_ get rid of the snprintf error I think.
  7. macrumors regular

    thank you for your suggestions, however the error still occurs :(
  8. macrumors 65816


    Hmm I am intrigued - do you have a reduced test case - like may be just copy the failing part of the code and create a standalone header and .cpp to reproduce this? If so post the .h/.cpp here and I will try to see what's going on.

    What version of gcc (gcc -v) are you compiling this under?
  9. macrumors newbie

    Found a solution

    Hi digging around for a solution, I found a comment suggesting that using the recursive checkbox i include paths was the problem.

    It was!.. Strange...

Share This Page