Cross-compiler for Linux on Mac OS X? - linux

I've been reading lots of documents on the internet about creating a cross compiler for linux on mac os x but can't seam to get any to work.
It seams as if no one can help me with the question: Getting GMP to work with GCC 4.5.2
Is there any easy'er way to create a cross compiler?

You need to:
install the xcode base build tools
install the optional xcode command line tools
install homebrew
install the homebrew build tools
4.1 brew install crosstool-ng mpfr gmp grep
4.2 brew tap homebrew/dupes
create a case sensitive volume using "disk utility"
use this volume to build the tool chain itself
6.1 generate a base configuration (for me this is an arm cortex a8)
6.1.1 ct-ng arm-cortex_a8-linux-gnueabi
6.2 use menuconfig (ct-ng menuconfig) to tweak the configuration
6.2.1. disable fortran and java (c compiler)
6.2.2. turn off static linking (c compiler)
6.2.3. change the paths to be on the volume you created above (paths and misc options)
6.2.4. remove dmalloc (debug facilities)
6.3 invoke the build:
6.3.1 ulimit -n 1024
6.3.2 ct-ng build
with much thanks to the crosstools-ng list.

In order to build binaries for architectures different that your build host, you need far more than just a cross-compiler - you need a full-blown toolchain, which can be a real pain to create, as you probably discovered.
A couple of approaches:
Use a proper Linux distribution in a virtual machine, such as VirtualBox. If you only want to build binaries for Linux/i386 on an MacOSX/x86_64 host, this is - in my opinion - the easiest, safest and most clean solution. It is not a cross-compiler, of course, but it works and it has the added advantage that you can actually test your executables.
Use a script such crosstool-NG (a descendant of the original crosstool) to automatically build the toolchain - definitely easier than building it on your own, although you may have to compromise for slightly older compiler versions.

Related

How to safely reconfigure gcc on my Linux system?

