用clang和插件编译 [英] compiling with clang and plugin

查看:123
本文介绍了用clang和插件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

clang支持插件,并且通常将此概念用于构建诸如静态分析之类的工具. 要开始使用它,我使用了此示例,其中将打印目标cpp文件中存在的所有函数名称.
我编译了运行以下命令的插件:

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

然后按书"运行它:

clang++ \
 -c main.cpp \
 -Xclang -load \
 -Xclang $PWD/plugin.so \
 -Xclang -plugin \
 -Xclang print-fns

工作正常:在main.cpp
中打印函数名称并退出(由于-c标志而无需编译main.cpp).

it works just fine: it prints the function names in main.cpp
and exit (without compiling main.cpp due the -c flag).

我要做的是打印所有函数名称,并将main.cpp编译为可执行文件.
我尝试删除-c标志,但得到了:

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

我在做什么错了?

推荐答案

您需要使用-add-plugin而不是-plugin

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

这篇关于用clang和插件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