Getting GMP to work with GCC 4.5.2 - linux

I'm trying to make a cross compiler with the files from http://crossgcc.rts-software.org/doku.php?id=i386linuxgccformac
I'm on an Intel Mac (10.6.6, x86_64) I compiled: gmp, mpfr, mpc for the cross compiler as 32bit (as I'm on a 64bit Mac) but I'm getting
ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file /gmp1/lib/libmpc.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /gmp1/lib/libmpfr.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /gmp1/lib/libgmp.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
When compiling GCC with:
--prefix=/usr/local/i386-linux-4.5.2 --target=i386-linux --enable-languages=c --without-headers --disable-shared --disable-threads --disable-nls --with-gmp=/gmp1 --with-gmp-lib=/gmp1 --with-gmp-include=/gmp1 --with-mpfr=/gmp1 --with-mpfr-include=/gmp1 --with-mpfr-lib=/gmp1 --with-mpc=/gmp1 --with-mpc-lib=/gmp1 --with-mpc-include=/gmp1
Also, if I compile GMP with:
./configure --prefix=/gmp1 --host=i386-linux
I get:
configure: WARNING: +----------------------------------------------------------
configure: WARNING: | Cannot determine global symbol prefix.
configure: WARNING: | link -dump -symbols output doesn't contain a global data symbol.
configure: WARNING: | Will proceed with no underscore.
configure: WARNING: | If this is wrong then you'll get link errors referring
configure: WARNING: | to ___gmpn_add_n (note three underscores).
configure: WARNING: | In this case do a fresh build with an override,
configure: WARNING: | ./configure gmp_cv_asm_underscore=yes
configure: WARNING: +----------------------------------------------------------
checking how to switch to read-only data section... .data
checking for assembler .type directive...
checking for assembler .size directive...
checking for assembler local label prefix... configure: WARNING: "link -dump -symbols" failure
configure: WARNING: cannot determine local label, using default L
L
checking for assembler byte directive... .byte
checking how to define a 32-bit word... link: illegal option -- d

I think that you are confused about which package should be compiled for which platform:
GCC needs to be compiled for an x86_64 MacOS X host and an i386-linux target.
GMP, MPC and MPFR are runtime dependencies for GCC. Therefore they also need to be compiled for the GCC host - x86_64 in your case. Therefore, the --host=i386-linux option in the GMP configure command is incorrect.
In general, only libraries that will be linked in the programs compiled by GCC need to be built for the cross-compiler target (e.g. i386-linux). GMP and MPFR are not such libraries, unless your programs are actually using them - in that case you will need to have two copies of such libraries, one for GCC and a cross-build for the target.
EDIT:
Have you considered using MacPorts? It has all the dependencies for your cross-compiler:
gmp-5.0.1
mpfr-3.0.0
libmpc-0.8.2
There is also an older newlib-based cross-compiler for i386:
i386-elf-gcc-4.3.2
Even if you do not want to use these, you can still have a look at the build instructions in their Portfiles.
The bottom line is:
Apply whatever patches these libraries need - MacPorts already do that.
Compile the libraries for your build host i.e. MacOSX/x86_64. That means that in any --host options for their configure calls you should be something along the lines of --host=x86_64-darwin (or whatever your host needs). If configure can figure out the host on its own, you can skip the --host options altogether.
Compile GCC with --host being your build host (the 64-bit Mac OS X) and a target of i386-linux, e.g. --target=i386-linux. If I were you, I'd start simple with a compiler for the C and C++ languages only.
See also this tutorial. It has some information on how to produce a working toolchain with a proper glibc.
That said, I think that you'd be better off installing a proper Linux distribution in a virtual machine, for a whole bunch of reasons. Is there a reason for you to need a cross-compiler specifically? What do you want to do with that compiler?

Did you use the "ABI=32" option when compiling GMP? If not, I think it will use 64-bit code even if the host/target are specified as i386.

Related

CMake Target Link Library G++ Flags conflict with OSX Clang

