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.

Click to expand...

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?

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....

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 .

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?

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:

Code:

class Player {
static const float kShotYOffset;
...
};

In Player.cpp:

Code:

const float Player::kShotYOffset = 0.05f;

I don't know why it worked with gcc 3. AFAIK, it shouldn't.

Click to expand...

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.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.