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

build error: undefined reference to `llvm::Twine::str[abi:cxx11]() const' #1928

Closed
timotheecour opened this issue Dec 19, 2016 · 36 comments

Comments

@timotheecour
Copy link

commented Dec 19, 2016


git clone https://github.com/ldc-developers/ldc
cd ldc
git submodule update --recursive --init
mkdir build && cd build
CMAKE_PREFIX_PATH=`brew --prefix` cmake ..

git rev-parse HEAD
1155379b2775d440599c0c44a46ae0af0daf52b2

make

[  7%] Generating bin/ldc2
/home/timothee/git_clone/D/ldc/build/lib/libldc.a(ldctraits.cpp.o): In function `traitsTargetHasFeature(Dstring)':
/home/timothee/git_clone/D/ldc/gen/ldctraits.cpp:43: undefined reference to `llvm::Twine::str[abi:cxx11]() const'

on Ubuntu 14.04.5 LTS

@thewilsonator

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2016

Hmmm, git blame shows the whole file was added in June (1 revision) so it can't have "Just broken", what version of llvm are you using? How long since you last rebuilt it? etc.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 19, 2016

never built it on this machine; IIRC it used to work (a while ago, on other machines, probably w older versions of ldc)

looks like it's using llvm-3.8 (cf /usr/include/llvm-3.8/ in log below);

/home/timothee/git_clone/D/ldc/build/lib/libldc.a(modules.cpp.o): In function `ForcePassLinking':
/usr/include/llvm-3.8/llvm/LinkAllPasses.h:165: undefined reference to `llvm::createPrintModulePass(llvm::raw_ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
@thewilsonator

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2016

Were llvm and ldc built by the same compiler and are they linking to the same version of the c++ standard library/cxxabi? because I see a std::__cxx11::, its possible its looking in the wrong namespace and hence not finding the symbols.

@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 19, 2016

Can you paste CMake's output?

@kinke

This comment has been minimized.

Copy link
Member

commented Dec 19, 2016

What comes to mind is that we require gcc 4.9+ for building.

From https://gcc.gnu.org/onlinedocs/libstdc%2B%2B/manual/using_dual_abi.html:

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

ok, how should i modify my build command?
btw, this is one more reason we need to support building ldc via linuxbrew (which allows to be more selfcontained, and more cross platform), cf #1729

@thewilsonator

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2016

Either re-build llvm with c++11 or build ldc with not c++11, assuming that gcc automatically defines _GLIBCXX_USE_CXX11_ABI properly.

It should be CMAKE_CXX_FLAGS set this to the relevant c++11 mode.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

CMAKE_CXX_FLAGS shows as '' in ccmake (i don't see c++11)
CMAKE_CXX_COMPILER shows as /home/timothee/.linuxbrew/bin/c++
/home/timothee/.linuxbrew/bin/c++ --version
c++ (Homebrew gcc 5.3.0) 5.3.0
LLVM_CONFIG = /usr/bin/llvm-config-3.8

grep 'c++11' CMakeCache.txt => empty

@thewilsonator

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2016

what I meant was whatever the relevant flag to gcc to use (or not use) c++11.
e.g. on clang it is
-std=<value> Language standard to compile for
-stdlib=<value> C++ standard library to use

@rainers

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2016

On Ubuntu 16, I recently had to build with
CC=clang CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" ../ldc

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

not sure I understand what you want me to try ; you said:

Either re-build llvm with c++11 or build ldc with not c++11

so I'd like to try to build ldc with not c++11 ; all I did was CMAKE_PREFIX_PATH=brew --prefixccmake .. [no mention of c++11 in curses gui] followed by make; and it fails; at what point does it assume c++11 ?

EDIT: on ubuntu 14.04.5

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

On Ubuntu 16, I recently had to build with
CC=clang CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" ../ldc

just tried (on ubuntu 14.04.5)

CMAKE_PREFIX_PATH=`brew --prefix` CC=clang CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" ..

[  9%] Generating gccbuiltins_x86.di
../bin/gen_gccbuiltins: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ../bin/gen_gccbuiltins)
@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

Can you build LLVM manually first and use that to build LDC? To verify that there is nothing else broken somehow.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

git clone git clone http://llvm.org/git/llvm.git
cd path/llvm/build
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=path/usr/local/ ..
ninja && ninja install
ls path/usr/local/bin/llvm-config
#ok
ls path/stage/usr/local/include/llvm/IR
#ok

cd ~/git_clone/D/ldc/build

CMAKE_PREFIX_PATH=`brew --prefix` ccmake ..

LLVM_CONFIG path/usr/local/bin/llvm-config
LLVM_INTRINSIC_TD_PATH path/usr/local/include/llvm/IR

make
path/ldc/gen/tollvm.cpp: In function 'llvm::Constant* DtoConstFP(Type*, longdouble)':
path/ldc/gen/tollvm.cpp:428:72: error: no matching function for call to 'llvm::APFloat::APFloat(const llvm::fltSemantics& (&)(), llvm::APInt)'
                                                      APInt(80, 2, bits)));

@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

Did you make a mistake there? Setting LLVM_CONFIG should be done before running cmake on LDC's source. Try passing -DLLVM_ROOT_DIR="path/usr/local" to cmake.

@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

(also, use LLVM 3.9, LLVM trunk has changed a bit and compilation fails)

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

(also, use LLVM 3.9, LLVM trunk has changed a bit and compilation fails)

will try when i get a chance

Setting LLVM_CONFIG should be done before running cmake on LDC's source. Try passing -DLLVM_ROOT_DIR="path/usr/local" to cmake

does it matter? i'm editing via ccmake gui curses options to point LLVM_CONFIG to what i want, then press [c] configure and [g] generate

@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

ah, ok, thought the "ccmake" was a typo :)

@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

Just checked: I can build LLVM+LDC on Ubuntu 14 without troubles, without special cmake commandline flags. (if not, our industrial user would be in big trouble! ;)
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86
cmake -DLLVM_ROOT_DIR="/usr/local" -DCMAKE_BUILD_TYPE=Release

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

indeed, building llvm 3.9 from source did work, thanks for suggesting that. The build instructions should be updated to avoid this pain for the next guy.

CMAKE_PREFIX_PATH=brew --prefix ccmake ..
(the CMAKE_PREFIX_PATH was needed because of #952 )

then edit:
LLVM_CONFIG=/home/timothee/temp/stage/usr/local/bin/llvm-config
LLVM_INTRINSIC_TD_PATH=/home/timothee/temp/stage/usr/local/include/llvm/IR

Things that did not work:

  • using linuxbrew
  • using apt-get on ubuntu 14.04
  • building from source using /usr/include/llvm-3.8/
  • building from source using LLVM trunk
  • using ldc/releases (no shared libs libphobos.so, which i needed)
@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

CMAKE_PREFIX_PATH

This will no longer be necessary soon: #1832

using linuxbrew

Don't think this has something to do with LDC: to me it looks like linuxbrew builds LLVM in a "non standard" way?

building from source using LLVM trunk

#1936
But it's unavoidable that LDC releases will not build with LLVM trunk.

Please close this bug report if you agree that what you were seeing was a problem with the LLVM installation, and not something LDC can fix.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 20, 2016

Feel free to close, but I think at very least instructions for build ldc from source should be upgraded to reflect this bug report, eg:

  • using /usr/include/llvm-3.8/ didn't work (was problably installed via apt-get, althouhg i'm not sure, on the system i'm using)
  • building llvm39 from source and referring to that did work
@kinke

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

Right, building LDC from source using a Ubuntu/Debian LLVM distro package ought to work. I can check that later at home.

@kinke

This comment has been minimized.

Copy link
Member

commented Dec 20, 2016

I installed package llvm-dev on Ubuntu 16.04 (LLVM 3.8) and built LDC master successfully via

#!/bin/bash
mkdir build-ldc
cd build-ldc
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DD_COMPILER=dmd -DLLVM_ROOT_DIR=/usr ../ldc
make -j3 all

I don't think my self-built LLVM 3.9 in /usr/local played a role. Edit: Just to make sure, I renamed /usr/local and rebuilt successfully.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 21, 2016

I confirm that building works in ubuntu 16.04 (docs could specify to add sudo apt-get install libconfig++-dev on ubuntu), simply with brew install llvm && cmake .. && make

however, it does not work in ubuntu 14.04:

sudo apt-get install libconfig++

cmake -v  ..
# obscure error message: Failed to execute llvm-config ('/usr/bin/llvm-config-3.4',

cmake -v -DLLVM_ROOT_DIR=/home/parallels/.linuxbrew/ ..
# same obscure error message; unlike what docs seem to suggest, LLVM_ROOT_DIR seems useless

cmake -v -DLLVM_CONFIG=/home/parallels/.linuxbrew//bin/llvm-config ..
#that succeeds but ...

make

[  0%] Generating ddmd/idgen
[  0%] Generating ddmd/id.d, ddmd/id.h
Scanning dependencies of target LDCShared
[  0%] Building CXX object CMakeFiles/LDCShared.dir/gen/aa.cpp.o
cc1plus: error: -Werror=date-time: no option -Wdate-time
make[2]: *** [CMakeFiles/LDCShared.dir/gen/aa.cpp.o] Error 1
make[1]: *** [CMakeFiles/LDCShared.dir/all] Error 2

@thewilsonator

This comment has been minimized.

Copy link
Contributor

commented Dec 21, 2016

Does 14.04 come with llvm 3.4 by default? If so that would explain why it tries to use 3.4 (which is unsupported)

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 21, 2016

not sure when it comes by default, but it doesn't warn about incompatible version (error message rather unhelpful); i've updated docs in https://wiki.dlang.org/Building_LDC_from_source regarding using LLVM_CONFIG.

But even with that, the make fails, as above. Any chance you could try?

@thewilsonator

This comment has been minimized.

Copy link
Contributor

commented Dec 21, 2016

Any chance you could try?

I'm on OSX with LLVM 3.6.1, so no.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 21, 2016

via parallels or virtualbox ?

@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 21, 2016

Note: LLVM_ROOT_DIR is not ineffective: I use it always and only.

@kinke

This comment has been minimized.

Copy link
Member

commented Dec 21, 2016

Well, the latest official llvm-dev for Ubuntu 14.04 is really 3.4, so there's no point in making sure LDC can be built using an official distro package for the 2nd last LTS. Additionally, the latest official gcc is 4.8, and afaik, we require at least 4.9. @timotheecour managed to build LDC using a self-built LLVM 3.9 and gcc. The libconfig++-dev package is already mentioned (and has been) in https://wiki.dlang.org/Building_LDC_from_source#Prerequisites.
On Ubuntu 16.04, building LDC with the official distro LLVM 3.8 and official gcc works fine.
I use LLVM_ROOT_DIR exclusively too, but I only use it with self-built LLVMs.
Afaik, the binary releases are built on Ubuntu 12.04 with a self-built LLVM and gcc 4.9.

Is there any issue left? Edit: Oh, I forgot the 'rather unhelpful' ;) error msg if (too old) LLVM 3.4 is detected. Btw, did you clean the CMake working dir before each CMake invokation?

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 21, 2016

Btw, did you clean the CMake working dir before each CMake invokation?

just did make clean each time

Is there any issue left? Edit: Oh, I forgot the 'rather

ya, making message more helpful would be nice; but I've added a few notes in https://wiki.dlang.org/Building_LDC_from_source

I use LLVM_ROOT_DIR exclusively too, but I only use it with self-built LLVMs.

ya maybe it's different on ubuntu 14.04 for some reason

All in all, the provided instructions work great for ubuntu 16.04, but would be nice to make experience on ubuntu 14.04 a little bit better. Thanks!

@kinke

This comment has been minimized.

Copy link
Member

commented Dec 21, 2016

Btw, did you clean the CMake working dir before each CMake invokation?

just did make clean each time

That may be the explanation for the LLVM_ROOT_DIR/LLVM_CONFIG mess and cryptic error messages. I don't have good experiences with re-running CMake (some variables are cached, so not setting them explicitly in the 2nd command line uses the previous values instead of defaulting etc.), so I always wipe the directory before re-running CMake.

@timotheecour

This comment has been minimized.

Copy link
Author

commented Dec 22, 2016

indeed! that was the case for this particular issue, thanks for the tip! LLVM_ROOT_DIR does indeed work.

I've updated https://wiki.dlang.org/Building_LDC_from_source to reflect that.

NOTE[ubuntu 14.04]: besides the unhelpful error with llvm3.4, when /usr/bin/llvm-config-3.8 is installed, building ldc will result in later link errors IIRC.

This will work though:

brew install llvm
cmake -DLLVM_ROOT_DIR=`brew --repo`
@JohanEngelen

This comment has been minimized.

Copy link
Member

commented Dec 22, 2016

besides the unhelpful error with llvm3.4

Fix: #1940

@kinke

This comment has been minimized.

Copy link
Member

commented Jan 4, 2017

Thanks for that Johan, I think it's safe to close this now.

@kinke kinke closed this Jan 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.