Ivan Vučica
Ivan Vučica

Reputation: 9669

Compiling for amd64 under i386 Debian

Cheers,

I want to avoid problems with compiling my code on amd64, yet I don't have a 64-bit CPU available and have no hopes of getting upgrade to my machine any time soon. I have no dreams of testing the code (although that should theoretically be possible using qemu-system) but I'd like to at least compile the code using gcc -m64.

Basic idea works:

CFLAGS=-m64 CXXFLAGS=-m64 ./configure --host x86_64-debian-linux

However, the code depends on some libraries which I typically install from Debian packages, such as libsdl1.2-dev, libgmp3-dev and such. Obviously, getting 64-bit versions of packages installed alongside of 32-bit versions is not a one-liner.

What would be your practices for installing the 64-bit packages? Where would you put them, how would you get them there and how would you use them?

To repeat, I don't have 64-bit CPU and cannot afford getting a new machine.

I have already set up amd64-libs-dev to give some basic push to gcc's -m64.

Attempted so far:

Upvotes: 2

Views: 6043

Answers (6)

Fabel
Fabel

Reputation: 1761

Try cross compiling SDL, gmp and other libraries yourself. Or manually extract the files you need from the Debain packages.

Upvotes: 0

Vitalie
Vitalie

Reputation: 736

Check out pbuilder, It can create build environments for many architectures, some instructions here

Upvotes: 0

Dirk is no longer here
Dirk is no longer here

Reputation: 368181

You want to look into the dchroot package to set up a simple chroot(8) environment -- that way you can compile real amd64 binaries in a real 64-bit setting with proper libraries and dependencies. This surely works the other way (i.e. I am using i386 chroots on amd64 hosts) but I don't see why it shouldn't work the other way if your cpu supports amd64.

Edit: Now that you stress that you do not have a amd64-capable cpu, it gets a little trickier. "In theory" you could just rebuild gcc from source as a cross-compiler. In practice, that may be too much work. Maybe you can just get another headless box for a few dollars and install amd64 on that?

Upvotes: 1

LiraNuna
LiraNuna

Reputation: 67232

If you're using debian, before you can use gcc -m64, you need to install gcc-multilib and g++-multilib. This will also install all files needed to link and create a 64bit binary.

You don't have to have a 64bit capable CPU for this either.

Then you can call GCC as follows:

$ gcc -m64 source.c -o source

As for external libraries, debian takes care of that if you have multilib installed. I have a 32bit machine that compiles 64bit code for another machine and links a handful of libraries (libpng, libz for example). Works great and the executable run (debian to debian).

Upvotes: 4

Thomas
Thomas

Reputation: 181705

Doesn't Debian distinguish between lib32 and lib64 directories? In that case, you can just grab the packages and force them to install, regardless of architecture.

If that does not work (or would hose your system!) I would set up a chroot environment and apt-get the 64-bit libraries into there.

Upvotes: 0

Omry Yadan
Omry Yadan

Reputation: 33596

check out this fine article that describes how to easily create a 32bit chroot, where you can install all the 32bit tools (gcc and libs)

Upvotes: 0

Related Questions