Yes, this is possible. To convert foo.a
into libfoo.dylib
, try this command:
clang -fpic -shared -Wl,-all_load foo.a -o libfoo.dylib
On Linux, here's the equivalent command using gcc
:
gcc -fpic -shared -Wl,-whole-archive foo.a -Wl,-no-whole-archive -o foo.so
Here's a complete example.
Let's start by creating (and testing) libfoo.a
:
$ cat > foo.h
int foo();
$ cat > foo.c
int foo() {
return 42;
}
$ cat > main.c
#include "foo.h"
int main() {
return foo();
}
$ clang -c foo.c -o foo.o
$ ar -r libfoo.a foo.o
ar: creating archive libfoo.a
$ clang libfoo.a main.c -o main.out
$ ./main.out; echo $?
42
Now let's convert it into libbar.dylib
and test again:
$ clang -fpic -shared -Wl,-all_load libfoo.a -o libbar.dylib
$ clang -L. -lbar main.c -o main.out
$ ./main.out; echo $?
42