Reputation: 4885
If I make this function inline and call it from a objective-c method, it gives me a clang: error: linker command failed with exit code 1 (use -v to see invocation)
Vector addv(Vector v1, Vector v2) {// works
return (Vector){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
}
inline Vector addv(Vector v1, Vector v2) {// if I call this, does not build
return (Vector){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
}
Why is it doing this, and what can I do to fix it?
Upvotes: 2
Views: 187
Reputation: 78943
C99 inline
doesn't guarantee that a linker symbol is emitted. You'd have to place an "instantiation" in just one compilation unit (that is a .c).
So the inline
definition in the .h file:
inline Vector addv(Vector v1, Vector v2) {// if I call this, does not build
return (Vector){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
}
and
Vector addv(Vector v1, Vector v2);
in one .c file to generate the symbol.
Upvotes: 3