You are not logged in.

#1 2012-07-24 19:05:43

xangelux
Member
Registered: 2010-05-29
Posts: 73

[SOLVED]Compiling 32bit C programs on a 64bit arch

Hi guys, for the first time I decided to use 64bit arch on my machine and so far no complains (I don't think there will ever be). I'm a student of computer engineering  and I use C to code some projects but I haven't found a way to compile 32bit programs on my 64bit arch. Everybody says "just add -m32 flag to the compile step" but I think this is not all I have to do (it doesn't work if I just do that).

To prove it I have created a simple "hello world" in C:

#include <stdio.h>
int main(){
          printf("Hello, World");
          return 0;
}

When I try to compile it, I just run

gcc -m32 hello.c -o hello

But all I get is

In file included from /usr/include/features.h:399:0,
                 from /usr/include/stdio.h:27,
                 from test.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
compile finish

Needless to say it doesn't create the hello executable. Is there some packages I have to install in order to have this happen?

Last edited by xangelux (2012-07-25 00:24:40)

Offline

#2 2012-07-24 19:15:44

progandy
Member
Registered: 2012-05-17
Posts: 2,146

Re: [SOLVED]Compiling 32bit C programs on a 64bit arch

You'll have to install the multilib packages for gcc, libtool and binutils.

Offline

#3 2012-07-24 20:39:03

Cdh
Member
Registered: 2009-02-03
Posts: 1,098

Re: [SOLVED]Compiling 32bit C programs on a 64bit arch

xangelux wrote:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory

Well, you could see that something "-32" is missing so you are searching for 32 bit stuff that is not installed.

There's a tool called pkgfile which searches in the repository database for a file name and tells you which package it is in.
In this case, stubs-32.h

 ~ % pkgfile stubs-32.h
multilib/lib32-glibc

Maybe another helpful article: https://wiki.archlinux.org/index.php/Ar … ib_Project


฿ 18PRsqbZCrwPUrVnJe1BZvza7bwSDbpxZz

Offline

#4 2012-07-25 00:26:32

xangelux
Member
Registered: 2010-05-29
Posts: 73

Re: [SOLVED]Compiling 32bit C programs on a 64bit arch

Thank you guys, that was the answer, I didn't have the multilib repo enabled and so didn't have the gcc and devel for it. It's good to know a new (for me) tool that solves that and more.

This is solved, thanks to both.

Offline

Board footer

Powered by FluxBB