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.
Related
I am using Fedora 28 with Eclipse Version: Oxygen.3a.
I have already installed the add-on for LLVM-Clang from "Install new software". I am using GCC/G++ 8.1.1.
I built Clang using ninja build system, and it works perfectly fine from command line. I am interested in LibTooling library, so, it serves my purpose. Then, I was trying to setup Eclipse with Clang (mainly for easy debugging), but it Eclipse always gives me linker errors.
I tried 2 solutions:
Followed this thread Unable to install LLVM toolchain for Eclipse CDT. I made a hello world project, and I get the errors:
clang++ -I/home/hassan/Tools/llvm-clang/llvm/include -O0 -emit-llvm -g3 -Wall -c -fmessage-length=0 -std=c++0x -o src/clang_test.bc ../src/clang_test.cpp
clang++ -L/usr/lib/gcc/x86_64-redhat-linux/8/32/ -L/home/hassan/Tools/llvm-clang/build/bin -o clang_test src/clang_test.bc -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/32//libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/32//libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/32//libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/32//libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/32//libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/32//libgcc.a when searching for -lgcc
I set the include paths/lib paths to my already built (ninja build system) directory. It compiles fine without any problems, but I get linker errors, e.g., llvm::outs() could not be identified.
If anyone can point me in the right direction, that would be great.
Thanks.
I have a very similar issue to the one presented in how to dynamically link to local copy of libc.so.6, libstdc++.so.6 on system with old version of gcc and I followed the answer provided there. To summarize, the issue is that I have code written using C++11 and the cluster sysadmin won't upgrade the gcc compiler to a version which supports C++11. I did a manual install of gcc4.9 in my home directory (using --prefix=$HOME). I compile my code with the following flags:
-I/home/stroberg/include -L/home/stroberg/lib -lc -lstdc++ -llapack -lblas -O3 -std=C++11
I also set
export LD_LIBRARY_PATH=/home/stroberg/lib:$LD_LIBRARY_PATH
The compilation goes fine until it gets to the linking stage, where I get the following errors:
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libgcc_s.so when searching for -lgcc_s
Any ideas what could be causing the problem? I'm also using the armadillo package (also a local version) is that makes any difference.
Thanks.
I got it working, so I figured I should post what I did. Compiling with
-I$(HOME)/include -L$(HOME)/lib -lblas -llapack -lgsl -lglsblas -O3 -std=c++11
seemed to do the trick. Wish I knew exactly what fixed the problem, but I hope this helps.
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.
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.
I have a problem: I wrote code using Boost (locks.hpp). My server is running x64 Ubuntu (Linux). When i compile this code with -m64, it builds fine. But when I try to compile for -m32, I get these errors:
g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp -lboost_thread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.so when searching for -lboost_thread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.a when searching for -lboost_thread
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.so when searching for -lboost_thread
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.a when searching for -lboost_thread
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status
What am I doing wrong? Thanks!
Try installing the 32-bit boost package:
sudo apt-get install libboost-thread-dev:i386
You need a 32 bit version of the thread library. The answer to your question is already on stackoverflow.com. Use the address-model option when you build boost from source. Boost provides great documentation for building on Linux.
bjam address-model=32