Greg Stark
2015-Apr-01 15:19 UTC
[LLVMdev] Dynamic linking (dlopen/dlsym) against LLVM from a C program
I'm trying to write a .so which will be loaded using dlopen and called using dlopen. The application is written in C and I want to use the LLVM C API jfrom it. Obviously it will end up calling C++ functions internally but as long as I expose a C API to the application I should be ok. I have a code that compiles fine but when I try to call it from the application dlopen complains about missing C++ symbols. It seems for some reason the LLVM shared libraries aren't being added to the ELF NEEDED lines even though other shared libraries are. I switched --as-needed to --no-as-needed but it hasn't helped. The link line I'm using is: clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -g -O0 -fpic -I/usr/lib/llvm-3.5/include -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -O2 -fomit-frame-pointer -fPIC -Wno-ignored-attributes -shared -o pgjit.so pgjit.o -L/usr/local/pgsql/lib -Wl,--no-as-needed -Wl,-rpath,'/usr/local/pgsql/lib',-rpath,'/usr/lib/llvm-3.5/lib',--enable-new-dtags -I/usr/lib/llvm-3.5/include -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -O2 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fPIC -Woverloaded-virtual -ffunction-sections -fdata-sections -Wcast-qual -L/usr/lib/llvm-3.5/lib -lLLVMBitWriter -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter -lLLVMJIT -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMExecutionEngine -lLLVMMC -lLLVMCore -lLLVMSupport -lz -lpthread -lffi -ledit -ltinfo -ldl -lm -lm And the error I'm getting from dlopen is ERROR: could not load library "/home/stark/src/pgjit/pgjit.so": /home/stark/src/pgjit/pgjit.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE The NEEDED lines list all the non-llvm libraries but none of the llvm libraries: Dynamic Section: NEEDED libz.so.1 NEEDED libpthread.so.0 NEEDED libffi.so.6 NEEDED libedit.so.2 NEEDED libtinfo.so.5 NEEDED libdl.so.2 NEEDED libm.so.6 NEEDED libgcc_s.so.1 NEEDED libc.so.6 RUNPATH /usr/local/pgsql/lib:/usr/lib/llvm-3.5/lib What am I doing wrong here? -- greg