Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake-specific build failure on Solaris #19

Open
PHHargrove opened this issue May 16, 2016 · 6 comments
Open

cmake-specific build failure on Solaris #19

PHHargrove opened this issue May 16, 2016 · 6 comments

Comments

@PHHargrove
Copy link

I am able to build on Solaris-11.3/amd64 only if I use configure instead of cmake (and if I disable building the unittests as mentioned in #17).

The problem seen when using cmake is that linking shared library libLTO.so is failing with a large number of undefined symbols in the std:: namespace.

When using configure, the (successful) link of this library is performed as follows:

llvm[2]: Linking Release+Asserts Shared Library libLTO.so
g++ -m32  -O3 -Wl,-R -Wl,'$ORIGIN' -rdynamic -L/export/home/phargrov/upcnightly-32/llvm-upc/bld/Release+Asserts/lib -L/export/home/phargrov/upcnightly-32/llvm-upc/bld/Release+Asserts/lib    -shared -o /export/home/phargrov/upcnightly-32/llvm-upc/bld/Release+Asserts/lib/libLTO.so /export/home/phargrov/upcnightly-32/llvm-upc/bld/tools/lto/Release+Asserts/LTODisassembler.o /export/home/phargrov/upcnightly-32/llvm-upc/bld/tools/lto/Release+Asserts/lto.o \
   -lLLVMLTO -lLLVMObjCARCOpts -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMX86Desc -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMMC -lLLVMX86Utils -lLLVMCore -lLLVMSupport -lz -lpthread -lmalloc -ledit -lncurses -lm

However, when using cmake the same link is attempted using gcc (which explains why the standard C++ library is missing):

Linking CXX shared library ../../lib/libLTO.so
cd /export/home/phargrov/upcnightly-32/llvm-upc/bld/tools/lto && /shared/cmake-2.8.12.2/bin/cmake -E cmake_link_script CMakeFiles/LTO.dir/link.txt --verbose=1
/usr/bin/gcc  -fPIC   -Wl,-M,/export/home/phargrov/upcnightly-32/llvm-upc/bld/tools/lto/LTO.exports   -Wl,-z,defs -shared  -Wl,-hlibLTO.so -o ../../lib/libLTO.so CMakeFiles/LTO.dir/LTODisassembler.cpp.o CMakeFiles/LTO.dir/lto.cpp.o ../../lib/libLLVMX86CodeGen.a ../../lib/libLLVMX86AsmPrinter.a ../../lib/libLLVMX86AsmParser.a ../../lib/libLLVMX86Desc.a ../../lib/libLLVMX86Info.a ../../lib/libLLVMX86Disassembler.a ../../lib/libLLVMCore.a ../../lib/libLLVMLTO.a ../../lib/libLLVMMC.a ../../lib/libLLVMMCDisassembler.a ../../lib/libLLVMSupport.a ../../lib/libLLVMTarget.a ../../lib/libLLVMAsmPrinter.a ../../lib/libLLVMSelectionDAG.a ../../lib/libLLVMX86AsmPrinter.a ../../lib/libLLVMX86Utils.a ../../lib/libLLVMX86Info.a ../../lib/libLLVMCodeGen.a ../../lib/libLLVMTarget.a ../../lib/libLLVMInstrumentation.a ../../lib/libLLVMBitWriter.a ../../lib/libLLVMObjCARCOpts.a ../../lib/libLLVMipo.a ../../lib/libLLVMLinker.a ../../lib/libLLVMScalarOpts.a ../../lib/libLLVMInstCombine.a ../../lib/libLLVMIRReader.a ../../lib/libLLVMAsmParser.a ../../lib/libLLVMProfileData.a ../../lib/libLLVMObject.a ../../lib/libLLVMMCParser.a ../../lib/libLLVMMC.a ../../lib/libLLVMBitReader.a ../../lib/libLLVMVectorize.a ../../lib/libLLVMTransformUtils.a ../../lib/libLLVMAnalysis.a ../../lib/libLLVMCore.a ../../lib/libLLVMSupport.a -lrt -ldl -lcurses -lpthread -lz -lm -Wl,-R"\$ORIGIN/../lib"
Undefined                       first referenced
 symbol                             in file
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned int) const ../../lib/libLLVMAsmPrinter.a(WinCodeViewLineTables.cpp.o)
[... many more undefined std:: symbols ...]
@swatanabe
Copy link

AMDG

On 05/16/2016 01:42 PM, Paul H. Hargrove wrote:

