Undefined references during linking when compiling with clang, but not with gcc

I’m working on quite a large c++ project, and I have the option to compile it either with clang (3.6) or gcc (5.1).

Now the project itself produces an executable, which uses quite a bit of shared libraries (which are built as part of the project).

Now when I compile with gcc, everything is fine and I get a working executable.
However, when I compile with clang, I get linking errors when linking the executable:

/home/{user}/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libSystem.so: undefined reference to `boost::program_options::arg'
/home/{user}/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libMysql.so: undefined reference to `mysqlpp::Query::str(mysqlpp::SQLQueryParms&)'
/home/{user}/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libTfc.so: undefined reference to `std::ios_base::failure::failure(char const*, std::error_code const&)'
/home/{user}/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libTfc.so: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'

The strange thing is that the libraries it references compile and link just fine, and all the required libraries that the linker mentions are configured for the linking stage in the executable (newlines added for readability):

"/usr/bin/ld" -export-dynamic -z relro --hash-style=gnu --hash-style=both --build-id --enable-new-dtags
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o /home/{user}/Projects/60ChannelSIP/bin/Clang/opt/swmi/bin/TetraNode
/usr/lib/crt1.o /usr/lib/crti.o /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/5.1.0/crtbegin.o
-L/home/{user}/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib -L/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/5.1.0
-L/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/5.1.0/../../.. -L/usr/local/bin/../lib -L/lib -L/usr/lib -ltcmalloc_minimal -rpath ../lib
-rpath /opt/swmi/lib /home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TmcOperationalMgrCmd.o
/home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TmcDispatchers.o /home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TmcApplication.o
/home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TmcExe.o /home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TestCommand.o
/home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TmcCommand.o /home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TetraNodeTestCmd.o
/home/{user}/Projects/60ChannelSIP/obj/Clang/TetraNode/TmcCopyProtection.o -lInterTnx -lUdpcp -lStatistics -lMysql -lHptl
-lUrlHandling -lTigTnx -lTigTsc -lTig -lTig2Tnx -lTig2Tsc -lTig2 -lNmsCommunications -lWebServerGoAhead -lTetraCapture -lTetraTnx
-lTetraNumberPlan -lTetraBs -lTetra -lTbsComm -lLrrp -lTelephoneTnx -lOmTccTnspV1V2 -lTelephoneTsc -lTelephone -lMptTnx -lMptNumberPlan
-lMptNumberPlanTsc -lMptTsc -lMpt -lE1TelephoneTsc -lE1Telephone -lE1MediaPro -lIsdn -lSipTelephone -lSipGateway -lRohill.Codec
-lConventionalTnx -lConventionalTsc -lConventional -lCommonCallProtocolTsc -lCommonCallProtocol -lAllCallProtocolsNumberPlan
-lResourceMgr -lCallMgr -lTransmissionMgr -lOperationalMgrTmc -lTca -lTnPnP -lSwTcc -lSwmi -lAcelpMixer -lNodeCapabilities
-lProtocolCapabilities -lTig2Mgr -lDatabase -lInternodeMgr -lOperationalMgrTcc -lCallLogger -lTccTnspV2 -lTnspV2 -lTnsp -lIPLinkTetra
-lIPLinkR855 -lIPLinkCore -lTndUtilities -lTfc -lNmea -lVersion -lTmw -lSystem -lRohill.Core -lRohill.SIP -lagent++ -lsnmp++ -lmysqlpp
-lmysqlclient -lrt -lncurses -lcrypt -lxml2 -lcurl -lz -lbz2 -lssl -lcrypto -ldl -luuid -lboost_signals -lboost_system
-lboost_filesystem -lboost_regex -lboost_thread -lboost_iostreams -lboost_program_options -lboost_chrono -lboost_date_time
-lTetraCapture -lTmw -ljansson -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/5.1.0/crtend.o /usr/lib/crtn.o

From what I can find is that all the libraries the linker is complaining about are later in the linker list than the libraries which it says have undefined references. Any ideas?


Source: gcc

Leave a Reply