I'm stumped on this.
I am using Ubuntu 18.04. I want link together an executable as a 32-bit program, for educational purposes.
My ld default search paths are all for the 64bit toolchain, so I think I need to invoke ld with additional library search paths since I want to link as 32bit. It can not find libc for some reason.
ld -mi386linux -L/lib/i386-linux-gnu/ -lc -o cc codechef.o -dynamic-linker /lib/i386-linux-gnu/ld-linux.so.2
This gives me the error ld: cannot find -lc
I have verified that libc.so.6 file does exist at /lib/i386-linux-gnu/libc.so.6
adding --verbose to my command reveals: attempt to open /lib/i386-linux-gnu//libc.a failed Why does my ubuntu installation not have this file but does have the .so?
Related
I am using the davidva/gcc49 copr, on Fedora 27.
When I try to compile after running source /usr/bin/gcc49 as the copr webpage describes, I get this error:
/usr/bin/ld: cannot find -lgcc_s
After learning about how the flag -l works for gcc, I learned it is looking for library gcc_s. I found it in /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64, which sounds like the right spot for it to be. Why is it not linking? Do I need to add a directory to a library path? If it's LDFLAGS, it's already there because of the file I sourced:
export LDFLAGS="-L/opt/gcc-$gver/$lib/gcc/$gcc_target_platform/$lib/"
What do I need to do to get gcc 4.9 on Fedora 27 to find its library file which is clearly in the LDFLAGS directory?
The problem is that the libgcc_s.so file is in the wrong directory! Just symlink to it in the 4.9.3 directory:
pushd /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/4.9.3
sudo cp -p ../lib64/libgcc_s.so.1 .
sudo ln -s libgcc_s.so.1 libgcc_s.so
popd
I guess the /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64 directory was supposed to be included in any LDFLAGS parameter, and that might be a weakness of the build process I was using and not the gcc 4.9 package.
Putting this file and appropriately-named symlink in the 4.9.3 directory allows my build process to complete successfully.
Reference: https://bgstack15.wordpress.com/2018/02/01/gcc-4-9-for-fedora-27/
I am trying to link two files, one complied with nasm from an assembly file and the other compiled with gcc from a C file, using a custom file. The command executed is this one:
ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o
However, it returns this error:
ld: target elf12-i386 not found
I am running a Debian 3.16.39 i686
When I compile my program with the command
gcc -o ****** -Xlinker -Bstatic -L/usr/lib -lf2c -lm
an error occurs
usr/bin/ld: cannot find -lgcc_s
Who can tell me the way to solve this error? The version of my system is 32bit Ubuntu 13.04, gcc 4.6. And I had searched the error,somebody said it maybe the error of symlink, but it has the link of /usr/lib/libgcc_s.so to /lib/i386-linux-gnu/libgcc_s.so.1 on my system. I also setted system variable LD_LIBRARY_PATH=/lib/i386-linux-gnu, but it did not work.
It is happening when I add -Bdynamic to the command,gcc compile successfully.The commands of compiling program with archive library and dynamic library are different.Maybe it is the explanation of "cannot find -lgcc_s"
I installed the rpm package as well but have this issue while building my code.
I also see that the rmp -q command tells me I have rpm-4.8.0-37.el6.x86_64 installed as well.
Not sure if I am missing any configuration somewhere
I am trying to mex C code using 32-bit 2012a Matlab on 64-bit Ubuntu 12.10
I've downloaded all possible libraries (gcc 4.7, build-essential,libs-32 etc.) however I am getting the following error
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.so when searching for -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.a when searching for -lgomp
/usr/bin/ld: cannot find -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
I've found that this problem can be solved by setting symbolic link from 64-bit libraries to the 32-bit ones. I tried to create different links but couldn't finish the compilation.
Thank you in advance.
UPDATE 1
gcc-multilib was missing, so after
sudo apt-get install gcc-multilib
I get the following errors
Warning: You are using gcc version "4.7.2-2ubuntu1)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
My mexopts.sh looks like
CC='gcc'
CFLAGS='-ansi -D_GNU_SOURCE'
CFLAGS="$CFLAGS -fPIC -pthread -m32"
CFLAGS="$CFLAGS -fexceptions"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64"
CLIBS="$RPATH $MLIBS -lm"
COPTIMFLAGS='-O -DNDEBUG'
CDEBUGFLAGS='-g'
CLIBS="$CLIBS -lstdc++"
the -m32 is there, however I am not sure if it should be written in that way.
Can someone elaborate on how to edit mexopts.sh to make matlab look at 32-bit libraries?
UPDATE 2
after looking at Linking using g++ fails searching for -lstdc++
I tried to install g++-multilib
sudo apt-get install g++-multilib
Now, errors have the form:
/usr/bin/ld: i386:x86-64 architecture of input file `bin/fv_cache.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `bin/obj_func.o' is incompatible with i386 output
...
First make sure you can build 32-bit executable from command prompt by executing gcc (more info here: 32bit application on 64 bit Linux)
In matlab command prompt execute mex -setup and choose gcc as a compiler. At the end you will get a message about location of 'mexopts.sh' (usually ~/.matlab//mexopts.sh)
Try to "mex".
If not successful open mexopts.sh and check if option -m32 is in CFLAGS. If not, add it.