I wrote like this :
gcc -m elf_i386
it says:
gcc: error: elf_i386: No such file or directory
basically I am trying to compile a 32bit program on 64bit system,but error :
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ld:
skipping incompatible /usr/lib/libSDL.so when searching for -lSDL
which I've checked the project built with -m32 and I can see all the *.o file are ELF 32-bit LSB,and the /usr/lib/libSDL.so are ELF 32-bit LSB too...so I might need pass -m elf_i386 to ld right? but I don't use ld directly I just use gcc to compile it.
gcc -m32
is what you want probably. The elf_i386 is passed by gcc to ld (if needed) just as Alan Curry mentioned in the comments.
The "skipping incompatible library" warning is just a warning and if it doesn't come up with "can't find the library", then you can assume it linked to the correct binary (because of the -m32 option).
Related
Preamble: this question is not about Oracle, instead I'd like to understand the fundamental difference between gcc-4 and gcc-6 in the handling of Position Independent Code.
So I have decided to try an Oracle 12c installation on a Debian stretch.
During the link stage with gcc-6, error messages like the following are issued:
/usr/bin/ld: /opt/oracle/product/12.2.0/lib/libpls12.a(pci.o):
relocation R_X86_64_32S against `.rodata.str1.4' can not be used when making a shared object;
recompile with -fPIC.
However, if I switch the compiler to use gcc-4.9, all the linking is done without any problems.
Thus my 2 questions:
Is there a change in the defaults for -fPIC and -fPIE between gcc version 4 and 6? Most probably yes, version 6 seems to use the 2 options by default.
More important for me: does gcc, version 6 have an option to use the version 4 behavior for the generation of position independent code? (Or will I sooner or later no more be able to link against old libraries because gcc-4 is no more available?)
Most likely the gcc-6 linker creates position independent executables by default. The problem can be reproduced as follows and solved by adding the linker flag -no-pie:
UNIX # gcc-6 -g -Wall -fno-pic -c helloworld.c -o helloworld.o
UNIX # gcc-6 -g -Wall helloworld.o -o helloworld
/usr/bin/ld: helloworld.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
UNIX # gcc-6 -g -Wall -no-pie helloworld.o -o helloworld
Indeed, after adding -no-pie to the gcc options used by Oracle, linking works without any errors.
Solution from broeni works fine. Some additional steps I made to make it work:
During installation, I modified the default linker tool from oracle, editing the file
/opt/oracle/product/12.2.0/db1/bin/orald
In the first lines, I forced to use GCC linker, and add the -no-pie option:
#if [ -z "$BASH_VERSION" -o -n "$ORALD_USE_GCC" ] ; then
exec gcc -no-pie "$#"
exit 1
#fi
tags: oracle 12c debian stretch
After hours of googling, I decide to give up and ask you experts. I am trying to build a 32-bit application (xgap if anyone interested) in my 64 Ubuntu 11.10. I added the CFLAGS=-m32 and the LDFLAGS=-L/usr/lib32 in the makefile. The objects are built into 32 bit fine. The last step is to link all the objects and libraries for X windows into this executable---xgap. Somehow it keeps giving me this error:
gcc -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11 -lSM -lICE
/usr/bin/ld: skipping incompatible /usr/lib32/libXmu.so when searching for -lXmu
...
/usr/bin/ld: i386 architecture of input file `xcmds.o' is incompatible with i386:x86-64 output
...
I have installed ia32-libs and mutilib support. I think I just need to force the linker to generate a i386 output. I tried to put two ld flags in my gcc command as shown above: -melf_i386 and -oformat elf32-i386. But what happens is that gcc doesn't search for the 32 bit library in /usr/lib32 anymore. I wonder if I need to put those flags in some fixed order?
Thanks for any idea and help!
EDIT: when I add the -m32 flag in my last gcc command (the linking stage I believe), even if I have the -L/usr/lib32 flag in place, gcc doesn't search in /usr/lib32 anymore ( really weird...) and generates the following error:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libXaw.so when searching for -lXaw
/usr/bin/ld: skipping incompatible /usr/lib/libXaw.so when searching for -lXaw
/usr/bin/ld: cannot find -lXaw
collect2: ld returned 1 exit status
Any one has any idea why this happens? I am using the auto tool to configure and make. I am really good at modifying those script files.
You need to use link with -m32 as well.
gcc -m32 -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11 -lSM -lICE
All things considered, I think you should be able to drop the -L/usr/lib32 when using -m32.
I solved the problem. I think that gcc was expecting a static library archive. I used the getlibs script from http://ubuntuforums.org/showthread.php?t=474790 to download all the .a archives needed for linking. Then gcc worked. I think gcc did search in /usr/lib32 directory but didn't find the .a archives so went on to search in the standard directory which is /usr/lib, where it finds the incompatible *.so files.
But then the question is: the *.so files in /usr/lib32/ from package ia32-libs doesn't really have the libraries needed for linking? What are those files in /usr/lib32/ used for?
I'm currently trying to compile a dynamically linked library (for a plugin system) using Windows and MinGW.
I compile each objects using this command line :
mingw-g++ -fPIC test.cpp
And the library using this line:
mingw-g++ -rdynamic -shared -Wl,-soname,test.so.1 -o test.so test.o
It doesn't work at all (using GCC with Linux, a similar line works though) : fPIC and rdynamic are ignored for some reason.
And while trying to make the library, it fails because the compiler try to link it with objects that are supposed to be resolved as I dynamically link it with the main binary.
So how do you compile this using MinGW?
Thanks :) !
-fPIC and -rdynamic are ignored because they are unused for Windows.
Also, .so is not the correct output extension for libraries on Windows.
To make a shared library for/on windows with GCC:
mingw-g++ -c file.cpp -o file.o
mingw-g++ -shared -Wl,--out-implib,libfile.a -o file.dll file.o
No more, no less.
And, documentation is always lovely to have: http://www.mingw.org/wiki/sampleDLL
I need compile a piece of C code to be called from matlab (mex compiling).
I am doing that on an intel mac and, since I am using Matlab's R2010a (7.10.0.499), I'd like to compile the C code into a version for 64-bits.
For whatever reason, just doing mex with the -arch=maci64 option did not seem to work...
As a way around, I am compiling the C code to a mexmaci64 file directly on the command line.
I used the gcc calls made by mex (with the -v option on) as a starting point.
I managed to compile the C code to an object file, but it looks like I am not compiling the C code to the correct architecture.
Does anyone know how to correct the gcc calls below so the C code gets compiled to 64-bits intel macs?
Details are listed below.
As always, any help greatly appreciated...
Keep thirsty, my friends. :p
G
DETAILS:
Here is how I did the compilation and linking:
gcc -c -I/Applications/MATLAB_R2010a.app/extern/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -fexceptions -D MACVERSION -DMX_COMPAT_32 -O3 -DNDEBUG "BoxQP.c"
gcc -O -bundle -Wl,-flat_namespace -undefined suppress -Wl,-exported_symbols_list,/Applications/MATLAB_R2010a.app/extern/lib/maci64/mexFunction.map -o "BoxQP.mexmaci64" BoxQP.o -L/Applications/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
Here are the warnings I get:
ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmx.dylib, file is not of required architecture
ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmex.dylib, file is not of required architecture
ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmat.dylib, file is not of required architecture
Ignoring the warnings and calling the BoxQP function from matlab results in the following error message:
??? Invalid MEX-file '/Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64':
dlopen(/Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64, 1): no suitable image found.
Did find: /Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64: mach-o, but wrong architecture.
PS: I tried changing the -DMX_COMPAT_32 flag to -DMX_COMPAT_64 but I do get the same warnings and same error...
PPS: I guess it may be relevant to mention that I am using Mac OS X 10.5.8 (the "tropical"/plain-vanilla Leopard, i.e., not the snow Leopard).
PPPS: The same happens with the yprime.c example provided by MATLAB
On my machine (Windows running cygwin) it compiles correctly. Flex is version 2.5.35 and bison is version 2.3
On linux machine 1 it compiles correctly. Flex is version 2.5.4 and bison is version 1.875c.
On linux machine 2 it does not compile correctly. Flex is version 2.5.4 and bison is 2.3.
One would expect by looking at the flex/bison version numbers that if it compiled correctly on my machine, it would compile correctly on machine 2, but that's not the case.
On linux machine 2, when I run gcc -c y.tab.c I get the following warnings several times
warning: incompatible implicit declaration of built-in function 'printf'
And when I run the following
gcc -o cminus y.tab.o lex.yy.o -ly -lfl
I get the following error.
gcc -o cminus y.tab.o lex.yy.o -ly -lfl
/usr/bin/ld: cannot find -ly
collect2: ld returned 1 exit status
make: *** [cminus] Error 1
This error can be removed by taking out the -ly option in gcc so that the program compiles, but the compiled program does not function correctly as it does on my machine and the other linux machine.
What could be causing the problem?
/usr/bin/ld: cannot find -ly
is the message you get when the linker cannot find the library.
You need to locate liby.a or liby.so and then insert a -L<that path> in your gcc command line.
On my Cygwin install, it's located in /lib/liby.a so I would use something like:
gcc -o cminus y.tab.o lex.yy.o -L /lib -ly -lfl
The warning sounds like you have a missing '#include ' in some source file. The link error means that you don't have liby.a installed on your machine. liby is part of yacc and some versions of bison, but is rarely actually needed (it just defines default implementations of yyerror and a couple other things). The fact that it links without it means that you don't really need it.
You don't say in what way the progrma misbehaves when its not functioning correctly, so that's tough to diagnose