Linking error for inline functions Linking error for inline functions objective-c objective-c

Linking error for inline functions


That to me, looks like a bug. This simple case exhibits the same error:

inline void foo() {}int main() {    foo();}

Yields:

$ clang test-inline.cUndefined symbols for architecture x86_64:  "_foo", referenced from:      _main in test-inline-MfUY0X.old: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)

That has got to be wrong!? Unless I'm totally missing something about inline.

Edit: Oh no, wait, check out this - http://clang.llvm.org/compatibility.html#inline

Basically it appears I didn't understand inline fully, either. And nor did the person writing that sample code at Apple!

The inline on the ChangeBits function means that that definition is to be used only for inlining. Not that the function should always be inlined. There must be another, non-inline definition available elsewhere in the application otherwise it's illegal. Hence the link error as no non-inline ChangeBits is provided.

The real solution is to declare ChangeBits as static inline since that tells the compiler that the definition is local to that translation unit only and there does not therefore need to be a non-inline definition.

More information on the LLVM page I linked to, though. Hope that helps!