Help us understand the problem. What is going on with this article?

64bit Linuxで32bit ELFをコンパイル

More than 3 years have passed since last update.

タイトル通り.
32bitのELFをコンパイルしたかったが,新たに32bit環境を構築するのもめんどくさいのでググった.
環境はDebian x64.

gccでできるらしい

gcc-m32オプションを付加すると,32bitのバイナリにコンパイルしてくれる.

$ gcc -m32 prog.c
In file included from /usr/include/stdio.h:27:0,
                 from prog.c:1:
/usr/include/features.h:374:25: fatal error: sys/cdefs.h: No such file or directory
 #  include <sys/cdefs.h>
                         ^
compilation terminated.

できないじゃん.

さらにググる

結局すぐに解決した.32bitの用のライブラリをインストールしないといけないらしい.
というわけでインストール.

$ sudo apt-get install libc6-dev-i386

インストール後,もう一度コンパイルしてみる.

$ gcc -m32 prog.c
$ ls
a.out prog.c

できた.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした