OpenModelica and FMU cross compilation (Linux->Windows) - linux

I would like to compile in Ubuntu a FMU for Windows (32 and 64bits).
I read in the OpenModelica User's Guide Release v1.11.0 (https://openmodelica.org/newss/179-february-6-2017-openmodelica-1-11-0-released):
"Added OMEdit support for FMU cross compilation. This makes it possible to launch OMEdit on a remote or virtual Linux machine using a Windows X server and export an FMU with Windows binaries."
"Cross compilation of C++ FMU export. Compared to the C runtime, the C++ cross compilation covers the whole runtime for model exchange."
How can I do the cross compilation?
Should I install anything to get a Windows option in the "Platform" section?
Thanks!!!
Edited:
"sudo apt-get install mingw-w64" adds the Mingw compilers.
Is it possible to add other compilers? For example: Clang for Windows.

Mingw: sudo apt-get install mingw-w64
The option will appear in the dialog window.

Related

Compile the Fortran program in Windows using gfortran

I have a Fortran program(.f) that I have written in Ubuntu Linux. I compiled the written Fortran program in Linux by using the below command and it it successfully executed.
gfortran -o program program.f
Now I want to execute the same Fortran program in Windows 10 Can it be executed in window system? If so please suggest me a way to do it.
I tried gfortran -o program program.f in Windows command window,but it fails.
To compile Fortran code for Windows you need a Fortran compiler for Windows. Microsoft neither provides a built-in one nor offers one for sale. Third-party compilers are available, including gfortran, but you'll need to install one yourself. If you want to use gfortran in particular, or if you like it simply because you don't have to spend money to get it, then I would recommend obtaining it as part of mingw-w64. Alternatives are available from multiple vendors, some free of charge, but most for sale.
Note also that Windows expects executables to be named with an .exe extenstion, so you would want to use a variation on gfortran your compilation command:
gfortran -o program.exe program.f
If you want to use gfortran on Windows, I suggest you install MSYS2, which has a bash terminal, and a package manager that can install gcc and gfortran, as well as lapack and many other libraries.
There is also a separate distribution of mingw-w64 that can be installed without MSYS2, but I don't recommend it, as the last files there have gcc-8.1.0, from 2018 (apart from a recent build by Ray Linn that includes the Ada, but not the Fortran compiler).
Another compiler that is now free is Intel Fortran : you have to install Microsoft Visual Studio Community, Intel oneAPI Base Toolkit and Intel oneAPI HPC Toolkit. More information here. Available on Linux, macOS and Windows (of course, Visual Studio is needed only on Windows). Intel oneAPI is at least partly open source, not sure about the Fortran compiler.
MSYS2 is a much smaller package (in terms of disk pace needed), and is used by several other free projects: R (Rtools), Octave and Strawberry Perl all include parts of it, including the gcc compilers.

Optimal way to install clang locally when GCC is outdated

I need to use tools that depend on clang on a Unix machine I remote onto at work. Anything I install is locally installed onto ~/local. I do not have root permissions.
/usr is pretty outdated, with gcc being at version 4.4.7. clang requires gcc 4.7+
I read on linux from scratch that a gcc 6.1 installation requires 8.4 gb. This is not something I can do, because that's huge.
Can someone advise me on the best workaround to install up to date clang on my ~/local?
Please and thanks.
Edit:
Courtesy of Nishant, here is the short answer:
Set up a personal machine running the same linux distro and cross compile using gcc to your specific architecture. For me, I will run a Redhat 6.5 VM and compile using gcc an arm x64 binary. Thanks Nishant!
You can get pre-build binaries for Unix system from LLVM's release website: http://llvm.org/releases/
You can then put the binaries in any local folder you want and source it using the PATH variable, which can be done by modifying your ~/.bashrc file by appending:
export PATH=$PATH:<clang-binary-directory>
Now you will able to use clang from the command line terminal as if it was installed.
If you want to build from source only, you can get older source code of clang which will use gcc 4.4.7 and build it and then use clang to build clang. Or get the latest clang binary and use it to build latest clang.

How to cross-compile a autotools project for ARM?

