3

When I use command "gcc .. ../../*.so", there are the following error messages:

/usr/bin/ld: /home/demonwnb/build/src/*.so: error: undefined reference to 'llvm::raw_ostream::operator<<(void const*)'
/usr/bin/ld: /home/demonwnb/build/src/*.so: error: undefined reference to 'clang::DeclarationName::printName(llvm::raw_ostream&) const'

I think that I do not link "llvm library" correctly, so how should I do?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
kunou
  • 91
  • 1
  • 2
  • 3

2 Answers2

6

You need to tell your compiler where to load the libraries from, which can be done using the llvm-config command.

You could set the following symbols in your makefile

CC = g++

LLVM_MODULES = core jit native

CPPFLAGS = `llvm-config --cppflags $(LLVM_MODULES)`
LDFLAGS = `llvm-config --ldflags $(LLVM_MODULES)`
LIBS = `llvm-config --libs $(LLVM_MODULES)`

all:
    $(CC) *.o $(LDFLAGS) $(LIBS) -o MyOutput
main:
    find -name '*.cpp' -print0 | xargs -0 $(CC) -c $(CPPFLAGS)
Chethan Ravindranath
  • 2,001
  • 2
  • 16
  • 28
  • @kunou: This is an extract from my makefile of a project that uses LLVM. You might have to tweak a bit to make it work for your project! – Chethan Ravindranath Dec 09 '11 at 04:14
  • 1
    It's worth mentioning that LLVM builds itself as set of static libraries. Some linkers a sensitive to order of -lLLVM* flags, so it's **highly** recommended to use llvm-config script. Or `llvm_map_components_to_libraries()` if you are using CMake. – arrowd Dec 09 '11 at 13:48
  • @kunou You could mark this as the right answer if it worked for you! – Chethan Ravindranath Dec 16 '11 at 09:35
  • What is the `find` for? – Galaxy Sep 20 '20 at 15:18
  • @Galaxy: The find is to find all the files that have a .cpp extension. This list will be input to gcc for compilation. It's not absolutely necessary. You could even do a $(CC) file1.cpp file2.cpp -c $(CPPFLAGS) if you want to statically list the files in the Makefile. – Chethan Ravindranath Sep 21 '20 at 03:38
0

Did you try using g++ to do the link? Those are C++ libraries and gcc doesn't pass the C++ libraries to the linker.

smparkes
  • 13,807
  • 4
  • 36
  • 61