I am trying to write a single CMakeLists.txt file for C++ compilation on Linux with G++ and on OSX with Clang.
I want to use the Target Library flags -Wl,--start-group and -Wl,--end-group with G++, but these give an error when linking with Clang: ld: unknown option: --start-group
The only results I can find choose to just delete these flags on Mac copies, but that doesn't allow easy project migration from linux to OSX. I tried to make these statements CMAKE conditions, but those are treated as literal libraries which are not found:
eg: $<IF($<NOT:APPLE>)> -Wl,--start-group $<ENDIF($<NOT:APPLE>)>
produces: c++: error: $<IF: No such file or directory
Is there a way to conditionally edit in the CMAKE TARGET_LINK_LIBRARIES field?
I'd try this:
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(START_GROUP "-Wl,--start-group")
set(END_GROUP "-Wl,--end-group")
else()
set(START_GROUP "")
set(END_GROUP "")
endif()
Then just replace those options with ${START_GROUP} and ${END_GROUP}, and they will only be used with the GNU compiler.
Don't switch based on platform if it's really the compiler that matters. Otherwise, Clang users on Linux won't be able to build your project.

Cross compiling gcc 6.2 for QNX

I'm trying to cross compile GCC or clang for qnx and I am not able to find any good set of instructions that explain cross compiling to other operating systems. I already have access to qnx and a GCC compiler version 4.7 for the target.
I've tried reading http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/ and wasn't successful. I keep running into this error:
checking dynamic linker characteristics... ldqnx.so
checking how to hardcode library paths into programs... immediate
checking for shl_load... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
Makefile:11454: recipe for target 'configure-target-libstdc++-v3' failed
make[1]: *** [configure-target-libstdc++-v3] Error 1
I want to compile the latest stable GCC. The host machine is an x86_64 linux. The target is i486-pc-nto-qnx6.6.0. Any ideas?

configure test with static lib

I am trying to cross compile libpng for RaspberryPi on Ubuntu 14.04 (x_64) with zlib
but configure fails with
configure:11400: arm-linux-gnueabihf-gcc -o conftest -g -O2 -I/home/user/RPI_DEV/lib/include conftest.c -lz -lm >&5
/home/user/RPI_DEV/xtools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
configure:11400: $? = 1
configure: failed program was:
....
Because I am using toolchain for arm, arm-ld cant find zlib.
Is there any option for configure not to compile with shared lib but to try with static lib (eg. -static -lz).
Command is
./configure --enable-static=true --enable-shared=false --with-zlib-include="/home/user/RPI_DEV/lib/include" --with-zlib-lib="/home/user/RPI_DEV/lib/lib" LDFLGS="-L/home/user/RPI_DEV/lib/lib" CPPFLAGS="-I/home/user/RPI_DEV/lib/include" -enable-static --host=arm-linux-gnueabihf --prefix=/home/user/RPI_DEV/lib --exec-prefix=/home/user/RPI_DEV/lib
You need to cross build and install zlib into your toolchain before trying to use it in another project.
What you are doing might work but only if you spell LDFLAGS correctly:
LDFLGS="-L/home/user/RPI_DEV/lib/lib"
Note the missing 'A'. I don't know why your second attempt worked, given you had the same misspelling; possibly you had a correct LDFLAGS in your environment?
Anyway there should be a Ubuntu cross-development guide somewhere that explains how to do this. It's slightly off topic but for Gentoo you use 'crossdev' to install the toolchain then a crossdev specific version of the normal package installation mechanism ([host]-emerge) to install zlib into the toolchain.
Also, the arguments --with-zlib-include and --with-zlib-lib are not supported by any current version of libpng I can find. If you are cross-compiling libpng for an RPi (or, indeed, any ARM system) you should be using the latest version of 1.6 that you can find.
Unless someone solves this the RIGHT way, this is hack I've done.
Open configure.ac file
Find and comment out line
AC_CHECK_LIB(z, zlibVersion, , AC_ERROR([zlib not installed]))
Configure will pass wihout check for zlib and then add zlib by hand
LDFLGS="-L/home/user/RPI_DEV/lib/lib -L/home/user/RPI_DEV/lib/lib/libz.a"
Run autoconf
Run ./configure ...

