devtoolset-7 stl_vector.h undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)' - linux

I am currently trying compile my program on CentOS 7, and below error has occurred.
It works well with ubuntu 18.04, but it is not works with CentOS 7.
db/obj-db.o: In function `std::vector<std::string, std::allocator<std::string> >::_M_range_check(unsigned long) const':
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_vector.h:825: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
db/obj-db.o: In function `std::vector<int, std::allocator<int> >::_M_range_check(unsigned long) const':
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_vector.h:825: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../bin/x64/libUFMatcher.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)#GLIBCXX_3.4.20'
../bin/x64/libUFMatcher.so: undefined reference to `__cxa_throw_bad_array_new_length#CXXABI_1.3.8'
collect2: error: ld returned 1 exit status
make: *** [Makefile:56: ../bin/x64/MatchingServer] Error 1

The centos 7 has a old gcc version, maybe 4.8.5. But now many libraries need a more high version. You can run below commands to use a higher gcc version
sudo yum update -y
sudo yum install centos-release-scl
sudo yum install devtoolset-8 # gcc 8 is part of this toolset
scl enable devtoolset-8 bash # make the gcc version be 8.3.1

Check whether the linked target(object/lib) is compiled with the same version of gcc.

I got the same compiling issue after I had a second version of gcc/g++ on my machine (CentOS 7). The original one was installed by yum (v4.8.5) and the other was installed from source code (v4.9.2). It looks like the manual install changes $PATH entries order in my shell, that /usr/local/bin went before the /usr/bin. So when my code compiles, it just looks for gcc/g++ which comes first from the $PATH. Since my manual installation of 4.9.2 gcc is not fully completed, there are missing libraries and its binary is under the /usr/local/bin.
Quick fix: just check your $PATH to see if it's messed up. For me, put /usr/local/bin after /usr/bin works.
# echo $PATH
/usr/sbin:/usr/bin:/root/bin:/usr/local/sbin:/usr/local/bin:...

Related

/usr/bin/ld: /usr/include/c++/8/bits/stl_construct.h:107: undefined reference to ***

Running into errors when compiling Google's BoringSSL for NGINX QUIC on my Raspberry Pi 4B, with Raspberry Pi OS, aka Raspbian buster running on it.
The commands I used to compile
As what Google's document says, I used these commands:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
I've also tried to run cmake without passing -DCMAKE_BUILD_TYPE=Release.
Error output
Here's part of the error message. I'm not showing the entire output since it's too long (there are 352 lines). Tell me if the entire output is needed to solve this issue.
[ 75%] Linking CXX executable crypto_test
/usr/bin/ld: CMakeFiles/crypto_test.dir/abi_self_test.cc.o: in function `ABITest_SanityCheck_Test::TestBody()':
/usr/include/c++/8/bits/unique_ptr.h:81: undefined reference to `abi_test_trampoline'
/usr/bin/ld: CMakeFiles/crypto_test.dir/abi_self_test.cc.o: in function `ABITest_ARM_Test::TestBody()':
/usr/include/c++/8/bits/stl_construct.h:107: undefined reference to `abi_test_clobber_r4'
/usr/bin/ld: /usr/include/c++/8/bits/stl_construct.h:107: undefined reference to `abi_test_trampoline'
/usr/bin/ld: /usr/include/c++/8/bits/stl_construct.h:107: undefined reference to `abi_test_clobber_r0'
/usr/bin/ld: /usr/include/c++/8/bits/stl_construct.h:107: undefined reference to `abi_test_clobber_r1'
/usr/bin/ld: /usr/include/c++/8/bits/stl_construct.h:107: undefined reference to `abi_test_clobber_r2'
......
Additional information
cmake version 3.16.3
GNU Make 4.2.1
$ uname -a
Linux Kaibins-RPi 5.10.52-v8+ #1439 SMP PREEMPT Thu Jul 22 15:43:49 BST 2021 aarch64 GNU/Linux
Searched Google but I can't find any similar cases. I need help. Thanks so much.
This issue can also be found in Chromium bug tracker:https://crbug.com/boringssl/422. You can find full error output in the attachment there.
There is a boringssl package for OpenWrt which supports BCM2711 boards (the one the Raspberry Pi 4B is using). There is even a draft PR to package nginx with QUIC support. So, in principal, BoringSSL and nginx-quic work on this architecture. The BoringSSL version used in OpenWrt is from June 2021.
I have also compiled BoringSSL on Raspberry Pi OS without issues. These are the steps I documented for compiling on Debian and, from my memory, the same worked on Raspberry Pi OS:
sudo apt install cmake libpcre3-dev golang mercurial
git clone https://boringssl.googlesource.com/boringssl && cd boringssl
mkdir build && cd build
cmake ..
make -j16
cd ../..
hg clone -b quic https://hg.nginx.org/nginx-quic && cd nginx-quic
./auto/configure --with-debug --with-http_v3_module --with-cc-opt="-I../boringssl/include" --with-ld-opt="-L../boringssl/build/ssl -L../boringssl/build/crypto"
make -j16
sudo cp objs/nginx /usr/bin/nginx-quic
I can try to verify this again with a newer version if I find some time.

Paho MQTT throws undefined reference error during compile

I have a problem using Paho MQTT client in C.
I downloaded the pre built binaries for my system (Windows 10 64) from their projects page. I unpacked the zip file to a folder in the documents folder, where I also created a .c file with the example at the bottom of the Paho product page. My editor is atom and my compiler is gcc.
When I tried to compile it in Atom, I got this error:
undefined reference to MQTTClient_create'
So I went searching and found plenty of topics, but I still couldn't figure out, how to resolve this issue. From this stackoverflow topic I gather that it's a linker problem and that I need to link the files during compile, so here's what I tried:
gcc MQTT.c -L "C:\Users\Pete\Documents\MQTT on C\Examples\Paho\lib" -l paho-mqtt3c
Which still gives me the same undefined reference error. When I try to link to the dll of the same name, the compiler does not find the file.
Can anyone point me in the right direction, please?
Any help is appreciated!
I'd be interested to know if you have registered the Paho MQTT dll in Windows?
You should have paho-mqtt3c.dll as part of the download.
I don't know if this will work for you, but I have the same issue (undefined reference to MQTTClient_create)...
Copy the dll file into c:/windows/system32
Run CMD Prompt as Administrator and type:
regsvr32 i/ paho-mqtt3c.dll
Worth a try.
The problem was that I was compiling the program with the 32-bit gcc compiler for the 64-bit library. Installing and using MinGW64 worked.
I had the same issue in OS X. This is how I resolved it
I compiled the paho-mqtt library in Linux/EC2 instance.
Installed all the dependencies:
sudo yum install install build-essential gcc make cmake cmake-gui cmake-curses-gui
sudo yum install cmake
sudo yum install doxygen graphviz
cmake -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_STATIC=TRUE -DPAHO_BUILD_SHARED=FALSE -DPAHO_MQTT_C_PATH=../paho.mqtt.c/ -DPAHO_MQTT_C_LIB=../paho.mqtt.c/src/libpaho.mqtt3as-static.a
make
make html
make install
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ec2-user/paho.mqtt.c/src
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
sudo ldconfig
gcc test1.c -o test1 -lpaho-mqtt3c
Compiled successfully..
./test1
This solution works for OS X as well. Replace step 2 with
brew install cmake doxygen openssl-devel

ICU 58 undefined reference in MSYS2/MinGW64

Using instructions from
Compiling-ICU-with-MinGW
I got the following error
digitlst.o:digitlst.cpp:(.text+0x11): undefined reference to `_free_locale'
digitlst.o:digitlst.cpp:(.text+0x8fe): undefined reference to `_create_locale'
digitlst.o:digitlst.cpp:(.text+0xa20): undefined reference to `_create_locale'
collect2.exe: error: ld returned 1 exit status
My build environment:
MSYS2 with gcc version 6.3.0 (Rev1, Built by MSYS2 project)
64 Bit Toolchain: pacman -S mingw-w64-x86_64-toolchain
ICU 58.2 Sources ICU4C
I did
unzip icu4c-58_2-src.zip
cd icu/source
./runConfigureICU MinGW prefix=$PWD/../dist
make
Does anybody know how to solve this issue?
Edit: Same is with 58.1, but 57.1 works fine.
I was trying to build QT 5.8 with the latest version of ICU and this issue popped up...
I was able to build icu4c-58_2 by linking against libmsvcr100.a using x86_64-6.3.0-posix-seh-rt_v5-rev1
It appears that these functions are missing from the default libmsvcrt.a