I am trying to install a program on CentOS 6.10 and at the end of the installation, it gave an error saying that Glibc-2.14 is necessary. I upgraded the current Glibc and this time the error below occurred:
* These critical programs are missing or too old: gcc
* Check the INSTALL file for required versions.
I upgraded the gcc and tried to configure again. However, the same error persists. Hence I read the INSTALL file as it suggests, and I see this section:
You may also need to reconfigure GCC to work with the new library. The
easiest way to do that is to figure out the compiler switches to make
it work again (`-Wl,--dynamic-linker=/lib/ld-linux.so.2' should work
on GNU/Linux systems) and use them to recompile gcc.
So should I go to where gcc is built and do:
$ ./configure -Wl,--dynamic-linker=/lib/ld-linux.so.2 ?? Do I understand the instructions correctly? If so, then how will I be able to configure only gcc and not the other executable files as they are all in the same folder? (e.g gcc-5, git, idle, python, python-build.. etc) The directory is something like: home/linuxbrew/.linuxbrew/bin/gcc
I'm asking this because GNU compiler and GCC are fundamental in Linux system, and I'm not sure if those are the correct steps.
You are probably using a really old compiler (the one that comes with CentOS by default).
You need to install Red Hat Developer Toolset which provides up-to-date versions, see https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ for more details:
Developer Toolset is designed for developers working on CentOS or Red Hat Enterprise Linux platform. It provides current versions of the GNU Compiler Collection, GNU Debugger, and other development, debugging, and performance monitoring tools.

How can I obtain a newer GCC? I don't have root, and can't compile it (memory error)

I have a shared account on a machine that is running an older version of GCC. I do not have root. When I try to compile GCC, my build process gets killed due to memory usage from the following command:
build/genattrtab ../../../work/gcc-6.1.0/gcc/common.md ../../../work/gcc-6.1.0/gcc/config/i386/i386.md insn-conditions.md \
-Atmp-attrtab.c -Dtmp-dfatab.c -Ltmp-latencytab.c
I'd really like to be able to compile some software on this machine that requires a newer GCC. Any suggestions are appreciated.
You can manually unpack one of the GCC packages for any major distribution, try to use the package that closely matches your distribution. These installable packages are just tar files with some meta data and install script. You can unpack them and extract binaries that you'll need. Just keep in mind that you might need to more than just gcc package. Some distributions chop their devtools into tons of small packages ( gcc, g++, binutils, gdb)
Another good source is to use pre-build gcc toolchain used by embedded vendors, sometimes these vendors include host version of gcc together with cross-compiler. For example Android NDK is one of such distributions.
Finally, you can compile GCC on another machine that is not so restrictive and copy the resulting binaries to your restrictive machine. As in case of the first approach of unpacking installable package, try to find machine that resembles your restrictive machine as close as possible. You can use tools like vagrant and docker to set-up close replica of your target machine. Vagrant and docker have a lot of pre-built templates that you can use as a jump start to create the machine you need.

Can you build Rust for old (Redhat 5 vintage) Linux?

Redhat 5 has the required 2.6.18 kernel but not the latest glibc, g++ and certainly no clang. The binary distribution doesn't run, complaining about glibc version.
Has anyone made an attempt to back port to old Linux? I could imagine cobbling together a frankensystem with an old kernel but new compilers and try to compile against old glibc or statically compile in some of new glibc but it seems like a fraught course.
Just wondering if anyone has tried and can offer guidance?
I'm thinking there must be a distro setup to do such builds. Anaconda, for example, includes lots of new technologies but works fine on Redhat 5. I wonder how they build it?
Update: Once you get some newer compilers working on RHEL5 it's still not possible to build Rust because it depends on a working binary of itself to bootstrap. See: https://github.com/rust-lang/rust/issues/9545#issuecomment-54865031
Anaconda packages are built against CentOS 5 (which is equivalent to Redhat 5). The important thing is to compile against an old enough glibc, as it is strictly forward compatible (as you saw). The version of glibc is typically tied to the version of the distro, so your best bet is to make a VM with CentOS 5 and build on that.
The version of the compiler used is not as important, and in fact in some cases it is necessary to use a newer compiler than the old one that comes with the system to get things to work. I have gcc 4.8 built for CentOS 5 which you can get with conda (conda install -c asmeurer gcc).
I hit this very issue this weekend, because Skylight supports Linux 2.6.18, including CentOS 5.10, and we use Rust in our agent.
Alex Crichton of the Rust core team was kind enough to get this working again by using CentOS 5.10 boxes for the build, which uses glibc 2.5 and Linux 2.6.18.

Compile for CentOS on Ubuntu

Can I install an older version of gcc/g++ (4.1.3) on the latest Ubuntu (which comes with 4.4.3) and use it to compile a .so which should run on CentOS? The binary compiled with the Ubuntu version of gcc fails to load on CentOS because of missing imports (GLIB_2_11, ...). I need C++ (including exceptions), so I can't just statically link against glibc, which I already tried.
Can I install the older gcc without removing the newer one? How do I go about the libs required by the older gcc?
I'm currently developing code in CentOS, but it's such a pain to use. I really want to move to an Ubuntu desktop.
g++-4.1 is available for Ubuntu; just run apt-get install g++-4.1 then run g++-4.1 instead of g++. However, simply using an older compiler may not fix all of your library issues.
Like Joachim Sauer said, your best bet is to do your development on Ubuntu then do the final compilation on CentOS.
Even though you're using C++, static linking should still be an option. (However, you're much better off compiling on CentOS and using dynamic linking.)
Edit: A virtual machine is the most straightforward way to build on CentOS, but if you want to avoid the memory and CPU overhead of running a VM and don't care about differences between Ubuntu's and CentOS's kernel, then you can create a subdirectory containing a CentOS or Fedora filesystem and chroot do that to do your builds. This blog posting has details.

How do I use cygwin to cross compile to linux, when I have an application that needs libX11.so, libGL.so, and libGLU.so?

Will I have to use the crosstool that cygwin provides to make the libX11.so, libGL.so, and libGLU.so libraries using their respective source code? Or do you know where I can find them compiled already for crosstool (I'm new to this cross compilation)?
Just for clarification: I'm on a windows 7 machine trying to get my application also to compile for linux systems by using cygwin's cross compilation. The application uses OpenGL. Thanks
To cross-compile for Linux you should install the needed development libs and headers on a linux box[1] and then copy /usr/lib and /usr/include your cygwin environment (e.g. /crosscompiler/linux/...). When you build the cross compiler in cygwin, tell it where those native linux headers and libs are so they'll be used when you compile your app.
[1] If you're looking to run on a wide variety of linux boxes make sure you pick an older linux distro (e.g. Red Hat 9) to ensure your app doesn't have dependencies on very new glibc, etc..
Why do you want to use Cygwin?
There is instructions on the OpenGL Wiki about how to use OpenGL on Windows using MinGW.
MinGW use the same GNU tools that are available on Linux (GCC, GDB, GMAKE, etc.) but produce Windows native executables. So, you shouldn't have trouble compiling your source code on both platforms.
I just ended up building on a native Linux machine.

Resources