g++ unable to locate libs - c++

I'm compiling my code using g++ -L/lib64 -I /git/src ... but I get
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lgcc_s
I checked my /lib64/ and found that these libs are actually present
/usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.19
/usr/lib64/libm.so -> ../../lib64/libm.so.6
/usr/lib64/libgcc_s.so.1 -> libgcc_s-4.8.5-20150702.so.1
/usr/lib64/libc.so.6 -> libc-2.17.so
When I try ld -lc --verbose this too fails. All the libs are present in /lib64 and the path is included still g++ fails to locate them. Any Idea what is going on ?

Related

/usr/bin/ld: cannot find -ldlib /usr/bin/ld: cannot find -lcblas /usr/bin/ld: cannot find -llapack

/usr/bin/ld: cannot find -ldlib
/usr/bin/ld: cannot find -lcblas
/usr/bin/ld: cannot find -llapack
In the process of executing the dlib library code in centos7, up to'cmake' was executed.
However, the above error occurred during the make process. How do I fix it? (In ubuntu, only /usr/bin/ld: cannot find -ldlib problem occurred)
I had this problem and solved it by installing this library on my ubuntu(20.04) OS:
sudo apt install libatlas-base-dev

error while building opencv 2.4.5 application with eclipse and ubuntu 13.04

this is maybe a noob question but I've been stuck for a while and I appreciate any help...
I have been able to install opencv and run a sample application using the terminal without any problems however I want to use eclipse to manage my project easily...
I have followed the instructions given by the opencv tutorial in this [link]
http://docs.opencv.org/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html
I followed everything and i still get the following errors
/usr/bin/ld: cannot find -llibopencv_calib3d
/usr/bin/ld: cannot find -llibopencv_contrib
/usr/bin/ld: cannot find -llibopencv_core
/usr/bin/ld: cannot find -llibopencv_features2d
/usr/bin/ld: cannot find -llibopencv_flann
/usr/bin/ld: cannot find -llibopencv_gpu
/usr/bin/ld: cannot find -llibopencv_highgui
/usr/bin/ld: cannot find -llibopencv_imgproc
/usr/bin/ld: cannot find -llibopencv_legacy
/usr/bin/ld: cannot find -llibopencv_ml
/usr/bin/ld: cannot find -llibopencv_nonfree
/usr/bin/ld: cannot find -llibopencv_objdetect
/usr/bin/ld: cannot find -llibopencv_photo
/usr/bin/ld: cannot find -llibopencv_stitching
/usr/bin/ld: cannot find -llibopencv_superres
/usr/bin/ld: cannot find -llibopencv_ts
/usr/bin/ld: cannot find -llibopencv_video
/usr/bin/ld: cannot find -llibopencv_videostab
collect2: error: ld returned 1 exit status
make: *** [Test_OpenCV01] Error 1
the only differences I was able to find between my steps and the tutorial is:
when i run the command :
pkg-config --libs opencv
this is my output
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
so the library names are a bit different so I use the names that I have.
the command line that was executed automaticly from eclipse is
g++ -L/usr/local/lib/ -o "Test_OpenCV01" ./src/main.o -llibopencv_calib3d -llibopencv_contrib -llibopencv_core -llibopencv_features2d -llibopencv_flann -llibopencv_gpu -llibopencv_highgui -llibopencv_imgproc -llibopencv_legacy -llibopencv_ml -llibopencv_nonfree -llibopencv_objdetect -llibopencv_photo -llibopencv_stitching -llibopencv_superres -llibopencv_ts -llibopencv_video -llibopencv_videostab
it clearly specifies that the library path is /usr/local/lib/ which is where the shared libraries are at however in the error it says that it can't find the lib files in /usr/bin/ld
p.s.
I have tried both
1)Configuring OpenCV for using shared libraries:
sudo gedit /etc/ld.so.conf.d/opencv.conf
and adding the following line at the end of the file
/usr/local/lib the running sudo ldconfig after saving.
2)run the command
export LD_LIBRARY_PATH=/usr/local/lib
I also added
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
to the end of the /etc/bash.bashrc file.
Thanks for your help in advanced.
Your linking step is specifying the libraries incorrectly. If the library is libfoo.so, then you need to say -lfoo.
Replace
g++ -L/usr/local/lib/ -o "Test_OpenCV01" ./src/main.o -llibopencv_calib3d -llibopencv_contrib -llibopencv_core -llibopencv_features2d -llibopencv_flann -llibopencv_gpu -llibopencv_highgui -llibopencv_imgproc -llibopencv_legacy -llibopencv_ml -llibopencv_nonfree -llibopencv_objdetect -llibopencv_photo -llibopencv_stitching -llibopencv_superres -llibopencv_ts -llibopencv_video -llibopencv_videostab
with
g++ -L/usr/local/lib/ -o "Test_OpenCV01" ./src/main.o -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
You can read more about linking options here.
Even though the file names are like liblibopencv_core.so under /usr/local/lib folder, in GCC C++ linker libraries just mention opencv_core. Do the same for other files you are adding in library.