Can't install cabal-install

I've just installed Mint 17 on my laptop and followed this with haskell platform generic. (I chose generic instead of using apt-get because it was the only way I could get ghc 7.10) When I try:
cabal install cabal-install
I get this error:
Resolving dependencies...
Configuring cabal-install-1.22.6.0...
Failed to install cabal-install-1.22.6.0
Build log ( /home/william/.cabal/logs/cabal-install-1.22.6.0.log ):
cabal: Error: some packages failed to install:
cabal-install-1.22.6.0 failed during the configure step. The exception was:
user error ('/usr/local/bin/ghc' exited with an error:
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
)
Does anyone know how to fix this ?
update:
Fixed by installing libgmp-dev
[edit] You already found that
sudo apt-get install libgmp-dev
should solve your problem (for Mint - for systems without apt-get you would need to use the resident package manager, and in other apt-get based system there could be variation in package names).
If you run into similar errors in the future, here is the reasoning with which to solve the problem: ld is a linker, essentially linking libraries into a program which is being compiled. -lgmp is the argument supplied to ld, telling it to link in the library gmp. It cannot find this library, so either you need to:
(a) tell it about its location in case you know you have the library (the cabal argument --extra-lib-dirs= is useful in this case), or
(b) install the library (google the library name and your system).
GMP is the GNU MP Bignum library which plays a role in providing the Integer and Fractional types.

Trying to compile linux build of project, cannot find library

I am trying to build a project written in c++ on Linux Mint 16, using...
make -f ./Makefile
and I keep getting this error
/usr/bin/ld: cannot find -ludev
collect2: error: ld returned 1 exit status
make: *** [BINARY] Error 1
I was getting a lot more of the /usr/bin/ld: cannot find -foo, but I checked in my Makefile and, using the synaptic package manager, installed all the other necessary libraries, eliminating all but this error. I cant seem to find it anywhere, although perhaps I am not looking in the right places.
Thanks.
I had the some problem, right after updating to Linux Mint 17.1. I was trying to build an application with Qt 5 serial port module. Solved by installing: libudev-dev .
try:
sudo apt-get install udev
I don't know how to do that in synaptic, but it should be easier, right?

Resources