gcc 3 vs gcc 4

Discussion in 'Mac Programming' started by cintari, Nov 4, 2008.

  1. cintari macrumors newbie

    Mar 1, 2007
    I have code that compiles on my linux box that is using gcc 3. I bring the code over to my mac and it fails to link.

    Undefined symbols error.

    The symbols are clearly defined in my header files but the linker is failing to find them.

    Does anyone know how to install gcc 3? I have a new alu macbook.
  2. gnasher729 macrumors P6


    Nov 25, 2005
    A quick reality check: What are the chances that there is a bug ni gcc 4.0 that hasn't stopped Apple from delivering Tiger and Leopard, and hasn't stopped hundreds of thousands of developers from writing code for MacOS X, and you are the first one who finds out about it, and going back to gcc 3.0 will fix it?
  3. Kane.Elson macrumors regular

    Jul 27, 2006
    I agree with the above poster. GCC 4 has been stable for a long time now, pretty much every modern unix/linux platform has had it installed by default for over a year now. I think if there was such a big linking problem it would have been fixed by now. I have never had any problems compiling in recent builds of gcc 4.
    I think you just need to look at what you are doing. Maybe you missed some parameters when compiling or something. A bit has changed since 3....
  4. cintari thread starter macrumors newbie

    Mar 1, 2007
    how do you explain why the exact code compiles using my linux box but fails on linking errors on my mac?

    As it turns out, I am not the only person that is in a separate reality than the rest of you.

    I found this:

    However, the instructions here do not work. I was hoping someone had a different way of doing it.
  5. Guiyon macrumors 6502a

    Mar 19, 2008
    North Shore, MA
    What symbols are not being defined in the source code you're attempting to compile and what command are you using to compile your source?
  6. cintari thread starter macrumors newbie

    Mar 1, 2007
    Here is a snippet
    Undefined symbols:
      "Player::kShotYOffset", referenced from:
          __ZN6Player12kShotYOffsetE$non_lazy_ptr in simulation.o
          __ZN6Player12kShotYOffsetE$non_lazy_ptr in hud.o
    inside player.h
    class Player {
    	static const float kShotYOffset = 0.05f;
    Here is what my make command is doing.

    g++ ${objects} -framework Cocoa -framework OpenGL -framework GLUT -framework Foundation -lstdc++ -lm -shared -o game
  7. ncl macrumors member

    Aug 16, 2008
    In C++, static const float data members cannot be initialized in the class definition. You have to separate the declaration and initialization:
    In Player.h:
    class Player {
    	static const float kShotYOffset;
    In Player.cpp:
    const float Player::kShotYOffset = 0.05f;
    I don't know why it worked with gcc 3. AFAIK, it shouldn't.
  8. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    It is highly unlikely that GCC 3 is doing anything correctly. What is probably happening is that GCC 3 allowed a mistake to go unnoticed and they just fixed the bug in GCC 4. So it is just now telling you about the bugs in your code.

    This is why you should always compile your code using the pedantic settings :).
  9. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    Initialising a static float in the class header is not in the standard. I'm finding that gcc 4 still lets you do it though, but you still need to declare storage for the variable. Perhaps gcc3 was allowing initialisation of floats the same way as ints for convenience?

    b e n
  10. cintari thread starter macrumors newbie

    Mar 1, 2007
    Thanks. This worked. It was lucky there weren't too many of these in the code. I should note that if you define it in the .h file and define it again in a .cpp file, the compiler complains of a double definition. So it seems that the compiler does store a value for it while parsing. It must ignore it during code generation.

    ALSO, I found out that Apple does not support gcc 3 compiled programs for intel macs.


Share This Page