How to compile 32 bit programs on 64 bit Ubuntu OS 3


I installed ia32-libs, but got an error like this while compiling my program(already added -m32 option to CPPFLAG arguments in the Makefile)
[code]
jacky@ubuntu-msdk:/opt/workspace/msdk/src/msdk_client32$ make
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.
g++ -m32 -I./../base_shm -g -O2 -Wall -c main_cli.cpp -o main_cli.o
In file included from /usr/include/stdio.h:28:0,
from ./../base_shm/config.h:4,
from main_cli.cpp:1:
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.
make: *** [main_cli.o] Error 1
jacky@ubuntu-msdk:/opt/workspace/msdk/src/msdk_client32$
[/code]

Solution for this error:
sudo apt-get install gcc-multilib

Try again. But still return with errors(If you are compiling a C program, than it’ll be OK now. But I’m compiling a C++ program…):
[code]
jacky@ubuntu-msdk:/opt/workspace/msdk/src/msdk_client32$ make
g++ -m32 -I./../base_shm -g -O2 -Wall -c main_cli.cpp -o main_cli.o
main_cli.cpp: In function ‘void* WorkerThread(void*)’:
main_cli.cpp:230:41: warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type ‘void*’ [-Wformat]
main_cli.cpp:270:228: warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 2 has type ‘TThreadParam*’ [-Wformat]
main_cli.cpp: At global scope:
main_cli.cpp:51:13: warning: ‘void cbDecodeCallback(unsigned char*, unsigned int, short unsigned int, short unsigned int, unsigned int, long long unsigned int, void*)’ defined but not used [-Wunused-function]
g++ -m32 -I./../base_shm -g -O2 -Wall -c ../base_shm/easyshm.cpp -o ../base_shm/easyshm.o
../base_shm/easyshm.cpp: In member function ‘int easyshm::rs_shm_get(TShmInfo*)’:
../base_shm/easyshm.cpp:24:8: warning: unused variable ‘mem’ [-Wunused-variable]
../base_shm/easyshm.cpp: In member function ‘int easyshm::rs_shm_post(TShmInfo*, void*, size_t, int, EShmProtoType)’:
../base_shm/easyshm.cpp:262:52: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
g++ -m32 -I./../base_shm -g -O2 -Wall  .//main_cli.o ./../base_shm/easyshm.o -lpthread -o msdk_client32
/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
make: *** [msdk_client32] Error 1
[/code]

For Fedora, make sure you have installed the following packages as well:

  • libstdc++.i386
  • libgcc.i386
  • glibc.i386
  • glibc-devel.i386

And for Ubuntu that’ll be:
sudo apt-get install g++-multilib

So, as a conclusion for compiling 32 bit programs on a 64 bit Linux OS, you need not only
sudo apt-get install ia32-libs
but also
sudo apt-get install build-essential module-assistant

  • C: sudo apt-get install gcc-multilib
  • C++: sudo apt-get install g++-multilib

 


Leave a Reply to Prasad Cancel reply

Your email address will not be published. Required fields are marked *

3 thoughts on “How to compile 32 bit programs on 64 bit Ubuntu OS