CLANG getting started

Hello,

I’m a newbie here and I’m having some trouble with running the examples from clang. I built libPrintFunctionNames.so , by doing make in llvm/tools/clang/examples/PrintFunctionNames, but I don’t know how to see it at work. I’ve tried with

opt -load /usr/llvm/Debug/lib/libPrintFunctionNames.so -print-fns test.bc

just like one would do for a llvm pass, but it doesn’t work:

opt: CommandLine Error: Argument ‘version’ defined more than once!
opt: CommandLine Error: Argument ‘help-hidden’ defined more than once!
opt: CommandLine Error: Argument ‘help’ defined more than once!
opt: CommandLine Error: Argument ‘debug-only’ defined more than once!
opt: CommandLine Error: Argument ‘debug’ defined more than once!
opt: CommandLine Error: Argument ‘info-output-file’ defined more than once!
opt: CommandLine Error: Argument ‘track-memory’ defined more than once!
opt: Unknown command line argument ‘-print-fns’. Try: ‘opt --help’

I could really use a hand on this, especially because I can’t find some fully explained examples on clang site (are there any? if yes, please give me a link).

Many thanks,
Cristina

Well, libPrintFunctionNames.so is not an opt plugin, so that doesn't
work. It is a
clang-cc plugin. So:

clang-cc -load libPrintFunctionNames.so -plugin=help should print

clang-cc plugins:
  print-fns - print function names

and clang-cc -load libPrintFunctionNames.so -plugin=print-fns should execute it.

Hello,

I am also having the same problem; of course, I am using the last version of this example, so my command line looks like:

$> clang -cc1 -load /home/xxx/llvm/Debug/lib/libPrintFunctionNames.so -plugin=help

I get the below error:

$> error: unknown argument: ‘-plugin=help’

I am following the README file, so I added the next lines to the tool/clang/Makefile:

No plugins, optimize startup time.

TOOL_NO_EXPORTS = 1

I make clean and make it again, and I’m still getting the same error.

Somebody know what could be the problem?

BTW, I also test TOOL_NO_EXPORTS = 0, and I used the commands suggested by Seo.

Thanks in advance,

Juan Carlos

Hi,

The -plugin argument changed syntax and no longer accepts the
'-plugin=foo' form, use '-plugin foo' (e.g., '-plugin help') instead.

However, I think that the plugin example is currently broken because
of the way static constructors in the back end work. I hope to add
some new API hooks to make writing non-plugin clang -cc1 like tools
easier, and I will switch the PrintFunctionNames example to use that
API when I do.

- Daniel