I've run into weird issue where I need to pass -lm to clang in order for it to compile the code:
gcc test.c -o test #works
clang test.c -o test #doesn't work
clang -lm test.c -o test #works
#include <stdio.h>
#include <complex.h>
int main() {
double complex z = 1.0 + 3.0 * I;
double complex conjugate = conj(z);
printf("The conjugate of Z is = %.2f %+.2fi\n", creal(conjugate), cimag(conjugate));
return 0;
}
Specifically, there is linker error:
/tmp/test-561678.o: In function `main':
test.c:(.text+0x4a): undefined reference to `conj'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
One important thing I noticed is that in this case gcc is able to outperform clang easily, because gcc inlines function calls whereas clang doesn't:
clang:
$ nm -g test
0000000000601048 B __bss_start
U conj@@GLIBC_2.2.5
...
gcc:
$ nm -g test
0000000000601038 B __bss_start
...
I use kubuntu 16.04. Clang 3.8 version, and 5.4.0 gcc version.
Is there a way to make clang inline calls to these functions ?