Linking both 32bit and 64bit .so files with g++ for a c++ program

I am trying to link both 32bit and 64bit .so files at the same time for a c++ program.
I am using 64bit Ubuntu 12.04.1 I also don't have the source files to recompile.
When I run the g++ command:
g++ onlineTraining.cpp -I /usr/local/MATLAB/R2012a_Student/extern/include/ -L /home/forest/SoarSuite/out/ -L /usr/local/MATLAB/R2012a_Student/bin/glnx86/ -I /home/forest/SoarSuite/out/include -leng -lmat -lmex -lut -lSoar
I get the following output since it doesn't recognize the 32bit .so files:
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libeng.so when searching for -leng
/usr/bin/ld: cannot find -leng
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libmat.so when searching for -lmat
/usr/bin/ld: cannot find -lmat
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libmex.so when searching for -lmex
/usr/bin/ld: cannot find -lmex
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libut.so when searching for -lut
/usr/bin/ld: cannot find -lut
collect2: ld returned 1 exit status
When I run the g++ command with -m32:
g++ -m32 onlineTraining.cpp -I /usr/local/MATLAB/R2012a_Student/extern/include/ -L /home/forest/SoarSuite/out/ -L /usr/local/MATLAB/R2012a_Student/bin/glnx86/ -I /home/forest/SoarSuite/out/include -leng -lmat -lmex -lut -lSoar
I get the following output since now it doesn't recognize 64bit .so files:
/usr/bin/ld: skipping incompatible /home/forest/SoarSuite/out//libSoar.so when searching for -lSoar
/usr/bin/ld: cannot find -lSoar
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
Is it possible to link both of the 34bit and 64bit .so files at the same time?
Thank you.
No, this is not possible. 32-bit libraries can only be linked into a 32-bit executable, and 64-bit libraries can only be linked into a 64-bit executable.
If the Matlab libraries you are trying to link in are only available as 32-bit, you will need to build your application as 32-bit (using -m32) as well, and link in only 32-bit libraries.
I'd suggest making a shell script or make file that runs the two compiler commands.

make command gives Incompatible i386 architecture(i386x86-64)

Im having trouble using my make file for a program i am writing in a linux environment. The program is a fern fractal that uses bitmapImage.h and bitmapImage.so given to me by my professor. Whenever i attempt to run the make file i get a long string of errors, the main one being :
make
g++ -c -o fern.o fern.cpp
g++ -c -o fernType.o fernType.cpp
g++ -m32 -o fern fern.o fernType.o bitmapImage.so
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status
make: *** [spiro] Error 1
my guess is that the bitmapImage.so is designed for a 32 bit system, but my virtual machine ubuntu runs 64-bit. How do i go about fixing this so i can compile my program? Thanks!
EDIT: updated my old post to show the current error i am getting
MakeFile:
# Make file for spirograph program
## note, uses bitmapImage shared object file (library).
OBJS = fern.o fernType.o
CC = g++ -m32
DEPS1 = fernType.h
DEPS2 = bitmapImage.h
all: spiro
spiro: $(OBJS)
$(CC) -m32 -o fern $(OBJS) bitmapImage.so
spiro.o: fern.cpp $(DEPS1)
$(CC) -m32 -c fern.cpp
spiroType.o: fernType.cpp $(DEPS1) $(DEPS2)
$(CC) -m32 -c fernType.cpp
# -----
# clean by removing object files.
clean:
rm $(OBJS)
Add the -m32 option to your compilation lines, that forces everything to be compiled for a 32-bit address space. (It will still run on a 64-bit system.)
Yes, that's exactly the problem -- you can't link a 32-bit object file with a 64-bit object file. You need to either:
Compile on a 32-bit machine (real or virtual),
Ask your professor for a 64-bit library, or
Ask for the source code to the library so you can compile it all yourself
Use file to see if, indeed, the shared lib is 32-bit.
If it is, you'll have to acquire a 64-bit copy of it somehow.

Compiling x32 bit LD_PRELOAD on 64 bit Ubuntu

I'm trying to compile x32 LD_PRELOAD on x64 platform(Ubuntu), my command:
g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp
But i'm getting error:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
How can i fix that?
Thanks!
You need to install 32-bit development packages provided by your distribution. You are seeing this error because you do not have a 32-bit libstdc++ to link against.
Try installing Ubuntu's g++-multilib package.