#import and .h files problem - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: #import and .h files problem (/thread-1644.html)
#import and .h files problem - kendric - Mar 11, 2009 09:34 AM
I have 2 .h files
I use them in 2 classes and I import using #import.
I get duplicate function linker errors. The functions in each.h are not the same but its acting like the #import is not blocking the double include. I even tried #ifndef lock around it and it didn't help.
Does anyone know whats going on? The 2 functions in question are:
Vector3f Vector3f_create(CGFloat x, CGFloat y, CGFloat z)
Vector2f Vector2f_create(CGFloat x, CGFloat y)
#import and .h files problem - ThemsAllTook - Mar 11, 2009 12:22 PM
kendric Wrote:but its acting like the #import is not blocking the double include
This actually doesn't help you here. If you import this header from more than one implementation file, you end up with multiple definitions of the functions declared in the header, since the implentation files are compiled in separate modules. Since #import is essentially just a copy-and-paste operation, each module gets its own copy of the functions, so the linker complains that there are multiple definitions when it stitches your object files together.
A simple solution is to add the static qualifier to the functions in the header. All function implementations in header files that may be included from more than one module must be static for exactly this reason.
#import and .h files problem - kendric - Mar 11, 2009 01:54 PM
Thank you much! This solved the problem!