/bin/ld cannot find lstdc++ but libstdc++.so does exist - g++

Given error:
/bin/ld: cannot find -lstdc++
I used the following commands:
locate libstdc++.so
And its output:
$ locate libstdc++ | grep libstdc++.so
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libstdc++.so
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libstdc++.so
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.19-gdb.py
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.19-gdb.pyc
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.19-gdb.pyo
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo
/usr/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6.0.19
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo
Clearly libstdc++.so exists. Why it gives that error?

Related

How to solve cmake linking error `lld: error: undefined symbol: llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool) ...`

I am trying to compile from source ypsilon, but couldn't get it installed on Ubunut 22.04 LTS after multiple trial-and-errors.
I followed the official instructions linked above but process fails at cmake --build ., complaining that it couldn't find llvm. Then, I used cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake .... Now, the compilation is OK, but there are many link errors even after trying out -DCMAKE_EXE_LINKER_FLAGS_RELEASE=:
$ cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake -DCMAKE_EXE_LINKER_FLAGS_RELEASE=-L/usr/lib/llvm-14/lib -DCMAKE_BUILD_TYPE=Release .. && cmake --build . |& tee ~/a.txt
-- Build type: Release
-- Found LLVM 14.0.0
-- Using LLVMConfig.cmake in: /usr/lib/llvm-14/cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/tmp/ypsilon/build
[ 2%] Building CXX object CMakeFiles/ypsilon.dir/src/arith.cpp.o
...
[100%] Linking CXX executable ypsilon
ld.lld: error: undefined symbol: llvm::Type::getInt32Ty(llvm::LLVMContext&)
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<8>::copy(llvm::Value*))
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<24>::copy(llvm::Value*))
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<16>::copy(llvm::Value*))
>>> referenced 96 more times
ld.lld: error: undefined symbol: llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool)
...
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [CMakeFiles/ypsilon.dir/build.make:817: ypsilon] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:164: CMakeFiles/ypsilon.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
I am not familiar with cmake or its linking flags on the command line.
Does any one know how to fix the cmake linking issue in the above commands?
The steps I tried are as follows:
sudo apt install clang lld
git clone https://github.com/fujita-y/ypsilon.git
cd ypsilon/ ; mkdir -p build ; cd build
cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake -DCMAKE_EXE_LINKER_FLAGS_RELEASE=-L/usr/lib/llvm-14/lib -DCMAKE_BUILD_TYPE=Release .. && cmake --build .

How to fix libtool: undefined symbols not allowed in x86_64-pc-msys shared

I am trying to build heimdal package for msys2. To my dismay, during linking of the first constituent library, roken, dlls fail to be built, and that causes sort of a chain reaction further on.
The only message i get is:
libtool: undefined symbols not allowed in x86_64-pc-msys shared ... only static will be built
however, there is no information provided on what symbols are undefined. How can i find that out?
If i turn on output of commands wuth make V=1 i get libtool command that links from a large numbert of .lo files. If i try to run gcc over them (copying command from there), it does not recognize them as anything.
I am trying to follow instructions as outlined in msys2 package build script for heimdal.
On Windows building a shared library while allowing undefined symbols is not allowed.
Try to build with the -Wl,-no-undefined linker flag, for example by adding LDFLAGS="-Wl,-no-undefined" to the ./configure command.
If that didn't work try this after ./configure and before make:
sed -i.bak -e "s/\(allow_undefined=\)yes/\1no/" libtool
If you already had a failed build earlier you should also clean up any .la files like this before running make again:
rm $(find -name '*.la')

Cannot find -l<nameOfTheLibrary>, even after setting LD_LIBRARY_PATH

