A shared object is created with the name a.out , and then another shared object called libbindings.so , which supposedly refers to a.out but does not refer to anything. Now, if there are no undefined characters in the input file set, no libraries are searched or added to the output. So libbindings.so is essentially an empty library. Make sure that:
% nm a.out | grep create_foo 00000000000006bc T create_foo % nm libbindings.so | grep create_foo %
If you have several source files, you must create an object file from each source (use the -c compilation flag) (then optionally merge the objects into a static library --- skip this step if you are not releasing static libraries), then create a shared object from previously constructed objects:
clang++ -c -fPIC foo.cpp clang++ -c -fPIC bar.cpp clang++ -shared -o libfoobar.so foo.o bar.o
If you have only one source or very few source files that you can easily compile together, you can create a shared library in one step:
clang++ -std=c++14 wrapper.cpp somethingelse.cpp -shared -fPIC -o libbindings.so
This is not recommended for large projects.
source share