Linking issues with Clang 3.6.2

Hello,

I have a C++ project (quite extensive, lots of sub-projects that produce libraries used in the final executable) which I can compile just fine with gcc 5.1.0.

As an alternative, some preparations have been previously done to compile the project with clang (in this case 3.6.2), which we’d as a company like to transition to at some point.

However when compiling with clang, I get several undefined references when linking the final executable on some libraries in the project which I don’t get when compiling with gcc.

First let me explain my build environment, which is custom:

I have an openSUSE 11.3 OS due to backwards compatibility reasons

Originally, gcc 4.5 is installed (located in /usr/bin)

I compiled gcc 5.1 myself (using gcc 4.5, located in /usr/local/bin, $PATH has been modified to search here first)

I compiled clang 3.6.2 myself (using gcc 5.1, located in /usr/local/bin)

Several other libraries (including mysql++ & boost) are compiled with gcc (located in /usr/local/lib, headers in /usr/local/include)

Codelite 8.0, compiled with gcc 5.1

Now when doing a clean clang build of my project I get 4 undefind reference linking errors:

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libSystem.so: undefined reference to `boost::program_options::arg’

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libMysql.so: undefined reference to `mysqlpp::Query::str(mysqlpp::SQLQueryParms&)’

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libTfc.so: undefined reference to `std::ios_base::failure::failure(char const*, std::error_code const&)’

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libTfc.so: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()’

I am able to resolve the issues with boost & mysqlpp by recompiling these with clang, but after that, I get 2 more undefined references to std::ios_base::failure::failure:

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libboost_iostreams.so: undefined reference to `std::ios_base::failure::failure(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libboost_iostreams.so: undefined reference to `std::ios_base::failure::failure(char const*, std::error_code const&)’

/home/rohill/Projects/60ChannelSIP/bin/Clang/opt/swmi/lib/libTfc.so: undefined reference to `std::ios_base::failure::failure(char const*, std::error_code const&)’

But I don’t know if I want to do this, because I am no longer able to compile the project with gcc after this.

Furthermore, I find it rather strange that clang produces these linking issues in the first place, as it can compile and link those specific libraries just fine earlier in the build.

All external libraries used to compile & link the projects libraries are also configured for the linking of the final executable.

I am at a loss for an answer, but I suspect it having to do something with gcc 4.5 in some way, so I hope to get an answer via this.

Kind regards,

Roy Kleefman

image001.jpg
Rohill • Edisonstraat 12 • 7903 AN Hoogeveen • The Netherlands
Phone: +31-528-263355 • Fax: +31-528-271844 • www.rohill.com
Chamber of Commerce Meppel registration no. 09084362

This email, including any attached files, is confidential, may be legally privileged, and is solely for the intended recipient(s).
If you have received this email in error, please destroy it and notify Rohill immediately. Any unauthorized use, dissemination,
disclosure, copying or printing is strictly prohibited. Thank you.

John,

Thanks for the feedback. I’ve executed the compiling as well as the linking with –v, but I can’t find anything particular with it (I removed all project include directories, i.e. -I , & library usage, i.e. -l< workspace-libraries>, from both commands, this saves quite a bit of screen real-estate):

“/usr/local/bin/clang-3.6” -cc1 -triple i386-pc-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -main-file-name TmcExe.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array

-target-cpu pentium4 -momit-leaf-frame-pointer –v -dwarf-column-info -coverage-file/home/rohill/Projects/60ChannelSIP/obj/Clang//TmcExe.o -resource-dir /usr/local/bin/…/lib/clang/3.6.2 -dependency-file

/home/rohill/Projects/60ChannelSIP/obj/Clang//TmcExe.d –MT /home/rohill/Projects/60ChannelSIP/obj/Clang//TmcExe.o -D BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS -D SYSTEM_USE_DEFAULT_DISPATCHER=0 -D WEBS -D UEMF

-D GOAHEAD_LINUX -D USER_MANAGEMENT_SUPPORT -D DIGEST_ACCESS_SUPPORT -D _NO_LOGGING -D HEADER_DES_LOCL_H -D _USE_OPENSSL -I -internal-isystem /usr/local/bin/…/lib/gcc/i686-pc-linux-gnu/5.1.0/…/…/…/…/include/c++/5.1.0

-internal-isystem /usr/local/bin/…/lib/gcc/i686-pc-linux-gnu/5.1.0/…/…/…/…/include/c++/5.1.0/i686-pc-linux-gnu -internal-isystem /usr/local/bin/…/lib/gcc/i686-pc-linux-gnu/5.1.0/…/…/…/…/include/c++/5.1.0/backward -internal-isystem /usr/local/include -internal-isystem

/usr/local/bin/…/lib/clang/3.6.2/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -Werror -Wnon-virtual-dtor -Wno-overloaded-virtual -Wno-missing-braces -Wno-uninitialized -std=c++1y -fdeprecated-macro -fdebug-compilation-dir

/home/rohill/Projects/60ChannelSIP/Tmc -ferror-limit 19 -fmessage-length 0 -pthread -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp

-o /home/rohill/Projects/60ChannelSIP/obj/Clang//TmcExe.o -x c++ /home/rohill/Projects/60ChannelSIP/Tmc/Source/TmcExe.cpp

“/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/rohill/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/rohill/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 -l -lboost_signals -lboost_system -lboost_filesystem -lboost_regex -lboost_thread -lboost_iostreams -lboost_program_options -lboost_chrono -lagent++ -lsnmp++ -lmysqlpp -lmysqlclient -lrt -lncurses -lcrypt -lxml2

-lcurl -lz -lbz2 -lssl -lcrypto -ldl -luuid -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

ldconfig shows that it looks to /usr/local/lib for libstdc++

ldconfig -p | grep libstdc++

libstdc++.so.6 (libc6) => /usr/local/lib/libstdc++.so.6

libstdc++.so.6 (libc6) => /usr/lib/libstdc++.so.6

libstdc++.so (libc6) => /usr/local/lib/libstdc++.so

So from what I can tell is it’s looking for include files regarding gcc in the gcc 5.1 directories, and it’s trying to link with stdc++ (marked in bold), which should be the one from /usr/local/lib.

The directories it should search in specify -L/usr/local/bin/…/lib before -L/lib & -L/usr/lib (though I can’t tell which takes precedence over which).

As for your other suggestion, I don’t see what benefit the boost predef library has. Can you explain a bit more about this?

Kind regards,

image001.jpg