"Missing symbols at link time" build failure(s)
clang 3.6.0
Undefined references can have different reasons. Here are some:
1) The most common issue is about the the
inline behavior.
clang is following by default the C99 standard while gcc promote GNU89.
The following code will build with gcc but fails with:
main.c:(.text+0x12): undefined reference to `xrealloc'
// the right declaration in C99 is:
// static inline void xrealloc()
inline void xrealloc() { }
int main(){
xrealloc();
return 1;
}
besides the static, the command:
clang -std=gnu89 -o plop.exe main.c
will fix the issue.
See the
clang website for more information.
2)
An other issue is that gcc is that gcc optimizes the call to some functions at -O0 (causing -lm to be not necessary)
#include <math.h>
// Works: gcc -O0 -o plop plop.c
// Fails: clang -O0 -o plop plop.c
// Works: clang -lm -O0 -o plop plop.c
int main() {
double plop = fabs(2.0);
return 1;
}
3) There are also some rare issues with the --relocatable/-r linker flag.