How to change compiler of OpenMPI - gcc

I have OpenMPI which is using gcc to compile. I need to cross compile from an x86_64 host architecture to an aarch64 target architecture. Instead of using gcc to compile, I want to use aarch64-linux-gnu-gcc to cross compile.
Anyone know how to change the compiler from gcc to aarch64-linux-gnu-gcc?
Thanks in advance.

openmpi allows using their mpi-wrappers (i.e., mpicc, mpic++, ...) with a different compiler by specifying:
OMPI_CC=COMPILER_NAME_OR_PATH
OMPI_CXX=COMPILER_NAME_OR_PATH
e.g.,
OMPI_CC=clang
OMPI_CXX=clang++
or
OMPI_CC=/usr/bin/gcc-11
OMPI_CXX=/usr/bin/g++-11
In some cases, you might need to export these variables by prepending the export keyword.

Related

AVX and newer intrinsics with GCC on Mac; what assembler would one need?

I have been tweaking GCC 6.3.0 to get it to use the libc++ runtime instead of libstdc++ so that g++ can be used without worrying about C++ runtime incompatibilities:
https://github.com/RJVB/macstrop/tree/master/lang/gcc6
The tweak works, I can build and run KDE software using g++ against Qt5 and KF5 frameworks (and everything else) built with various clang versions.
What doesn't work is generating code that uses AVX and presumably most or all newer intrinsic instructions.
This is not a new issue that's never been invoked on here; it's answered here for instance: How to use AVX/pclmulqdq on Mac OS X
Evidently one can configure gcc to call the linked script instead of the actual as executable.
But can gcc not be configured to use another assembler altogether, like nasm, and would that solve this issue?

arm gcc by default compiling its libc

I am trying to compile an SDK with the an embedded arm gcc compiler in cygwin. It is a makefile based SDK. My target is a cortex m3 device. My problem is, the SDK has a custom libc implementation for the target, and when I compile with the arm compiler (arm-none-eabi-gcc) it looks to pick up the gnu arm libc, not the SDK libc. This is resulting in a compilation error. I am positive the makefiles are correct (I copy and pasted the entire SDK from a computer where this was working). I no longer have access to that computer to try and verify / compare settings. I don't know how to prevent the arm gcc compiler from looking for its own implementation of the libc and instead point it to the correct implementation. Any help is greatly appreciated.
There are perhaps two solutions:
Create an environment specific to your tool - the GNU toolchain uses a number of environment variables to define default behaviour. For a custom toolchain, you will need to set all necessary variables to override the system defaults.
Use the -nostdlib linker option and explicitly link your desired library and C Runtime start-up code, so your linker command line might include the following:
-nostdlib -L/usr/myarmtools/gcc/lib -lc crt0.o
Note that -nostdlib suppresses the default linking of libc libstdc++ and crt0.o, so you must provide search path (-L) to the libraries, or explicitly link them by their full path and file name and link the C runtime object code for your target.
I use option 2 for preference as it will work in any environment. However if you wish to use common makefiles for building for multiple targets, option 1 may be useful.

debug the environment used by make and port gcc from source

I know how to build gcc from source, what I still have to figure out is what are the exact environmental variables used by gcc when configure and building gcc itself, I'm actually trying to build the compiler from source using another version of gcc with different ABI.
Any idea on how to get this kind of information beside "try to grep all the variable that starts with $ inside all makefiles and configuration files" ?
You can see a list of Environment Variables Affecting GCC.
To create a completly independent gcc with a new toolset, have a look at LFS, they explain how to build gcc from an existing OS for a future OS.
There is also a page about building gcc, which talks about BOOT_CFLAGS='-O' and CFLAGS_FOR_TARGET and STAGE1_TFLAGS and BUILD_CONFIG. There is also some additional variables for cross-compiling and ada compiler.

Gcc compilation for different targets

I was just trying to understand something about cross compilers which made me ask this question.
gcc is a cross-compiler.
By default what it the target architecture for gcc compilation if none is specified is the native target on which I am compiling the source. Correct ?
If the above is correct then how does it manage to generate the code for several different architectures even when it is explicitly specified ?
Shouldn't it have to know all the ISA's ? How is this managed ? Do they have all the information for all the existing ISA's ?
A given (particular) gcc is built for a particular given target. Use gcc -v to find out which.
Often, cross-compilers are installed as different commands, e.g. avr-gcc on Debian for the Atmel AVR processor (with specific options ...)
On some architectures and systems (typically x86 & Linux) you may compile for a different variant. See this. In particular you may want to use -mtune=native or -march=haswell or -m32 ...
If you build gcc yourself from its source tarball, you'll give it at configure time specific configure options (e.g. --program-suffix=-avr and --target=avr for the avr-gcc etc....)

custom built gcc 4.6.0 on ubuntu 11.04 links wrong libstdc++

my custom built gcc 4.6.0, installed in my home directory, on ubuntu 10.04, links the system libstdc++ instead of the custom built one, most of the time (as evidenced by ldd). to be more puzzling, using this newly built gcc, custom compiled openmpi libraries are linked correctly, and this is the only software i have compiled that behaves ok. does anybody have any explanation for this, or a workaround?
thanks
Isn't there an option to statically link the libstdc into the gcc when you configure it? --disable-shared if I understand how it works correctly. Worst case make another compile of gcc with that switch and see if you run into the issue.
I don't know why this isn't detailed more clearly on the GCC website for end-users. The GCC FAQ clearly states this is a common problem wrt libstdc++. Environment variables are troublesome. Wrapping the linker, nobody knows how to do that. Editing /etc/ld.so.conf isn't an option. Adding -Wl,-rpath everywhere, come on. The easiest solution is the specs file. For a typical 64-bit x86 Linux system, go into your custom gcc installation, in dirname `g++ -print-libgcc-file-name`and then run g++ -dumpspecs > specs. Edit that file, find the *link_command: section. After %(link_libgcc) add -rpath /home/user/bin/gcc-9/lib64 (of course use your own path). Or add the same rpath to end of *link: section. Alternatively, configure gcc with --with-specs='%{!static:%x{-rpath=/home/user/bin/gcc9/lib64} %x{-enable-new-dtags}}' . Enjoy your own C++ compiler that generates binaries that just work.
See also:
GCC specs file: how to get the installation path
Linking g++ 4.8 to libstdc++
How to configure libstdc++ with GCC 4.8?

Resources