0

During a cross-compilation I got this linker error:

/home/tech/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lfontconfig

This is the g++ command line:

/home/tech/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++ -Wl,-rpath-link,/mnt/rasp-pi-rootfs/opt/vc/lib -Wl,-rpath-link,/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/mnt/rasp-pi-rootfs/lib/arm-linux-gnueabihf -mfloat-abi=hard --sysroot=/mnt/rasp-pi-rootfs -Wl,-O1 -o fontconfig fontconfig.o   --sysroot=/mnt/rasp-pi-rootfs -lpthread -L/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/ -lfreetype -lfontconfig 

And

ls /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libfontconfig*

/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libfontconfig.so.1
/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libfontconfig.so.1.8.0

I don't understand "why" the linker cannot find that library. What do you suggest to do in such a case to investigate further?

Mark
  • 4,338
  • 7
  • 58
  • 120

1 Answers1

-1

Linker requires import library with .a extension of the library for linker operations because it contains the signatures of classes and functions needed by the linker for linking while .so libraries are shared objects used at runtime.

You need to find the directory where you have libfontconfig.a (e.g.: through the command locate libfontconfig.a or 'find / -name libfontconfig.a') and then add it to the command line with -L/path/of/directory.

Francesco Argese
  • 626
  • 4
  • 11
  • Thank for the explanation! I installed the static libraries (by installing the -dev package). For this specific library it worked! But for another one with the same error didn't. Example: before I had the libicui18n not found error, installing the -dev package with .a files leads to another one: libicui18n.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'. But this time it says explicity *.so. – Mark Apr 28 '16 at 19:16
  • /home/tech/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++ -c -pipe -marm -mfpu=vfp -mtune=arm1176jzf-s -march=armv6zk -mabi=aapcs-linux -mfloat-abi=hard --sysroot=/mnt/rasp-pi-rootfs -O2 -std=gnu++0x -Wall -W -fPIC -I. -I/usr/include/x86_64-linux-gnu -I/usr/include/freetype2 -I/usr/include -I../../../mkspecs/devices/linux-rasp-pi-g++ -o icu.o icu.cpp – Mark Apr 28 '16 at 19:20
  • /home/tech/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++ -Wl,-rpath-link,/mnt/rasp-pi-rootfs/opt/vc/lib -Wl,-rpath-link,/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/mnt/rasp-pi-rootfs/lib/arm-linux-gnueabihf -mfloat-abi=hard --sysroot=/mnt/rasp-pi-rootfs -Wl,-O1 -o icu icu.o --sysroot=/mnt/rasp-pi-rootfs -lpthread -licui18n -licuuc -licudata – Mark Apr 28 '16 at 19:21
  • It seems a problem with the toolchain: https://github.com/raspberrypi/tools/issues/41 – Mark Apr 28 '16 at 19:22
  • 1
    Yes it seems that the version of the library you are using doesn't have the symbol __cxa_throw_bad_array_new_length@CXXABI_1.3.8. You can do a check of the symobls available in the .a library through the command nm called with a single argument which is the .a library. – Francesco Argese Apr 28 '16 at 19:25
  • 2
    @FrancescoArgese: A linker doesn't require you to link against static libraries for cross-compilation. By statically compiling you end up compiling the library into your shipped binary, but it is by no means necessary for compilation to succeed. – photoionized Apr 29 '16 at 17:02
  • @photoionized I have modified static library with import library. – Francesco Argese Apr 29 '16 at 19:28