Crosscompile libdaemon to ARM does not work? - arm

I tried to cross-compile the library libdaemon for an ARM architecture but I'm facing the problem that libdeamon is not being cross-compiled, and I cannot understand why. After cross-compiling (make the ./conf and make install) the library libdeamon, I have been able to check the library isn't crosscompiled for arm,since it's been "crosscomppiled" for the build a intel as it can be seen
:~/libdaemon-0.14$ file -F usr/*/*.*
usr/lib/libdaemon.lausr/lib/libdaemon.a libtool library file,
usr/lib/libdaemon.sousr/lib/libdaemon.a symbolic link to `libdaemon.so.0.5.0'
usr/lib/libdaemon.so.0usr/lib/libdaemon.a symbolic link to `libdaemon.so.0.5.0'
usr/lib/libdaemon.so.0.5.0usr/lib/libdaemon.a ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xe4959941fb153e1dec5ec84f798dc32928219ae2, not stripped
The configure for the libdaemon is this
~/libdaemon-0.14$ ./configure --build=i686-linux --host=arm-linux-gnueabi --enable-shared --prefix=/usr
~/libdaemon-0.14$ sudo make DESTDIR=/home/j/libdaemon-0.14 install
Any tip of what I'm doing wrong?
Thanks in advance!

Related

How to use GCC from gcc_9.3.0-1ubuntu2_amd64.deb without installing the package?

I need to build a library from C sources for Arm aarch64 architecture and Linux Ubuntu x86 64 using GCC toolchain - my host work machine is Ubuntu 20.04 too.
For Arm there are GCC toolchains available for download at developer.arm-com.
What I do for Arm is:
download the zipped toolchain
unzip it to a /temp directory
build the library telling the underlying build system to use GCC from /temp/gcc
I would like to do the same for Linux x86 64, so, instead of Arm, target Linux Ubuntu x86 64. I don't want to use the GCC natively installed on the system.
Where do I find the GCC toolchain targeting Ubuntu x86 64 architecture?
I have found the https://packages.ubuntu.com/focal/amd64/gcc/download page. There I got the gcc_9.3.0-1ubuntu2_amd64.deb package. Can I "temporarily unzip" the deb, in order to use GCC without installing it on the system? Is there a zip instead of only deb?

MIPS GCC cross-compiler build fails: "cannot find -lc"

I am trying to set up a GCC 4.9.4 cross-compiler for a QCA955X-based router with Linux 2.6.31. This is a MIPS32R2-abi CPU that uses uClibc-0.9.30.1 (as found in /lib.) Due to this, I have decided to compile a GCC 4.x with the matching uClibc and binutils-2.19.1a. My host system is Ubuntu 18.04 with Linux 4.17-rc5 and gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)
~/mips-cross-gcc/staging_dir is my prefix, and ~/mips-cross-gcc/staging_dir/sysroot is the makeshift sysroot for my system.
1) I downloaded binutils-2.19.1a.tar.bz2, gcc-4.9.4.tar.bz2, linux-2.6.31.9.tar.xz, and uClibc-0.9.30.1.tar.bz2 into ~/mips-cross-gcc/sources.
2) I untar'd all the sources.
3) Install linux headers:
make ARCH=mips INSTALL_HDR_PATH=/home/user/mips-cross-gcc/staging_dir/sysroot/usr headers_install
4) Build binutils:
cd binutils-2.19.1
./configure --prefix=/home/user/mips-cross-gcc/staging_dir --target=mips-linux-uclibc --disable-multilib --disable-werror --enable-shared --without-newlib --with-sysroot=/home/user/mips-cross-gcc/staging_dir/sysroot --enable-languages=c,c++ --disable-libgomp
make all-binutils
make all-ld
make all-gas
make install-binutils
make install-ld
make install-gas
5) Build "stage 1" gcc, to bootstrap uClibc:
cd gcc-4.9.4
mkdir -p build/gcc-stage1
../../configure --target=mips-linux-uclibc --prefix=/home/user/mips-cross-gcc/staging_dir --disable-werror --disable-libgomp --without-newlib --disable-multilib --enable-languages=c,c++ --enable-shared --disable-__cxa_atexit --enable-target-optspace --disable-nls --disable-libmudflap --disable-libssp --with-float=soft --with-sysroot=/home/user/mips-cross-gcc/staging_dir/sysroot --with-gnu-ld --without-headers
make all-gcc
make install-gcc
6) Install uClibc headers:
cd uClibc-0.9.30.1
make PREFIX=/home/user/mips-cross-gcc/staging_dir/sysroot install_headers
7) Build libgcc for target arch:
cd gcc-4.9.4
make all-target-libgcc
Libgcc is compiled all the way until the final libgcc_s linking stage:
/home/daniel/mips-cross-gcc/staging_dir/mips-linux-uclibc/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
Makefile:937: recipe for target 'libgcc_s.so' failed
I thought that bootstrapping a GCC would not require a libc, because it has not been compiled yet, right? What could I be doing wrong? I would use this compiled GCC to build uClibc, and then I would compile GCC again with my new uClibc so that I can cross-compile software. The fact that GCC requires libc in the first build seems wrong.
I tried to use the first gcc without compiling libgcc for building uClibc, but nearly instantly I received:
LD ld-uClibc-0.9.30.1.so
mips-linux-uclibc-gcc: error: libgcc.a: No such file or directory
ldso/ldso/Makefile.in:54: recipe for target 'lib/ld-uClibc.so' failed
So, uClibc needs libgcc to link itself, and gcc needs a libc (of any type, including uClibc) to link its own libgcc. This seems like a chicken-and-egg problem. How would one fix this?
I fixed it. Apparently, GCC has to be built without shared libraries enabled (--disable-shared) so that it doesn't link the generated libraries like libgcc dynamically (i.e to libc,) but that still didn't work. -lc was still not found.
I did some more googling, and I found this helpful message from eglibc, about making their own toolchain with gcc: eglibc.org
The First GCC
For our work, we need a cross-compiler targeting a PowerPC Linux
system. However, that configuration includes the shared library
'libgcc_s.so', which is compiled against the EGLIBC headers (which we
haven't installed yet) and linked against 'libc.so' (which we haven't
built yet).
Fortunately, there are configuration options for GCC which tell it not
to build 'libgcc_s.so'. The '--without-headers' option is supposed to
take care of this, but its implementation is incomplete, so you must
also configure with the '--with-newlib' option. While '--with-newlib'
appears to mean "Use the Newlib C library", its effect is to tell the
GCC build machinery, "Don't assume there is a C library available."
Looks like with enough digging, someone's bound to find the exact problem one has.
In short, changing --enable-shared to --disable-shared and adding --with-newlib to GCC's
./configure solved the issue and compiled + linked a libgcc_s.so that I used to compile uClibc, and then recompiled gcc with the newly generated libc, from uClibc. Indeed, it is possible to compile a 2016 GCC 4.x with a 2011 uClibc on a 2018 GCC 7.x.

libwebsockets.h - no such file or directory, Ubuntu, arm-linux-gcc cross compiler

I am building a web server using the libwebsockets library on a TS-7800 board using the arm-linux-gcc cross compiler. Using Ubuntu. Installed CMake, OpenSSL, and libwebsockets and built the library per the instructions on Github.
I made a "hello world" C file which #includes libwebsockets.h
When I compile the executable with gcc, it compiles fine and the .exe runs.
When I compile with arm-linux-gcc, I get the following:
root#gordon-MS-7A39:/# arm-linux-gcc -o hellosockets /home/gordon/workspace/HelloCrossWorld/hello_cross.c
/home/gordon/workspace/HelloCrossWorld/hello_cross.c:3:27: libwebsockets.h: No such file or directory
It appears that arm-linux-gcc compiler cannot "see" the header file for libwebsockets. I'm guessing that the installation of the websockets library was successful because gcc can see it.
How do I enable the arm cross compiler to see the libwebsockets.h file?
Thank you for your input!
You'll need to add armhf architecture to your package management system. Perform the following actions as super user:
dpkg --add-architecture armhf
apt update
apt install libwebsockets-dev:armhf
Make sure you're also using the armhf toolchain:
apt install binutils-arm-linux-gnueabihf g++-arm-linux-gnueabihf
Alternatively, take a look at Buildroot
I was unaware of the -I and -L preprocessor options for gcc and arm-linux-gcc.
I was able to add libraries to the project and will look into creating makefiles for the project.

Objdump doesn't recognize the architecture of a shared library

I built a shared library on Ubuntu 14.04 for ARM platform. The file has compiled and build successfully. I can inspect exported symbols with nm command but when I check .so file header I got the information that architecture is unknown.
Is this library built correctly, why is the library architecture unknown ?
objdump -f libMyLib.so
libMyLib.so: file format elf32-little
architecture: UNKNOWN!, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x000033a0
You need to use the objdump binary provided by the toolchain of your target system (ARM), not from host system(x86_64).
As a example: I have setup a host system Linux x86_64 targeting openwrt mips, my toolchain folder has some files:
mips-openwrt-linux-gnu-ar
mips-openwrt-linux-gnu-as
mips-openwrt-linux-gnu-gcc
mips-openwrt-linux-gnu-ld
mips-openwrt-linux-gnu-objdump
mips-openwrt-linux-gnu-nm
These are the tools to manipulate programs for openwrt mips system, so instead of just calling objdump, I need to call ./mips-openwrt-linux-gnu-objdump -f <bin file> to read and get the proper output for the compiled file.

Cross-compile qemu for ARM

I need to cross-compile qemu to use it on a cubieboard2 with an ARM Cortex-A7 CPU and I'm cross-compiling it on Linux Mint.
I can't find anywhere the commands I need to use to do it, the only thing I could find is how to compile qemu on an emulated ARM system. This is what I tried:
git clone git://git.qemu-project.org/qemu.git
./configure --target-list="arm-softmmu arm-linux-user" --prefix=/usr --enable-kvm --enable-linux-user --enable-user --enable-system
make ARCH=ARM CROSS_COMPILE=arm-linux-gnueabihf-
I don't get any errors, everything seems fine, but I don't get an executable file that I can use on my board.
Thanks everyone!

Resources