Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling with clang and plugin

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?

like image 646
Stefano Azzalini Avatar asked Mar 09 '23 05:03

Stefano Azzalini


1 Answers

You need to use -add-plugin instead of -plugin

like image 140
gkoreman Avatar answered Mar 16 '23 01:03

gkoreman