Andersbakken / rtags

A client/server indexer for c/c++/objc[++] with integration for Emacs based on clang.
http://www.rtags.net
GNU General Public License v3.0
1.83k stars 252 forks source link

linker errors with 2.17: undefined symbols #1148

Open davydden opened 6 years ago

davydden commented 6 years ago

Please mark appropriate

Problem description

Linking fails on macOS High Sierra when building rtags from Spack package manager with llvm 4.0 build via Apple's clang 9.0.0.

Expected behavior

links

Actual behavior

     241   /Users/davydden/spack/lib/spack/env/clang/clang++   -I/Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/llvm-4.0.0-5pvwluskkrzla3swgvojhsdbjygyy3fz/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Wall -Wextra -Wpointer-arith -Wnon-virtual-dtor -Wformat -Wshadow -std=c++11 -stdlib=libc++ -Wstrict-aliasing=2 -Wcast-qual -fPIC -fstack-protector-all -Wstack-protector -O2 -g -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/rc.dir/rc.cpp.o  -o ../bin/rc -Wl,-rpath,/Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/llvm-4.0.0-5pvwluskkrzla3swgvojhsdbjygyy3fz/lib librtags.a /Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/llvm-4.0.0-5pvwluskkrzla3swgvojhsdbjygyy3fz/lib/libclang.dylib -lstdc++ -lpthread /Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/zlib-1.2.11-t74siw3tvuz3vfb3rje5mkbiwneuzfb5/lib/libz.dylib /Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/openssl-1.0.2k-u7nfvs3zafwtpadau4cuumzrxlylr2oc/lib/libcrypto.dylib -framework CoreServices -framework CoreFoundation
     242   ld: warning: ignoring file librtags.a, file was built for archive which is not the architecture being linked (x86_64): librtags.a
  >> 243   Undefined symbols for architecture x86_64:
     244     "RClient::exec()", referenced from:
     245         _main in rc.cpp.o
     246     "RClient::parse(unsigned long, char**)", referenced from:
     247         _main in rc.cpp.o
     248     "RClient::RClient()", referenced from:
     249         _main in rc.cpp.o
     250     "RClient::~RClient()", referenced from:
     251         _main in rc.cpp.o
     252   ld: symbol(s) not found for architecture x86_64
  >> 253   clang: error: linker command failed with exit code 1 (use -v to see invocation)
  >> 254   make[2]: *** [bin/rc] Error 1
  >> 255   make[1]: *** [src/CMakeFiles/rc.dir/all] Error 2

     259   /Users/davydden/spack/lib/spack/env/clang/clang++   -I/Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/llvm-4.0.0-5pvwluskkrzla3swgvojhsdbjygyy3fz/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Wall -Wextra -Wpointer-arith -Wnon-virtual-dtor -Wformat -Wshadow -std=c++11 -stdlib=libc++ -Wstrict-aliasing=2 -Wcast-qual -fPIC -fstack-protector-all -Wstack-protector -O2 -g -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/rp.dir/rp.cpp.o  -o ../bin/rp -Wl,-rpath,/Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/llvm-4.0.0-5pvwluskkrzla3swgvojhsdbjygyy3fz/lib librtags.a /Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/llvm-4.0.0-5pvwluskkrzla3swgvojhsdbjygyy3fz/lib/libclang.dylib -lstdc++ -lpthread /Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/zlib-1.2.11-t74siw3tvuz3vfb3rje5mkbiwneuzfb5/lib/libz.dylib /Users/davydden/spack/opt/spack/darwin-highsierra-x86_64/clang-9.0.0-apple/openssl-1.0.2k-u7nfvs3zafwtpadau4cuumzrxlylr2oc/lib/libcrypto.dylib -framework CoreServices -framework CoreFoundation
     260   ld: warning: ignoring file librtags.a, file was built for archive which is not the architecture being linked (x86_64): librtags.a
  >> 261   Undefined symbols for architecture x86_64:
     262     "initLogging(char const*, Flags<LogFlag>, LogLevel, Path const&, LogLevel)", referenced from:
     263         _main in rp.cpp.o
     264     "ClangIndexer::sServerOpts", referenced from:
     265         _main in rp.cpp.o
     266         sigHandler(int) in rp.cpp.o
     267     "ClangIndexer::exec(String const&)", referenced from:
     [ ... ]
     290         std::__1::__shared_ptr_emplace<EventLoop, std::__1::allocator<EventLoop> >::~__shared_ptr_emplace() in rp.cpp.o
     291         std::__1::__shared_ptr_emplace<EventLoop, std::__1::allocator<EventLoop> >::~__shared_ptr_emplace() in rp.cpp.o
     292         std::__1::__shared_ptr_emplace<EventLoop, std::__1::allocator<EventLoop> >::__on_zero_shared() in rp.cpp.o
     293     "Path::readAll(unsigned long) const", referenced from:
     294         _main in rp.cpp.o
     295   ld: symbol(s) not found for architecture x86_64

and a couple of others.

Environment

davydden commented 6 years ago

@Andersbakken ping.

Andersbakken commented 6 years ago

This looks very odd. Can you run this command on librtags.a

lipo -info ./src/librtags.a

Can you also try to blow away the whole build directory and rebuild? It seems like it's possible that different sources were compiled with different compilers or flags.

davydden commented 6 years ago

lipo -info ./src/librtags.a

$ lipo -info librtags.a
input file librtags.a is not a fat file
Non-fat file: librtags.a is architecture: x86_64

Can you also try to blow away the whole build directory and rebuild? It seems like it's possible that different sources were compiled with different compilers or flags.

Not in my case, i build with spack which makes sure that environment is clean and out-of-source build folder is freshly created.

p.s. i build with

'-DCMAKE_EXPORT_COMPILE_COMMANDS=1',
'-DRTAGS_NO_ELISP_FILES=1'

if that makes a difference.

davydden commented 6 years ago

here is configure/build log:

spack-build.out.zip

Andersbakken commented 6 years ago

Have you tried with the system clang?

I don't really see anything obviously wrong here. Clearly the linker somehow doesn't like the architecture even though it seems like it's x86_64 on both sides.

It sounds a little bit like this:

https://github.com/tpoechtrager/osxcross/issues/11

But the thing that seems to resolve that issue seems not be the case for you since you are using the ar from your clang build.

Anders

On Wed, Mar 14, 2018 at 3:06 PM, Denis Davydov notifications@github.com wrote:

here is configure/build log:

spack-build.out.zip https://github.com/Andersbakken/rtags/files/1813269/spack-build.out.zip

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Andersbakken/rtags/issues/1148#issuecomment-373190873, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEdSqegyM_Ol-_gigt5NMlKCe1GMCqtks5teZRbgaJpZM4Ry5qT .

davydden commented 6 years ago

Have you tried with the system clang?

it is system clang. It just goes through compiler wrappers which add a few things.