How to cross-compile with .gpr project file and gprbuild? - compilation

I'm trying to cross-compile from Linux (Fedora 29) an Ada program with Windows as target. I have no knowledge about compilation and the Gnat project manager doc couldn't help the noob I am.
I would prefer to use switches inside the project file and keep the command the simplest possible. What should I do?
I tried gprbuild -P logfilter.gpr --target=Windows which leads to
Error: no compiler found for language 'c', target = Windows, default runtime
Error: no compiler found for language 'ada', target = Windows, default runtime
logfilter.gpr:3:09: warning: no compiler specified for language "Ada", ignoring all its sources
logfilter.gpr:7:19: "log_filter_main.adb" is not a source of project "logfilter"
gprbuild: problems with main sources
Here is my gprconfig:
prconfig has found the following compilers on your PATH.
Only those matching the target and the selected compilers are displayed.
1. GNAT for Ada in /usr/bin/ version 8.3 (default runtime)
2. GCC-ASM for Asm in /usr/bin/ version 8.3.1
3. GCC-ASM for Asm2 in /usr/bin/ version 8.3.1
4. GCC-ASM for Asm_Cpp in /usr/bin/ version 8.3.1
5. LLVM for C in /usr/bin/ version 7.0.1
6. GCC for C in /usr/bin/ version 8.3.1
7. G++ for C++ in /usr/bin/ version 8.3.1
and my gprconfig --show-targets:
List of targets supported by a compiler:
x86_64-redhat-linux
x86_64-unknown-linux-gnu
here is my file.gpr:
with "../../lib/gnat/gtkada";
project LogFilter is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Exec_Dir use "exec";
for Main use ("log_filter_main.adb");
package Builder is
for Executable ("main.adb") use "Logs_Filter";
end Builder;
package Compiler is
for Switches ("ada") use ("-gnat2012");
end Compiler;
end Logfilter;

