[LLVMdev] Building LLVM on OS X Yosemite & Passes
serge guelton
sguelton at quarkslab.com
Wed Feb 18 02:23:37 PST 2015
On Wed, Feb 18, 2015 at 03:17:44AM -0600, Andrew Selvia wrote:
> I want to create LLVM passes on OS X Yosemite. First, I built LLVM as such (based on http://llvm.org/docs/GettingStarted.html <http://llvm.org/docs/GettingStarted.html> and trial & error):
>
> ...
> $ mkdir build && cd build
> $ CC=clang CXX="clang++ -stdlib=libc++" ../llvm/configure --enable-libcpp --enable-shared
> $ make
> $ make install
>
> Then, I tested it with the following command. It worked!
>
> $ opt -load /usr/local/lib/LLVMHello.dylib -hello <test.bc>/dev/null
>
> However, when attempting to build my own pass in OS X Yosemite, I ran into confusing linking problems:
>
> $ c++ $(CXXFLAGS) SourceLineAnnotator.cpp -c -o SourceLineAnnotator.o
> $ c++ SourceLineAnnotator.o -shared -o annotate.so
>
I have no trouble building my passes with the following commands:
$> /usr/bin/c++ $CPPFLAGS -std=c++11 -fno-rtti -fPIC -fno-exceptions -fno-rtti -o my.o -c my.cpp
$> /usr/bin/c++ -std=c++11 -fno-rtti -fPIC -std=c++11 -bundle -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-flat_namespace -Wl,-undefined -Wl,suppress -o my.dylib my.o
This command was generated by cmake thanks to the LLVM config...
[...]
> Eventually, I discovered the .so file could be successfully compiled as follows:
>
> $ c++ SourceLineAnnotator.o -shared `/usr/local/bin/llvm-config --ldflags --libs --system-libs` -o annotate.so
>
> By adding the flags specified, I can now compile the pass to a .so file. However, when I attempt to load it with opt, I get another type of error (also related to linking from what I can tell):
>
> $ opt -load annotate.so -annotate <test.bc>/dev/null
>
> opt: CommandLine Error: Option 'print-before-all' registered more than once!
> LLVM ERROR: inconsistency in registered CommandLine options
You get this error because you're linking statically with some LLVM core
libs (from the /usr/local/bin/llvm-config --ldflags --libs --system-libs). They have static conbstructors that register options, and those have already been registered when liked within opt.
> I’m quite stuck. I have fought with linker errors for weeks now and I’m not sure what to try. Any help would be greatly appreciated.
More information about the llvm-dev
mailing list