Link to home
Start Free TrialLog in
Avatar of sleepylight
sleepylight

asked on

linking an application built with -m32 flag

Hi,

I'm building an application on RedHat Enterprise 3 for x86-64.  I'm running the 64 bit kernel and compilers, but right now I need to build a 32 bit app.  I added the -m32 flag to my make files and it sure looks like 32 bit code is being generated.  However, when it comes time to link in the library I'm told that it's not compatible.  I figure I'm either missing a flag for ar or for ld.  I don't really know what to pass them and the man pages are so huge I figured it would be faster just to ask someone.

Here is a brief transcript of my problem:

[bottiger@rubicant ipm]$ make
g++ -D_DEBUG -DLINUX -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DRTI_USES_STD_FSTREAM -D__linux__  -Wno-deprecated -m32 -O -Dlinux \
-I/opt/itt/ipm/src/include  \
-L/opt/itt/ipm/lib/linux  \
 \
  \
-c ipm.cpp -o linux/ipm.o
ar -rc  /opt/itt/ipm/lib/linux/libipm.a linux/ipm.o

At this point, it is my understanding that the 32 bit library has been built, and that I shoud be able to build my app with the -m32 flag and statically link it.

[bottiger@rubicant example]$ make
cd client; make
make[1]: Entering directory `/home/bottiger/development/ipm/dev4/src/example/client'
echo in the .o maker
in the .o maker
g++ -I/opt/itt/ipm/src/include -Dlinux -O -exceptions -D_DEBUG -DLINUX -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DRTI_USES_STD_FSTREAM -D__linux__  -Wno-deprecated -m32 \
-I/opt/itt/ipm/src/include  \
-c client.cpp -o linux/client.o
g++ \
linux/client.o \
 \
 -L/opt/itt/ipm/lib/linux \
 -lm -lipm \
-o /opt/itt/ipm/bin/linux/client
/usr/bin/ld: skipping incompatible /opt/itt/ipm/lib/linux/libipm.a when searching for -lipm
/usr/bin/ld: cannot find -lipm
collect2: ld returned 1 exit status
make[1]: *** [/opt/itt/ipm/bin/linux/client] Error 1
make[1]: Leaving directory `/home/bottiger/development/ipm/dev4/src/example/client'
make: *** [CLIENT] Error 2

I'm betting my problem is with ar, but I'm a total novice with it, so I'm pretty well stuck.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

> I'm betting my problem is with ar,
ar is a simple program which concatenates the given files to a new one

you're building a dynamic shared object with g++, so you better give the full path to your static librrary instead of -lipm
oops missed to say that you need to use 32-bit versions of all other libs also
Avatar of Duncan Roe
Can you simply load ipm.o instead of the library?
At the very least, all modules in libipm.a have to be -m32.
Also, it may be necessary to use a 32-bit ar to build libipm.a
At the very least, all modules used in client.ohave to be -m32 too!
ASKER CERTIFIED SOLUTION
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sleepylight
sleepylight

ASKER

Yeah, it looks like I didn't have the -m32 flag enabled in the linking stage.  I changed the make file and everything worked fine.  Totally not an ar problem.