Once I did this with Fedora 24. But this required to build a cross compiler. I still have a docker image
and patches for fedora packages
I filled a request on fedora to include ada in windows in cross compiler, but they closed it. I'm unable to find the bug number, however.
Tell me if you are interested in fresh version of this or instructions how to use.
Update: I've rebuilt cross for FC29. You can try it this way:
dnf copr enable reznik/ada
dnf install mingw64-gcc-gnat
dnf install gprbuild
sed -i -e 's/-pc-mingw/-w64-mingw/g' /usr/share/gprconfig/*
cat > hello.adb << EOF
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line ("Hello");
end Hello;
EOF
cat > hello.gpr << EOF
project Hello is
for Main use ("hello.adb");
end Hello;
EOF
gprbuild --target=x86_64-w64-mingw32 -P hello.gpr
file hello.exe
hello.exe: PE32+ executable (console) x86-64, for MS Windows
PS: link to copr

As others have pointed out, the issue you're encountering is because you're not using a cross compiler.
Just to clarify something about gprbuild that might make this clearer: gprbuild is just a front-end for the versions of gcc and gnat on your system. Essentially it's just an Ada-specific analogue of make. It processes the project configuration file and works out what parts of the project to be built. From the gprconfig output it looks like you're using the FSF GNAT obtained from the Fedora repos. gprconfig --show-targets is only showing you the targets of the native Linux compilers that it's found in your $PATH.
To solve your problem you'll need to find an Ada compiler targeting Windows. AdaCore provide a pretty decent native Windows compiler if that's an option for you.

Related

I installed Nim without any problem, but it gives me this error, what should I do?

I install Nim Lang but it not works. I get this errors, how can i fix? (I have completed the setup.)
Error: invocation of external compiler program failed. Sistem belirtilen dosayayi bulamiyor.
Additional info: "Requested command not found: \'gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -I\"C:\\Program Files\\Nim Language\\lib\" -IC:\\Users\\SyTax\\Desktop -o C:\\Users\\Sytax\Desktop -o C:\\Users\\SyTax\\nimcache\\name_d\\stdlib_io.nim.c.o C:\\Users\\SyTax\\nimcache\\name_d\\stdlib_io.nim.c\'. OS error:" 2
Error;
enter image description here
Probably you only installed the first package from Nim's windows installation page. Note that there are other dependencies mentioned on that page. You may also need:
MingW compiler dependency, installed with finish.exe.
DLLs available on your system, like PCRE or OpenSSL, also available for download.
Alternatively you could try installing Nim using Scoop, which seems to be able to install both Nim and the required compiler.
The Nim compiler creates C code, so to compile your code to binary and run, you should install a C compiler. The default is GCC. In linux and mac, it comes with the system, so I am assuming you are using windows.
I am not a Windos user, but AFAIK you neet to install mingw amd gcc
http://www.codebind.com/cprogramming/install-mingw-windows-10-gcc/
http://mingw.org/

GCC /clang not present on BSD, and unable to install it

I have a freebsd 8.4 machine. I want to use to use pyinstaller to create a binary for freebsd. However it looks like pyinstaller does not support freebsd by default so i have to go in the bootloader and create stuff specific to the target system.
This is giving me errors that gcc/cc is not found on the system. Here is the first error message
Platform : FreeBSD-64bit detected
Checking for 'gcc' (C compiler) : not found
Checking for 'clang' (C compiler) : not found
So then i try to install gcc via ports. I do this
cd /usr/ports/lang/gcc49
make install
It fails :
checking whether the C compiler works... no
So i checked in the file system and there is no gcc or clang or cc. It only has ccache. Here are the details from /usr/bin
CC -> /usr/local/bin/ccache
gcc -> /usr/local/bin/ccache
There is nothing in /usr/local/bin (either CC or GCC)
so if i just do gcc at the command line i get this :
ccache: FATAL: Could not find compiler "gcc" in PATH
how do i fix this. This thing is driving me nuts. pkg install is also not working with error "No repositories found "
On FreeBSD 8.4 the standard compiler is gcc (4.2), and it's located in /usr/bin. It has to be there.
It seems that ccache installation created some problem removing/overwriting something. ccache package installs compiler links in /usr/local/libexec/ccache, but if you installed it manually I'm not sure what happened.
FreeBSD 8.4 is not maintained anymore and there's no package repository anymore for it.
My suggestion is to update your system to FreeBSD 10.2 and use clang, that's the new standard compiler.

What do you need to install to use Clang on windows to build c++14 for 64 bit?

UPDATE:
I've written a detailed tutorial that incorporates the top two answers on this question: http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt1/
TL;DR
On Windows, Given the following program:
#include <iostream>
int main()
{
int arr[] = {1, 2, 3, 4, 5};
for(auto el : arr)
{
std::cout << el << std::endl;
}
return 0;
}
I want to be able to do the following:
clang++ hello.cpp -o hello.exe -std=c++14
And get a 64 bit executable that just works. I don't want to have to append a ton of -I includes to tell clang where to find iostream or other standard c++ headers; I don't want to have to link in multiple steps.
I don't care so much about performance, efficiency, what linker is used, etc. I just want to be able to have clang/gcc/whatever set up correctly so that I can use a single, quick and dirty, console command like the one above.
What do I need to install for that to just work?
The Problem
As a predominately mac/linux user I'm used to being able to just use a package manager to install the latest version of clang, which just works.
I'm now trying to set up clang/gnu compiler on windows and it seems to be far more difficult, If only because there is little to no straightforward documentation out there (that I've been able to find)
I've tried to follow this tutorial: https://yongweiwu.wordpress.com/2014/12/24/installing-clang-3-5-for-windows - and was able to use it to get clang to build and link (using gcc 4.8.2), but the resulting binaries were 32 bit.
I've tried installing the latest prebuilt binaries of clang (3.6.2) and the 64 bit version of mingw-w64 (4.9.3 for 64 bit with posix and sjlj for exceptions), and am getting:
hello.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Which seems to indicate that clang is not seeing gcc's files. It seems that some versions of LLVM/clang are looking for only certain versions of gcc, but that doesn't seem to be documented anywhere?
Similarly someone mentioned to me on the LLVM IRC that you need to modify clang's driver to look for gcc in certain paths?
What I'm looking for
I'm fine with building LLVM/Clang from source if necessary, but I'm really just looking for clear, step-by-step instructions that allow me to use clang++ as easily as I'm able to do with mac/linux
Something like:
Build this version of LLVM/Clang and place it in that directory
Download and install this version of cygwin (or mingw32 or mingw-w64) and install these packages.
etc..
Try installing MSYS2 and then installing the mingw-w64-x86_64-clang (binary) package:
pacman -S mingw-w64-x86_64-clang
It is a bit old at the moment (3.6.2), but it might be good enough for you. Then when you run the Win64 shell provided by MSYS2, clang will be on your path.
If it's not good enough, I have recently been building a 64-bit version of clang with MSYS2 and using it to compile native 64-bit Windows executables. My process was something like:
Use pacman to install base-devel, mingw-w64-x86_64-ninja, mingw-x86_64-cmake and perhaps some other packages that are needed by the build process.
Grab my PKGBUILD script for clang and the files in the same directory. This is based on the mingw-w64-clang-svn package from MSYS2, which is largely the work of Martell Malone. You can find him on the MSYS2 IRC channel and ask him more about it.
In a Win64, shell, go to the directory with my PKGDUILD, run export MINGW_INSTALLS=mingw64 (so you are only compiling the 64-bit version), and then run makepkg-mingw.
It is unlikely you will get everything right on the first try, and some files might need to be edited. Clang may have changed since the last time I did this and some patches might not apply cleanly.
if you use the upcoming clang 3.7.0, simply set PATH to include mingw-w64's bin, clang will work as you expect
You can install llvm pre-release binary for Windows here. MinGW-w64 can be downloaded here. Of course, you should make sure the paths are properly set up.
For the latest version of clang, e.g., clang 6.0.0. The above solution by #user5271266 will not be enough. Now the default target for clang Windows is x86_64-pc-windows-msvc (Assume that you are using 64 bit Windows).
In order to compile C++ source files, according to here, we should change the target:
clang++ -target x86_64-pc-windows-gnu -std=c++14 test.cc -o test.exe

Default compiler from llvm-clang to llvm-gcc42 (command line)

I'm trying to compile a project from the command line. The default compiler LLVM-clang and i need to compile with LLVM-gcc42. Switching a compiler in Xcode is really easy. However, on command line it seems to be more problematic. To my understanding "/usr/bin/cc" and "/use/bin/gcc" are used for pointing c/c++ compilers. I noticed that "cc" was linked to "clang" in same directory. So, i changed "cc" to point at "gcc". Did not helped. When i run
$ gcc -v
i get response
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.5.0
How do i change the clang to gcc?
My setup is:
MAC OS X 10.8.5
Xcode 4.6.2
Command line tools
EDIT 13.02.2014
The project is a QT project which uses mixture of third party c/c++ libraries. My task is to write a new objective C lib to it. The project is build with -spec macx-g++ parameter. The configuration scripts can be found /QTROOT/mkspecs/macx-g++ and /QTROOT/mkspecs/common. In g++-base.conf key variables are defined as:
QMAKE_CC = gcc
QMAKE_CXX = g++
Instead of changing links which can affect other programs use the full path to the llvm executables in your build script
e.g. if you have installed the command line tools
QMAKE_CC = /usr/bin/llvm-gcc-4.2
QMAKE_CXX = /usr/bin/llvm-g++-4.2
Okay, nailed the problem. Solution was simple. I deleted the old links from /usr/bin/gcc and /usr/bin/g++ and created new ones pointing to the proper compilers.
gcc -> /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
and
g++ -> /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-g++-4.2

Haskell package missing c library

I'm having trouble building the hmatrix library on OS X Lion. Looking at the .cabal file, it requires the gsl library, so I installed it with macports. The .a files are in /opt/local/lib and the .h files are in /opt/local/include/gsl
As suggested here I changed the built-type from Custom to Simple. (without that change I get a similar error).
When I use cabal configure I get the following output:
* Missing C library: gsl
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
So I tried cabal --extra-include-dirs=/opt/local/include --extra-lib-dirs=/opt/local/lib configure, but I still get the same error. I can compile and link a c program that includes gsl. What files is cabal looking for? If I have the right files, how do I tell it how to find them?
libgsl.a is a universal binary:
$ file /opt/local/lib/libgsl.a
/opt/local/lib/libgsl.a: Mach-O universal binary with 2 architectures
/opt/local/lib/libgsl.a (for architecture x86_64): current ar archive random library
/opt/local/lib/libgsl.a (for architecture i386): current ar archive random library
ghc looks like it's 64-bit:
$ ghc --info
[("Project name","The Glorious Glasgow Haskell Compilation System")
,("GCC extra via C opts"," -fwrapv")
,("C compiler command","/usr/bin/llvm-gcc")
,("C compiler flags"," -m64 -fno-stack-protector -m64")
,("ar command","/usr/bin/ar")
,("ar flags","clqs")
,("ar supports at file","NO")
,("touch command","touch")
,("dllwrap command","/bin/false")
,("windres command","/bin/false")
,("perl command","/usr/bin/perl")
,("target os","OSDarwin")
,("target arch","ArchX86_64")
,("target word size","8")
,("target has GNU nonexec stack","False")
,("target has subsections via symbols","True")
,("Project version","7.4.2")
,("Booter version","7.4.2")
,("Stage","2")
,("Build platform","x86_64-apple-darwin")
,("Host platform","x86_64-apple-darwin")
,("Target platform","x86_64-apple-darwin")
,("Have interpreter","YES")
,("Object splitting supported","NO")
,("Have native code generator","YES")
,("Support SMP","YES")
,("Unregisterised","NO")
,("Tables next to code","YES")
,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn")
,("Leading underscore","YES")
,("Debug on","False")
,("LibDir","/usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2")
,("Global Package DB","/usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2/package.conf.d")
,("Gcc Linker flags","[\"-m64\"]")
,("Ld Linker flags","[\"-arch\",\"x86_64\"]")
]
As an alternative to mac-ports you can use the nix package manager for mac. It does a pretty good job of taking care of the c dependancies for for the libraries available through it. In general I have been more happy with it then any other package manager on mac.
Unfortunately mac(darwin) unlike for linux does not have as many binaries available through nix so installing ghc often means waiting for it to compile.
The commands to install ghc and hmatrix after installation of nix are:
nix-env -iA nixpkgs-unstable.haskellPackages.ghc
nix-env -iA nixpkgs-unstable.haskellPackages.hmatrix
All of the needed dependencies will be taken care of for you.
I just tried it on my macbook pro and hmatrix seems to be working correctly in ghci after trying commands from the first few pages of the tutorial.
I'm not a mac person, but it really sounds like you haven't installed the "-dev" version. For a mac, I suspect you need to install gsl-devel in addition to gsl. If the problem persists, verify that you have libgsl0-dev on your library path.

Resources