0

I'm trying to compile an example C program that links against PortAudio for a MIPSEL OpenWRT architecture targeting the MT7688 chip.

My starting point is this 351MB Docker image that has a working MIPSEL GNU uclibc toolchain (run source env.sh to set environment variables).

I tried to cross-compile PortAudio at first, but I couldn't get it to output MIPS binaries despite configuring Makefile for --host=mips-openwrt-linux-uclibc. So I copied working libasound.so.2, libportaudio.so.2 and libportaudio.so.2 files from my MIPS device and placed them in both the source folder and /usr/lib, then passed explicit include and linker paths:

$CC I/snowboy/examples/C/portaudio/install/include -L/usr/lib -lasound demo.c -o demo -v

> /bin/ld: cannot find -lasound
collect2: error: ld returned 1 exit status

No dice. I am too dumb to understand GCC linker paths, but I've come this far. Can anyone help me to navigate this cross-compilation minefield?

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • Do not copy cross-compilation libraries to your system directories (like `/usr/lib` is). That would overwrite whatever host-specific library already existed. For cross-compilation, *always* use special non-system directories for everything (including compilers, tools and of course libraries). Use the `-L` (and `-I`) options to specify those cross-compilation specific directories. – Some programmer dude Feb 18 '19 at 11:44
  • Also note that the host is the local system where you do the cross-compilation, and the target is the target you cross-compile for. That is, when cross-compiling you should set the *target* and not the host (i.e. use the `--target` flag). – Some programmer dude Feb 18 '19 at 11:45
  • @Someprogrammerdude when I try to ./configure PortAudio using `--target=mips-openwrt-linux-uclibc`, it complains with ```checking for suffix of executables... checking whether we are cross compiling... configure: error: in `/snowboy/examples/C/portaudio': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'.``` – Petrus Theron Feb 18 '19 at 11:56
  • Then set the host to whatever your host system is. Any good cross-compilation tutorial should be able to give you information about it. – Some programmer dude Feb 18 '19 at 11:57
  • @Someprogrammerdude let's assume I have working pre-compiled `libasound.so.2` and `libportaudio.so.2` files. How do I get `mipsel-openwrt-linux-gcc` to look for them? And is there a way to see where it looked? – Petrus Theron Feb 18 '19 at 12:07
  • For GCC give the sysroot path to specify the path at which it should take library from: "--sysroot=": this will make sure that your compiler will look into "/usr/lib" for all the library. rootfs should have all the library and include file etc for cross compiler also same libraries will be flashed to device. or give the path as -L – Deepak Feb 18 '19 at 12:46
  • Thanks, @Deepak. I tried compiling PortAudio from fresh source, and am getting `../deep/paths/...mipsel-openwrt-linux-uclibc/bin/ld: cannot find libportaudio.so.2: No such file or directory`. – Petrus Theron Feb 18 '19 at 14:05
  • This error seems not the same. This error means you don't have cross compiled libportaudio.so that you are using in your rootfs path. if you have this externally some place, then just give the path of that to compiler with -L. you can use "file libportaudio.so" command in the Linux/ubuntu PC to check for the architecture for which the library is compiled. – Deepak Feb 18 '19 at 14:13
  • @Deepak if I'm cross-compiling PortAudio from scratch, I expect it to producte libportaudio.so. But when I run `file libportaudio.so.2` on the lib I copied from my MIPS device, I get: `libportaudio.so.2: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, corrupted section header size` as expected. Big problem is getting GCC to use it. – Petrus Theron Feb 18 '19 at 14:18
  • If this is the proper library then just specify gcc with the path. ex: if you have library at "/home/libportaudio.so.2" then "-L/home" while compiling. as per this error, There is a problem in using libportaudio.so for linking. not generating this library. – Deepak Feb 18 '19 at 14:22
  • @Deepak hence the confusion: `libportaudio.so.2` is right there. Running `$CC -o test test.c -L./ -lasound` throws `/mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lasound collect2: error: ld returned 1 exit status`. Also tried `-L/absolute/path` – Petrus Theron Feb 18 '19 at 14:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188609/discussion-between-deepak-and-petrus-theron). – Deepak Feb 18 '19 at 14:30

0 Answers0