I'm trying to build OpenMVG, and can't resolve some dependency errors. I'm in an anaconda environment and using conda installed versions of g++ and some of the libs (I do not have root priveleges).
$ cmake --build . --target install
... (lots of output from seemingly successful steps) ...
[ 77%] Built target openMVG_sample_main_features_repeatability_dataset
[ 77%] Linking CXX executable ../../Linux-x86_64-RELEASE/openMVG_sample_features_affine
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -ljpeg
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lpng
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lz
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -ltiff
collect2: error: ld returned 1 exit status
gmake[2]: *** [Linux-x86_64-RELEASE/openMVG_sample_features_affine] Error 1
gmake[1]: *** [openMVG_Samples/features_affine_demo/CMakeFiles/openMVG_sample_features_affine.dir/all] Error 2
gmake: *** [all] Error 2
But libjpeg, libpng etc. are all /home/user/anaconda3/envs/sfm/lib/. For example:
(sfm) [openMVG]$ find /home/user/anaconda3/envs/sfm/ -name 'libjpeg*'
/home/user/anaconda3/envs/sfm/conda-meta/libjpeg-turbo-cos6-x86_64-1.2.1-h24432d5_0.json
/home/user/anaconda3/envs/sfm/lib/libjpeg.a
/home/user/anaconda3/envs/sfm/lib/libjpeg.so
...
So I've tried both of the following:
export LD_PRELOAD=/home/user/anaconda3/envs/sfm/lib/libjpeg.so
and
export LD_LIBRARY_PATH=/home/user/anaconda3/envs/sfm/lib/:/home/user/anaconda3/lib/:/usr/lib64/:/usr/lib/
before rerunning$ cmake --build . --target install, but get the same result.
It seems to me that the compiler couldn't find some libs. So I told it exactly where to look, and even tried preoloading them, and it still can't find them. Adding the paths to LD_LIBRARY_PATH was necessary to get this far - so it does seem to have worked for other things. Just not this problem. How do I troubleshoot from here?

spnavcfg - SpaceNavigator in Arch Linux

Attempting to install my SpaceNavigator on arch linux using the open source spacenavd service. The service starts up fine, and I have the libspacenav and spacenavd packages installed. I am attempting to build spnavcfg from the sourceforge website.
http://sourceforge.net/projects/spacenav/files/
I downloaded libspacenav and spacenavd from the AUR, ran makepkg -s, and then sudo pacman -U and installed the packages locally, no issues.
spacenavcfg is another story, will probably have to build my own ABS package before I can use pacman on it, however when I extract the contents from sourceforge, it does not compile. I can successfully run sudo ./configure, but when I type 'make', I get the following error:
gcc -o spnavcfg spnavcfg.o front.o back.o cfgfile.o `pkg-config --libs gtk+-2.0`
/usr/bin/ld: front.o: undefined reference to symbol 'XOpenDisplay'
/usr/lib/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:16: recipe for target 'spnavcfg' failed
make: *** [spnavcfg] Error 1
I have not been able to figure out what the issue is, the usual google/forum trolling has not yielded any answers.
Thanks!
Barrett
Try with this AUR PKGBUILD this time: https://aur.archlinux.org/packages/spnavcfg/

Trouble building a MIPS compatible C static library

I'm trying to build a C static library (.a) that is compatible with a MIPS processor (I'm working in an embedded system).
To do so I tried to execute the following commands (obs: I'm using the mipsel-unknown-elf tool):
mipsel-unknown-elf-gcc -o math.o -c math.c
(No erros followed this command)
mipsel-unknown-elf-gcc -archive -o libmath.a math.o -lm
With this command I got the following error message:
cannot find -lm
collect2: ld returned 1 exit status
By getting this message I tried to add a -L/path argument:
mipsel-unknown-elf-gcc -archive -o libmath.a math.o -L/usr/lib/i386-linux-gnu -lm
But then I got the following error:
skipping incompatible /usr/lib/i386-linux-gnu/libm.a when searching for -lm
cannot find -lm
collect2: ld returned 1 exit status
Does anyone knows what's going on?
Your cross compiler distribution should include a MIPS libm.a. I just checked and I found several libm.a versions in my installation of CodeSourcery mips-linux-gnu-gcc. I don't have mipsel-unknown-elf-gcc installed, so I can't check that. If the mips-linux-gnu- version of libm.a is self contained, you might try using that version.