I'm trying to adapt an existing scons build system to use clang++ instead of g++. When using -O0 or -O2 -- neither of which output llvm IR -- things work swimmingly, that is to say, the build complete without errors. When using -O4, which compiles to llvm bytecode to allow link-time-optimization, the build fails on the final link.
I've searched various places, but I am unclear on exactly how to fix this, either directly on the command line or, knowing that in my SConstruct file.
Note: Setting env['LINK'] = "/path/to/llvm-link" causes all of my dependency checks to fail.
Note: Adding -Xlinker "-plugin" -Xlinker "/usr/lib/LLVMgold.so" to the command works well. So, the question is how to add this conditioned upon the choice of clang in SConstruct.
$ /usr/sbin/distcc clang++ -o build/release/filex.o -c -std=c++11 -march=core-avx-i -W -Wall -O4 \
-DHAVE_LLVM=0x0303 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS \
-D__STDC_LIMIT_MACROS -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_CONFIG_H -D_X11 \
-DFIFODIR='"/var/run/dir"' -I. -Isrc -I/usr/include -I/usr/include/SDL src/filex.cpp
...
$ ar rc build/release/libfile2.a build/release/filea.o build/release/tools/fileb.o
$ ranlib build/release/libfile2.a
...
$ /usr/sbin/distcc clang++ -o mybinary -pthread build/release/file1.o \
build/release/libfile2.a ... -L/usr/lib -lLLVMBitWriter -lLLVMX86Disassembler \
-lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser \
-lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMJIT \
-lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts \
-lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC \
-lLLVMObject -lLLVMCore -lLLVMSupport -lz -lffi -ldl -lm -lboost_iostreams -lSDL \
-lSDL_net -lpthread -lboost_system -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 \
-lcairo -lfontconfig -lfreetype -lboost_program_options -lboost_regex -lSDL_ttf \
-lSDL_mixer -lvorbisfile -lSDL_image -lX11
/usr/sbin/ld.gold: error: build/release/file1.o:1:3: invalid character
/usr/sbin/ld.gold: error: build/release/file1.o:1:3: syntax error, unexpected $end
/usr/sbin/ld.gold: error: build/release/flie1.o: not an object or archive
The key is to append -Wl,-plugin,/path/to/LLVMgold.so to LINKFLAGS rather than the -Xlinker... syntax.
Related
I am trying to build the amanda program on ubuntu.
I'm faced with the following error from makefile:
libtool: link: ( cd ".libs" && rm -f "libamserver.la" && ln -s "../libamserver.la" "libamserver.la" )
/bin/bash ../libtool --tag=CC --mode=link gcc -Wall -Wextra -Wparentheses -Wdeclaration-after-statement -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wformat -Wformat-security -Wsign-compare -Wfloat-equal -Wold-style-definition -Wno-strict-aliasing -Wno-unknown-pragmas -Wno-deprecated-declarations -DAMANDA_FILE=\"`basename amindexd.o`\" -g -O2 -fno-strict-aliasing -o amindexd amindexd.o disk_history.o list_dir.o ../common-src/libamanda.la libamserver.la ../device-src/libamdevice.la ../common-src/libamanda.la ../amandad-src/libamandad.la -lm -Wl,--export-dynamic -lgmodule-2.0 -pthread -lgobject-2.0 -lgthread-2.0 -pthread -lglib-2.0 -lnsl -lresolv
libtool: link: gcc -Wall -Wextra -Wparentheses -Wdeclaration-after-statement -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wformat -Wformat-security -Wsign-compare -Wfloat-equal -Wold-style-definition -Wno-strict-aliasing -Wno-unknown-pragmas -Wno-deprecated-declarations -DAMANDA_FILE=\"amindexd.o\" -g -O2 -fno-strict-aliasing -o .libs/amindexd amindexd.o disk_history.o list_dir.o -Wl,--export-dynamic -pthread -pthread ./.libs/libamserver.so /src/amanda-3.3.1/device-src/.libs/libamdevice.so ../device-src/.libs/libamdevice.so /src/amanda-3.3.1/xfer-src/.libs/libamxfer.so /src/amanda-3.3.1/ndmp-src/.libs/libndmlib.so ../common-src/.libs/libamanda.so ../amandad-src/.libs/libamandad.so /src/amanda-3.3.1/common-src/.libs/libamanda.so -lm -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -lnsl -lresolv -pthread -Wl,-rpath -Wl,/usr/local/lib/amanda
/usr/bin/ld: /src/amanda-3.3.1/device-src/.libs/libamdevice.so: undefined reference to `dlopen'
/usr/bin/ld: /src/amanda-3.3.1/device-src/.libs/libamdevice.so: undefined reference to `dlerror'
/usr/bin/ld: /src/amanda-3.3.1/device-src/.libs/libamdevice.so: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
From the error message it seems that libtool is not able to link to ldl.
So I manually added "-ldl" to the provided Makefile.
LIBS = -lm -Wl,--export-dynamic -lgmodule-2.0 -pthread -lgobject-2.0 -lgthread-2.0 -pthread -lglib-2.0 -lnsl -lresolv -ldl
However, Makefile keeps making the exact same error whenever I try to build.
Can anyone suggest a solution?
Thanks.
I am working on a project where I am using boost::interprocess to create shared memory, when I compile the code in isolation and create a client it works fine:
Makefile for building .a :
$(info ETLIB_ROOT=$(ETLIB_ROOT) )
include $(ETLIB_ROOT)/.gmake_prologue
$(info BOOST_ROOT=$(BOOST_ROOT))
$(info BOOST_INC=$(BOOST_INC))
OBJDIR=obj
SRC=src
INCLUDE=include
LIB=lib
$(LIB)/libmetricsStore.a: $(OBJDIR)/MetricsStore.o
ar rcs $# $^
$(OBJDIR)/MetricsStore.o: $(SRC)/MetricsStore.cpp
g++ -g -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I$(INCLUDE) -c $(SRC)/MetricsStore.cpp -o $(OBJDIR)/MetricsStore.o
include $(ETLIB_ROOT)/.gmake_epilogue
Makefile for the test client:
include .gmake_prologue
OBJDIR=.
SRC=.
INCLUDE=../metricsstore/include
$(info BOOST_LIB=$(BOOST_LIB))
$(info BOOST_INC=$(BOOST_INC))
client: $(OBJDIR)/client.o
g++ $(OBJDIR)/client.o -o client -L$(BOOST_LIB) -lboost_filesystem-gcc44 -lboost_filesystem-gcc44-mt -L/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/boost_shared_mem/metricsstore/lib -lmetricsStore -lrt
$(OBJDIR)/client.o: $(SRC)/client.cpp
g++ -I$(BOOST_INC) -I $(INCLUDE) -c $(SRC)/client.cpp -o $(OBJDIR)/client.o
include .gmake_epilogue
The above two work fine and the test client gets built properly.
The gmake -n output of the test client is the following:
LIBDIR=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB
LIBDIR in prolouge=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB
BOOST_ROOT in prolouge=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53
BOOST_INC in prolouge=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include
CCFLAGS in prolouge=-g -mfpmath=sse -msse3 -I. -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include
BOOST_LIB=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/lib
BOOST_INC=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include
g++ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I ../metricsstore/include -c ./client.cpp -o ./client.o
g++ ./client.o -o client -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/lib -lboost_filesystem-gcc44 -lboost_filesystem-gcc44-mt -L/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/boost_shared_mem/metricsstore/lib -lmetricsStore -lrt
However, when I try the same options with another existing project I get errors like following which I am not able to understand and fix:
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/os_file_functions.hpp: In function 'bool boost::interprocess::ipcdetail::open_or_create_directory(const char*)':
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/os_file_functions.hpp:681: error: expected unqualified-id before 'do'
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/os_file_functions.hpp:682: error: 'info' was not declared in this scope
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/tmp_dir_helpers.hpp: In function 'void boost::interprocess::ipcdetail::create_tmp_and_clean_old(std::string&)':
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/tmp_dir_helpers.hpp:135: error: expected unqualified-id before 'do'
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/tmp_dir_helpers.hpp:136: error: 'info' was not declared in this scope
I have read the following link and tried different things but to no avail:
http://www.drdobbs.com/tools/debugging-makefiles/197003338
The Makefile of the new project looks like the following:
include .gmake_prologue
INCS += \
-I$(EXTLIB_ROOT)/one_market_data/one_tick/linux/include \
-I$(EXTLIB_ROOT)/Linux-glibc-2.3-x86_64/include \
-I$(EXTLIB_ROOT)/pico \
-I$(EXTLIB_ROOT)/proto \
-I$(EXTLIB_ROOT)/google \
-I$(BOOST_INC) \
-I$(ETLIB_ROOT)/boost_shared_mem/metricsstore/include \
$(JMS_INCS)
ETLIBS = \
$(ETLIB_ROOT)/Util/libUtil.a \
$(ETLIB_ROOT)/FIXLib/src/libFIXLib.a
LIBS = \
$(ETLIBS) \
$(JMS_LIBS_DYNAMIC) \
-L$(EXTLIB_ROOT)/one_market_data/one_tick/linux/lib -lonetick \
-L$(EXTLIB_ROOT)/proto/lib -lprotobuf \
-L$(EXTLIB_ROOT)/poco-1.4.3p1/lib/Linux/x86_64 -lPocoFoundation -lPocoNet \
-L$(BOOST_LIB) -lboost_filesystem-gcc44 \
-L$(BOOST_LIB) -lboost_filesystem-gcc44-mt \
-L$(ETLIB_ROOT)/boost_shared_mem/metricsstore/lib -lmetricsStore \
-dynamic -lnsl -lm -ldl -lpthread -lrt
OBJS1 = \
ConfigReader.o \
proto/common/pricedistribution.pb.o \
proto/fxecn/fxvenue.pb.o \
AppBase.o \
SocketFeedPublisher.o
Here is the gmake -n output of the above Makefile:
BOOST_ROOT in prolouge=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53
BOOST_INC in prolouge=/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include
CCFLAGS in prolouge=-g -mfpmath=sse -msse3 -I. -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include
/usr/bin/c++ -pthread -fexceptions -DOS_LINUX -D_GNU_SOURCE -D_THREAD_SAFE -DBYTE_ORDER_LSB -DINBUILT_NEW -DSFC_REPLACES_TIBAPI -g -mfpmath=sse -msse3 -I. -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/one_market_data/one_tick/linux/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/Linux-glibc-2.3-x86_64/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/pico -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/proto -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/google -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/boost_shared_mem/metricsstore/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/rdgLib -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/EMS_CPP_WRAPPER/ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/EMS_CLIENT_API/lincsg2-gcc3.0/4_4_1/EMS_CLIENT_API/ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/EMS_CPP_WRAPPER//../Source/code -DJMS_IO -DRDG_BUILD -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ATHENA_EMS/LCD -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ATHENA_EMS/e4jms/Linux/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/JMSTools -c -o SocketFeedPublisher.o SocketFeedPublisher.cpp
/usr/bin/c++ -pthread -fexceptions -DOS_LINUX -D_GNU_SOURCE -D_THREAD_SAFE -DBYTE_ORDER_LSB -DINBUILT_NEW -DSFC_REPLACES_TIBAPI -g -g -mfpmath=sse -msse3 -I. -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/one_market_data/one_tick/linux/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/Linux-glibc-2.3-x86_64/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/pico -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/proto -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/google -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/boost_shared_mem/metricsstore/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/rdgLib -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/EMS_CPP_WRAPPER/ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/EMS_CLIENT_API/lincsg2-gcc3.0/4_4_1/EMS_CLIENT_API/ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/EMS_CPP_WRAPPER//../Source/code -DJMS_IO -DRDG_BUILD -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ATHENA_EMS/LCD -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ATHENA_EMS/e4jms/Linux/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/JMSTools -o SocketFeedPublisher ConfigReader.o AppBase.o SocketFeedPublisher.o /app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/Util/libUtil.a /app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/FIXLib/src/libFIXLib.a -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/EMS_CLIENT_API/lincsg2-gcc3.0/4_4_1/lib/64 -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/EMS_CLIENT_API/lincsg2-gcc3.0/4_4_1/lib -ltibems64 -lssl -lcrypto -lz -lxml2 -ltibjms64 -ltibemslookup64 -lldap -llber -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/lib/ -lemscppwrapper64_2.2 -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/one_market_data/one_tick/linux/lib -lonetick -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/proto/lib -lprotobuf -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/poco-1.4.3p1/lib/Linux/x86_64 -lPocoFoundation -lPocoNet -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/lib -lboost_filesystem-gcc44 -L/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/lib -lboost_filesystem-gcc44-mt -L/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/boost_shared_mem/metricsstore/lib -lmetricsStore -dynamic -lnsl -lm -ldl -lpthread -lrt
Linux machine details:
Linux usl20037465 2.6.18-308.8.1.el5 #1 SMP Fri May 4 16:43:02 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
Boost version used 1.53
I have tried all that I could, but could not solve the problem can someone please help me understand how would I debug this.
EDIT
Block that throws the error:
/usr/bin/c++ -pthread -fexceptions -DOS_LINUX -D_GNU_SOURCE -D_THREAD_SAFE -DBYTE_ORDER_LSB -DINBUILT_NEW -DSFC_REPLACES_TIBAPI -g -mfpmath=sse -msse3 -I. -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/one_market_data/one_tick/linux/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/Linux-glibc-2.3-x86_64/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/pico -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/proto -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/google -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/boost_shared_mem/metricsstore/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/rdgLib -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/EMS_CPP_WRAPPER/ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/EMS_CLIENT_API/lincsg2-gcc3.0/4_4_1/EMS_CLIENT_API/ -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ems_cpp_wrapper/lincsg2-gcc3.0/2_2_0/EMS_CPP_WRAPPER//../Source/code -DJMS_IO -DRDG_BUILD -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ATHENA_EMS/LCD -I/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/ATHENA_EMS/e4jms/Linux/include -I/app/th/pkgs/omd/rates/development.deb/3.9.7/ETLIB/JMSTools -c -o SocketFeedPublisher.o SocketFeedPublisher.cpp
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/os_file_functions.hpp: In function 'bool boost::interprocess::ipcdetail::open_or_create_directory(const char*)':
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/os_file_functions.hpp:681: error: expected unqualified-id before 'do'
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/os_file_functions.hpp:682: error: 'info' was not declared in this scope
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/tmp_dir_helpers.hpp: In function 'void boost::interprocess::ipcdetail::create_tmp_and_clean_old(std::string&)':
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/tmp_dir_helpers.hpp:135: error: expected unqualified-id before 'do'
/app/th/pkgs/omd/rates/development.deb/3.9.7/EXTLIB/boost_1_53/include/boost/interprocess/detail/tmp_dir_helpers.hpp:136: error: 'info' was not declared in this scope
gmake: *** [SocketFeedPublisher.o] Error 1
Thanks and Regards,
-Deb
I'm doing the kaleidoscope tutorial. I'm on step two.
https://github.com/westymatt/creole
But I get this error when building with clang++
clang++ -Wno-c++11-extensions -g -std=c++11 -I/usr/local/Cellar/llvm/3.6.1/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS src/lexer.cc src/parser.cc -L/usr/local/Cellar/llvm/3.6.1/lib/ -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMProfileData -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMX86Desc -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMMC -lLLVMX86Utils -lLLVMCore -lLLVMSupport -lc++ -O0 -o creole
Undefined symbols for architecture x86_64:
"std::terminate()", referenced from:
___clang_call_terminate in lexer-608bbc.o
___clang_call_terminate in parser-09b617.o
ld: symbol(s) not found for architecture x86_64
std::terminate is located inside libc++ on OSX (which I assume you're using because of the "Cellar" in your path there). You appear to be explicitly linking against libc++ which means that the ordering is likely going wrong on your link line.
I can't duplicate this using the actual tutorial sources from top of tree (I don't have 3.6.1 checked out), but I'd suggest you follow the example Makefiles in there. The link line for a given part of the tutorial looks like:
clang++ -Wl,-dead_strip -rdynamic -Wl,-rpath -Wl,#executable_path/../lib -L/Users/echristo/builds/build-llvm/Debug+Asserts/lib -L/Users/echristo/builds/build-llvm/Debug+Asserts/lib -m64 -o /Users/echristo/builds/build-llvm/Debug+Asserts/examples/Kaleidoscope-Ch4 /Users/echristo/builds/build-llvm/examples/Kaleidoscope/Chapter4/Debug+Asserts/toy.o \
-lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMProfileData -lLLVMInstCombine -lLLVMInstrumentation -lLLVMTransformUtils -lLLVMipa -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lz -lpthread -ledit -lcurses -lm
which should give you an idea of what it'll look like.
From looking at your sources on github it looks like you've gone to a "include the output of llvm-config on the command line" which isn't very reliable as components may change, etc.
clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy
from the tutorial should be enough to compile your simple example. Just replace toy.cpp with both of your example files since you split it up.
I got this error, while I was linking my code with my static lib built with ARC but there were some Objective C file with .mm extension. When I rename them with .m, worked fine.
According to this you need to make sure your implementations for your functions all have corresponding declarations.
I have created an some classes I want to use with swig in order to generate ruby binding.
Everything is ok when I generate the code or compile the ruby module. But when a script load this module, there is an error:
undefined symbol: _ZTVN5clang5LexerE
I understand that this means that the problem is for the clang::Lexer. But I know I have
set the lclangLex lib for this.
here is the command I use in order to link the objects files:
clang++ -shared -o parser.so parser.o Declarations.o -L. -L/usr/lib -L. -Wl,-O1,\
--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic \
-L/usr/lib -lz -lpthread -lffi -lcurses -ldl -lm -lruby -lclangLex -lclangAST \
-lpthread -lgmp -ldl -lcrypt -lm -lc -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo \
-lLLVMTarget -lLLVMCore -lLLVMMC -lLLVMObject -lLLVMSupport
any idea ?
The problem was the order of the libs given to the linker:
-lclangAST -lclangLex -lclangBasic
lclangAST must be given before lclangLex then I just had to add lclangBasic and everything works.
I've been working on a small tool with clang/llvm but I haven't been able to successfully get g++ and gnu's linker to properly link my code against clang.
my linker is generating the following errors:
undefined reference to `clang::FileManager::~FileManager()'
undefined reference to `clang::FileManager::FileManager()'
undefined reference to `llvm::sys::getHostTriple()'
undefined reference to `clang::Diagnostic::Diagnostic(clang::DiagnosticClient*)'
undefined reference to `llvm::outs()'
undefined reference to `clang::TargetInfo::CreateTargetInfo(clang::Diagnostic&, clang::TargetOptions&)'
undefined reference to `clang::SourceManager::getOrCreateContentCache(clang::FileEntry const*)'
undefined reference to `clang::SourceManager::createFileID(clang::SrcMgr::ContentCache const*, clang::SourceLocation, clang::SrcMgr::CharacteristicKind, unsigned int, unsigned int)'
my compile commands looks like this:
g++ -g -fno-rtti -I~/llvm-2.8/tools/clang-2.8/include \
-I~/llvm-2.8/llvm/include \
`~/bin/llvm-config --cxxflags` \
-c Frontend.cpp
g++ -g -fno-rtti -I~/llvm-2.8/tools/clang-2.8/include \
-I~/llvm-2.8/llvm/include \
`~/bin/llvm-config --cxxflags` \
-c exec.cpp
g++ -I~/llvm-2.8/tools/clang-2.8/include \
-I~/llvm-2.8/llvm/include -L~/opt/lib/ \
-g -fno-rtti -lclangDriver -lclangAnalysis \
-lclangFrontend -lclangSema -lclangAST -lclangParse \
-lclangLex -lclangBasic \
`~/bin/llvm-config --cxxflags --ldflags --libs` \
Frontend.o exec.o -o run
any tips or advice would be welcomed.
cheers,
ct
PS: I've been exploring some of the information on this page:
http://ubuntuforums.org/showthread.php?t=532693
and it might do the trick, will post a comment on that tip when I can.
Solution
using clang code from this tutorial (which had to be modified to remove the references to FileSystemOptions b/c clang/Basic/FileSystemOptions.h doesn't exist in clang-2.8): http://clangtutorial.codeplex.com/
g++ tutorial1.cpp -g -fno-rtti -lclangFrontend -lclangDriver \
-lclangCodeGen -lclangSema -lclangChecker -lclangAnalysis \
-lclangRewrite -lclangAST -lclangParse -lclangLex -lclangBasic \
-lLLVMSupport -lLLVMSystem -I~/opt/include/ \
`llvm-config --cxxflags --ldflags --libs all`
seemed to do the trick!
When I've built some stuff against llvm / clang, this is what I've used to build it. Perhaps you can compare the two build lines.
Also, the llvm-config command I've used has been: llvm-config --cxxflags --ldflags --libs backend.
Finally, this is likely partially related to an ordering issue. You probably want to include the libraries for llvm before you include the clang libraries.
/usr/bin/g++ \
-fno-exceptions -fno-rtti -fno-common \
-I/Users/wlynch/Homebrew/include \
-DNDEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS \
../src/main.cpp -c -o src/main.cpp.0.o
/usr/bin/g++
src/main.cpp.0.o -o /Users/wlynch/Dropbox/Clang/Indexer/build/main \
-L/Users/wlynch/Homebrew/lib -L/Users/wlynch/Homebrew/lib \
-lpthread -lm \
-lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG \
-lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine \
-lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore \
-lLLVMX86AsmPrinter -lLLVMMC -lLLVMX86Info -lLLVMSupport -lLLVMSystem \
-lclangAST -lclangAnalysis -lclangBasic -lclangChecker -lclangCodeGen \
-lclangDriver -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex \
-lclangParse -lclangRewrite -lclangSema -lclangSerialization
I assume you have back quotes around ~/bin/llvm-config, right?
That being said, move the -l options and the
`~/bin/llvm-config --cxxflags --ldflags --libs`
after the .o files on the command line. Stuff won't be taken out of the libraries unless referenced by a preceding object file.