source file
rsetti::fastidio { /tmp }-> cat foo.c
#include <stdio.h>
void ACFunction() {
printf("ACFunction()\n");
AGoFunction();
}
compilation of shared lib
rsetti::fastidio { /tmp }-> clang -shared -o libfoo.so foo.c
foo.c:4:3: warning: implicit declaration of function 'AGoFunction' is invalid in C99 [-Wimplicit-function-declaration]
AGoFunction();
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_AGoFunction", referenced from:
_ACFunction in foo-lFDQ4g.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
rsetti::fastidio { /tmp }->
the same code on linux + gcc can be easily compiled.
To compile a C++ program on the command line, run the clang++ compiler as follows: $ scl enable llvm-toolset-6.0 'clang++ -o output_file source_file ...' This creates a binary file named output_file in the current working directory. If the -o option is omitted, the clang++ compiler creates a file named a.
Clang is a "LLVM native" C/C++/Objective-C compiler using LLVM as a backend and optimizer. It aims to be GCC compatible yet stricter, offers fast compile times with low memory usage, and has useful error and warning messages for easier compile troubleshooting.
Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.
By using:
-Wl,-undefined -Wl,dynamic_lookup
or
clang -shared -undefined dynamic_lookup -o libfoo.so foo.c
seems to maintain the same behaviour of GCC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With