clang
supports plugins, and often this concept is used to build tools like static analysis and such.
To start playing with it I took this example which prints all function names present in the target cpp file(s).
I compiled the plugin running the following:
clang++ -v -std=c++11 PrintFunctionNames.cpp \
$(llvm-config --cxxflags --ldflags) \
-o plugin.so -shared -Wl,-undefined,dynamic_lookup
and then run it "by the book":
clang++ \
-c main.cpp \
-Xclang -load \
-Xclang $PWD/plugin.so \
-Xclang -plugin \
-Xclang print-fns
it works just fine: it prints the function names in main.cpp
and exit (without compiling main.cpp due the -c flag).
What I'd like to do is to print all the function names AND compile main.cpp into an executable.
I tried removing the -c
flag but I got:
/usr/bin/ld: cannot find /tmp/main-284664.o: No such file or directory
What am I doing wrong?