[Solved] 32-bit gcc2 and gcc

I’m trying to build my own libraries in a (bare metal) 32-bit installation (works great on an old Netbook, by the way). Now, I am a bit confused about gcc and… gcc there. The system “defaults” to gcc2 (and I think I understand why), but a way more recent gcc version is also available. Just invoking gcc, link after link it points to gcc 2.95.3. However there is also gcc-x86, which points to gcc 13.3.0 (not exactly the latest, but good enough for my needs). By default there is only gfortran-x86. I can either add a link, gfortran, that points to gfortran 13.3.0. Or just add the more recent version to $PATH:

I could also modify my Makefiles slightly instead of messing with $PATH, but I prefer the same Makefiles work in both 64 and 32 bit. So I added the “correct” directory in the beginning of $PATH. That way gcc also points to gcc 13.3.0 instead of 2.95.3:

PATH=/boot/system/develop/tools/x86/bin:$PATH

With that, all my Makefiles work as expected. However I’m not sure that’s the “proper” way to do it. If two versions of gcc are supported, I assume the system already has a way to make the recent gcc version being the “default”. Am I missing something here?

1 Like

Running setarch x86 after opening the Terminal switches to the newer GCC 13,no need to manually edit any files or your PATH for that.

1 Like

Ah yes, stupid me! It has been years I used setarch. That’s exactly what I was looking for. Thank you @nipos.

I set CXX = g++ -x86 in Makefile.

There are many ways to compile in Haiku 32 while keeping the Makefile intact (same as in Haiku 64-bit). For example you can also compile with make CXX=g++-x86 or something similar. But I think setarch x86 is the most elegant, clean way.

You can also switch to clang if you like :grinning_face:

No because I mainly work with Fortran (and C/C++ when I have to, which is the exception rather than the rule). LLVM actually has Flang for that (in fact, there are two Flangs — it’s a mess). There is also the very promising LFortran compiler (based on LLVM as well), but it’s not production-ready.
GCC’s gfortran is the only reliable Fortran compiler for Haiku right now. On GNU/Linux there are several other options (by Intel, NVidia etc), but there is no Haiku support for them. And I’m not sure they can directly compete with gfortan anyway.

According to Implicit Variables (GNU make) the standard variable for Fortran compiling is FC. The linker is still to be defined though.

It is, that’s why I used make FC=gfortran-x86 in the beginning, and it worked fine. I could even modify the Makefile (which has a Haiku section anyway) so that it detects 32-bit and sets FC accordingly, e.g.

ifeq ($(shell uname), Haiku)
	ifeq ($(shell getconf LONG_MAX), 2147483647)
	   	FC=gfortran-x86
	endif
	< other settings here, such as setting Haiku include and lib dirs >
endif

In GNU/Linux and BSDs I use LONG_BIT to detet 32-bit in Makefiles — which is more elegant, because getconf LONG_BIT returns 32 or 64. However LONG_BIT doesn’t seem to exist in Haiku, so LONG_MAX instead will do just fine. Still, setting architecture to x86 and leave the Makefile intact still seems better to me.

Linking is always done with FC as well.