#import and .h files problem

Member
Posts: 306
Joined: 2009.03
Post: #1
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)
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
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.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #3
Thank you much! This solved the problem!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  import explosion 9livesoftware 0 2,068 Aug 8, 2009 04:25 PM
Last Post: 9livesoftware