How to compile ld with custom linker scripts?

i am trying to build a custom version of the linux kernel 3.8 and i want my linker to behave a bit different so i changed its ldscripts.
Specifically I configure binutils -> make -> change ldscripts -> make install.
However when i try to compile libc using my linker the only thing i see is this :
GNU ld (GNU Binutils) 2.23
Supported emulations:
elf32_sparc
sparclinux
elf64_sparc
sun4
using internal linker script:
==================================================
/* Script for --shared -z combreloc: shared library, combine & sort relocs */
etc
The thing is that i have changed my ldscripts and prepended a tag at the beginning of each script in order to recognize them but my compiler does not seem to care.
However i don't have any other elf scripts in my system so the option of searching the wrong library path is not actually an option.
Is there something i am missing here?
Notice that i am cross compiling for sparc
You can pass a custom linker script to ld:
ld -T <path/to/file> ...
or to gcc:
gcc -Wl,-T,<path/tofile> ...
Default ld scripts get compiled into compiler driver (gcc) so you should at least rebuild the toolchain.
That's also probably the case that gcc will not look at any linker scripts other than built into it, so you'll have to modify them in toolchain (it's probably in spec files somewhere).

Unresolved sincos during build of LAPACK

Following the instructions here I have built a Fortran enabled NDK toolchain (OSX, NDK-7b) with the goal of building LAPACK/BLAS.
Using android-cmake with the 3.4.0 net lib source it seems that I'm nearly successful. However, the BLAS build fails when linking one of the tests (with an error stating unresolved sincos and sincosf). A little searching reveals that these functions are not available in legacy Android versions. I'm wondering what is the best way to resolve these functions?
Below is and example of a linking error:
cd /Users/marc/software/lapack-3.4.0/Android/BLAS/TESTING && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/xblat2c.dir/link.txt --verbose=1
/opt/local/share/java/android-ndk-macosx/toolchains/arm-linux-androideabi-4.7.0/prebuilt/darwin-x86/bin/arm-linux-androideabi-gfortran -Wl,--gc-sections -Wl,-z,nocopyreloc -Wl,--fix-cortex-a8 -Wl,--no-undefined -lstdc++ -lsupc++ CMakeFiles/xblat2c.dir/cblat2.f.o -o ../../bin/xblat2c -rdynamic -L/Users/marc/software/lapack-3.4.0/Android/systemlibs/armeabi-v7a -L/opt/local/share/java/android-ndk-macosx/toolchains/arm-linux-androideabi-4.7.0/prebuilt/darwin-x86/user/libs/armeabi-v7a ../../lib/libblas.a -lm -Wl,-rpath,/Users/marc/software/lapack-3.4.0/Android/systemlibs/armeabi-v7a:/opt/local/share/java/android-ndk-macosx/toolchains/arm-linux-androideabi-4.7.0/prebuilt/darwin-x86/user/libs/armeabi-v7a
/opt/local/share/java/android-ndk-macosx/toolchains/arm-linux-androideabi-
4.7.0/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.7.0/../../../../arm-linux-androideabi/lib/libgfortran.a(c99_functions.o): In function cexpf':
/opt/local/share/java/android-ndk-macosx/src/build/../gcc/gcc-4.7.0/libgfortran/intrinsics/c99_functions.c:910: undefined reference tosincosf'
GCC needs to know at compile time whether sincos is available or not. It does so based on the target. In case of the target triplet arm-linux-androideabi, it looks at gcc/config/linux.h and finds there:
/* Whether we have sincos that follows the GNU extension. */
#undef TARGET_HAS_SINCOS
#define TARGET_HAS_SINCOS (OPTION_GLIBC || OPTION_BIONIC)
The reason for the inclusion of Bionic is that Android 2.3 added support for sincosf/sincos/sincosl [1]. Thus, you can either update Bionic or you patch GCC to assume that no sincos is available; cf. also [2].
[1] http://source-android.frandroid.com/bionic/libc/docs/CHANGES.TXT
[2] https://bugs.launchpad.net/linaro-android/+bug/908125

Resources