I am looking to cross-compile an existing library which uses GNU autotools build system. I have a Linaro arm-gcc toolchain installed in my host machine and I am able to compile small programs directly using arm-gcc.
Host machine: Ubuntu 12.04 Intel x64
Target machine: Ubuntu 14.04 ARM 32-bit (a board similar to Raspberry-Pi)
I have a library source code which has configure.ac and Makefile.am files for it. I want to compile this code on host machine and generate ARM binaries which can be copied over to the target platform.
What is the canonical way to do this?
For specifics, I am looking for something that would work for a "Hello World" application/library in C cross-compiled using arm-linux-gnueabi-gcc and autotools.
--build=`./config.guess` --host=arm-linux-gnueabi
might be sufficient, as it will look for a corresponding ARM toolchain. Otherwise, try adding: CC="arm-linux-gnueabi-gcc"
You can also add: CFLAGS="-pipe -Wall -O2 ... <other arm-gcc flags>"
for better code optimization.
The right way to do this on Ubuntu is to the use the distro-supplied cross-compiler, not a 3rd party one like Linaro. You only need an out-of-distro package when the distro one is not good enough for some reason (like you need some cutting-edge feature which is only in the Linaro toolchain and not yet in the distro). Hardly anyone needs to do that.
Install the gcc, g++ crosstollchains, a cross libc and some config tools with:
apt install crossbuild-essential-armhf
If the software you want to build needs nothing more than the C runtime library then you can build it as is. If it needs anything more then you need to install cross-build-dependencies.
If the software you want to build is packaged (and called $packagename), you should be able to:
dpkg --add-architecture armhf
apt update
apt build-dep $packagename
then build it with
dpkg-buildpackage -aarmhf
If it's not packaged you'll need to install build-dependencies, libraries for arch armhf, tools for the native arch (usually amd64 or arm64). For example:
apt-get install sgmltools ghostscript libpng-dev:armhf libssl-dev:armhf
would install native ghostscript and sgmltools (for doc-building) and headers/libraries for libpng and libssl for armhf.
More details on the Debian wiki.

Installing gcc on linux without c compiler

How can I install gcc on a system that have not any c compiler?
this system is a linux base firewall and have not any c compiler.
I guess you a have an appliance running Linux and shell-access, but neither a package manager nor a compiler is installed.
So, you need to cross-compile gcc and the whole toolchain (at least binutils) - this is quite simple, because the ./configure scripts of gcc, binutils, gdb etc. support cross-compiling with the --target= option. So all you have to do is to find out the target architecure (uname helps) and then download, unpack the gcc sources on a linux-host and run ./configure --target=$YOUR_TARGET.
With this, you now can build a cross-compiler gcc - this still runs on your host, but produces binaries for your target (firewall appliances).
This may already be sufficient for you, a typical desktop PC is much faster than a typical appliance, so it may make sense to compile everything you need on the Desktop PC with the cross-compiler and cross-binutils.
But if you really wish to do so, you can now also use your cross-compiler to compile a gcc running on your target (set this as --host= option) and compiling for your target (set this as --target option).
You can find details about allowed host/targets and examples in the gcc documentation: http://gcc.gnu.org/install/specific.html.
It depends on the distribution, if it's based on debian or some other of the big ones you can install gcc through apt-get or similar tool.
If it's a more basic system you need to compile gcc yourself on another computer and copy it over. It will be easiest if you have another computer with the same architecture (i386, arm or x86_64 for example).
I think that you might want to compile it statically also, so that you don't have dependencies on external libraries.
How do you plan to get all the source code needed for GCC loaded onto your machine? Could you mount the ISO image onto this machine and install from there?
Since you are using Endian Firewall, see "Building a development box" at the following link:
http://alumnus.caltech.edu/~igormt/endian/tips.html
If it's a debian based distribution, you can use
sudo apt-get install gcc
Note: maybe you must change "gcc" by a specific version of the debian package.

Which cross compiler?

What is the difference between
MinGW cross compiler and
GCC Cross compiler.
Which one used in which operating system?
I need to create an EXE file in the Linux operating system using Qt, hence which is the cross compiler to be used?
MinGW is a GCC cross compiler for Windows environments. (There are multiple GCC cross compilers for various different targets.)
To compile Windows executables on your Linux box, you want a MinGW install for your distribution of Linux.
If you're running
Debian, you want http://packages.debian.org/lenny/mingw32 (apt-get install mingw32)
Ubuntu, you want http://packages.ubuntu.com/jaunty/mingw32 (apt-get install mingw32)
Red Hat Linux or CentOS, you want several of the MinGW packages from http://download.fedora.redhat.com/pub/epel/5/i386/repoview/M.group.html (see EPEL how-to then yum install mingw32-binutils and mingw32-gcc-g++ at minimum)
Gentoo, see http://www.gentoo-wiki.info/MinGW
openSUSE, then you can find builds at http://download.opensuse.org/repositories/CrossToolchain:/mingw/
MingW32 is a port of GCC with "win32 target".
There are two architecture in a cross-compiler: host and target. The host is the platform the compiler run on; the target is what the result code will run.
Assume you are using Ubuntu, you can see the package here.
MinGW is basically a port of GCC and related tools, allowing them to run natively on Windows machines.
Cross compiling is the act of using a compiler on one operating system/architecture to generate a binary/EXE/DLL/object that is compatible with another operating system/architecture. Basically, you ask the compiler to generate assembly and startup routines for something other than the host OS's default.
If you were on a Linux machine, you'd use GCC to compile it for the Linux machine... If you were on a Windows machine, you'd use MinGW, but with flags to tell it to compile for the Linux machine's specifications.
GCC is usually used in Linux.. MinGW is just a Windows port of GCC to compile source to EXE files.

Resources