views:

544

answers:

5

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:

  • Setting up a 64-bit chroot jail with debootstrap in order to simplify installation of 64-bit development packages for libraries. Failed since finishing the setup (and installing anything afterwards!) requires 64-bit CPU.
  • Installing gcc-multilib and g++-multilib. This appears to do nothing beside depending on libc6-dev-amd64 which I already installed through amd64-libs-dev.
A: 

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)

Omry
The original poster has the opposite problem: he already has i386, he needs amd64. With that in mind, the article should be applicable.
Dirk Eddelbuettel
@Dirk A 64-bit chroot isn't going to work if he doesn't have a 64-bit processor
PiedPiper
@PiedPiper, I need chroot only for libraries, not for running executables. gcc -m64 works, and Debian already includes basic 64-bit development libraries in i386 distro.
Ivan Vučica
Your and Dirk's answers were the most promising, despite my CPU not supporting AMD64 (as was stated in the question). I spent last hour-and-a-half setting up an amd64 chroot, however I was unable to get apt-get to install stuff into the chroot.
Ivan Vučica
A: 

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.

Thomas
No -- multi-arch support is a current release goal we are working on and not yet supported.
Dirk Eddelbuettel
While this is quite interesting proposal (I did not know about /usr/lib64) it still wouldn't work -- files in /usr/share/doc and the package names, which are the same between archs, would still collide.
Ivan Vučica
A: 

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?

Dirk Eddelbuettel
But it doesn't.
Thomas
His CPU does **not** support 64bit.
LiraNuna
Which is why I amended my answer.
Dirk Eddelbuettel
I simply don't have the resources available to get any kind of new machine. I'm in desperate need of any desktop as-is (I daily work on a 3yr old cheap laptop on verge of breakdown) yet I can't afford it. Still, I want my software to at least compile on 64-bit.
Ivan Vučica
That's a completely different story story. Writing portable code is not dependent per so on access to another machine (though that helps with testing).
Dirk Eddelbuettel
I only need this to devise a proper method to allow compiling on both 32- and 64-bit compilers, and to occasionally test if I broke it -- I don't dream about doing further testing than that :-)
Ivan Vučica
+2  A: 

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).

LiraNuna
This looks precisely like the thing I need! Can you specify in greater detail how to install the libraries in parallel with the 32bit ones? I'm currently pained by libgmp3-dev, which on i386 does not include the 64-bit header (they have differing headers per arch).
Ivan Vučica
I'm not sure about libgmp3-dev, but most (all?) of the dev packages install both 32bit and 64bit if multilib support is present (i.e gcc-multilib/g++-multilib is installed). Try reinstalling (`sudo apt-get install --reinstall libgmp3-dev`) and see if you can compile.
LiraNuna
Unfortunately, reinstalling libgmp3-dev, as expected, still didn't install /usr/include/gmp-x86_64.h (as far as I know, contents of a package do not depend on the other packages installed). I'll try filing a wishlist bug report so that they include 64-bit header. Also, as far as I can tell, only one version of lib*.a is installed in most -dev packages, perhaps 32-bit libs can be linked with 64-bit code?
Ivan Vučica
Did further testing. Mesa OpenGL libraries have valid headers, but don't link properly (well, was sorta expected, wasn't it?) so even the configure phase does not pass.
Ivan Vučica
A: 

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

VitalieL
While very promising, this also failed. ...P: Extracting libslang2 \nP: Extracting util-linux \nE: Execution failed: Exec format error \nE: Internal error: install \nE: cdebootstrap failed \nW: Aborting with an error \nI: cleaning the build env \nI: removing directory /var/cache/pbuilder/build//16153 and its subdirectories \n
Ivan Vučica