I am able to build on Solaris-11.3/amd64 only if I use configure instead of cmake (and if I disable building the unittests as mentioned in #17).

The problem seen when using cmake is that linking shared library libLTO.so is failing with a large number of undefined symbols in the std:: namespace.

  1. Check that CMAKE_CXX_COMPILER is g++ not gcc.
  2. Check CMAKE_CXX_CREATE_SHARED_LIBRARY, which
    should be defined in terms of CMAKE_CXX_COMPILER.
    (The default definition is in
    /usr/share/cmake/Modules/CMakeCXXInformation.cmake)
Linking CXX shared library ../../lib/libLTO.so cd /export/home/phargrov/upcnightly-32/llvm-upc/bld/tools/lto && /shared/cmake-2.8.12.2/bin/cmake -E cmake_link_script CMakeFiles/LTO.dir/link.txt --verbose=1 /usr/bin/gcc -fPIC -Wl,-M,/export/home/phargrov/upcnightly-32/llvm-upc/bld/tools/lto/LTO.exports -Wl,-z,defs -shared -Wl,-hlibLTO.so -o ../../lib/libLTO.so CMakeFiles/LTO.dir/LTODisassembler.cpp.o CMakeFiles/LTO.dir/lto.cpp.o ../../lib/libLLVMX86CodeGen.a ../../lib/libLLVMX86AsmPrinter.a ../../lib/libLLVMX86AsmParser.a ../../lib/libLLVMX86Desc.a ../../lib/libLLVMX86Info.a ../../lib/libLLVMX86Disassembler.a ../../lib/libLLVMCore.a ../../lib/libLLVMLTO.a ../../lib/libLLVMMC.a ../../lib/libLLVMMCDisassembler.a ../../lib/libLLVMSupport.a ../../lib/libLLVMTarget.a ../../lib/libLLVMAsmPrinter.a ../../lib/libLLVMSelectionDAG.a ../../lib/libLLVMX86AsmPrinter.a ../../lib/libLLVMX86Utils.a ../../lib/libLLVMX86Info.a ../../lib/libLLVMCodeGen.a ../../lib/libLLVMTarget.a ../../lib/libLLVMInstrumentation.a ../../lib/libLLVMBitWriter.a ../../lib/libLLVMObjCARCOpts.a ../../lib/libLLVMipo.a ../../lib/libLLVMLinker.a ../../lib/libLLVMScalarOpts.a ../../lib/libLLVMInstCombine.a ../../lib/ libLLVMI RReader.a ../../lib/libLLVMAsmParser.a ../../lib/libLLVMProfileData.a ../../lib/libLLVMObject.a ../../lib/libLLVMMCParser.a ../../lib/libLLVMMC.a ../../lib/libLLVMBitReader.a ../../lib/libLLVMVectorize.a ../../lib/libLLVMTransformUtils.a ../../lib/libLLVMAnalysis.a ../../lib/libLLVMCore.a ../../lib/libLLVMSupport.a -lrt -ldl -lcurses -lpthread -lz -lm -Wl,-R"\$ORIGIN/../lib" Undefined first referenced symbol in file std::basic_string, std::allocator >::rfind(char, unsigned int) const ../../lib/libLLVMAsmPrinter.a(WinCodeViewLineTables.cpp.o) [... many more undefined std:: symbols ...]

In Christ,
Steven Watanabe

@PHHargrove
Copy link
Author

  1. Check that CMAKE_CXX_COMPILER is g++ not gcc.

If if was then I imagine all the .cpp source files would have failed to compile
The value is /usr/bin/c++, which is a symlink:

$ ls -l /usr/bin/[cg]++
lrwxrwxrwx   1 root     root          18 Sep 16  2015 /usr/bin/c++ -> ../gcc/4.8/bin/c++
lrwxrwxrwx   1 root     root          18 Sep 16  2015 /usr/bin/g++ -> ../gcc/4.8/bin/g++
  1. Check CMAKE_CXX_CREATE_SHARED_LIBRARY, which
    should be defined in terms of CMAKE_CXX_COMPILER.
    (The default definition is in
    /usr/share/cmake/Modules/CMakeCXXInformation.cmake)

Recursive grep shows there is no definition in the source our build directories.
Default defn:

if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
  set(CMAKE_CXX_CREATE_SHARED_LIBRARY
      "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()

@swatanabe
Copy link

AMDG

On 05/16/2016 02:27 PM, Paul H. Hargrove wrote:

  1. Check that CMAKE_CXX_COMPILER is g++ not gcc.

If if was then I imagine all the .cpp source files would have failed to compile

Maybe. I thought that gcc compiles .cpp with the C++ compiler.

  1. Check CMAKE_CXX_CREATE_SHARED_LIBRARY, which
    should be defined in terms of CMAKE_CXX_COMPILER.
    (The default definition is in
    /usr/share/cmake/Modules/CMakeCXXInformation.cmake)

Recursive grep shows there is no definition in the source our build directories.
Default defn:

if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
  set(CMAKE_CXX_CREATE_SHARED_LIBRARY
      "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()

I've found the problem. CMAKE_CXX_CREATE_SHARED_LIBRARY
is overridden in .../cmake/Modules/Platform/SunOS.cmake.
You should be able to fix it by overriding it in
CMakeCache.txt.

I also found this thread which describes the same problem:
https://cmake.org/pipermail/cmake/2006-August/010536.html

In Christ,
Steven Watanabe

@PHHargrove
Copy link
Author

Steven,

I tried appending the following line to CMakeCache.txt

CMAKE_CXX_CREATE_SHARED_LIBRARY:STRING=<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>

However, the build is still failing in the same way as before.

-Paul

@PHHargrove
Copy link
Author

I also found I could not resolve this by setting CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS=-lstdc++ to allow the shared library to link correctly using gcc.

I am currently working-around the problem by patching two files:

$ perl -pi -e "s,bin/gcc,bin/g++," -- \
                tools/lto/CMakeFiles/LTO.dir/link.txt \
                tools/clang/tools/libclang/CMakeFiles/libclang.dir/link.txt

@usebaz
Copy link

usebaz commented Oct 19, 2017

Try set: CC=gcc CXX=g++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants