nemo
nemo

Reputation: 633

arm-linux-gcc compiler linking, file could not be found

I am on Ubuntu and have developed a modbus1.c that #includes a certain modbus.h. I want to cross compile what I wrote to run on an embedded computer; to do this I know I need to use the arm-linux-gcc crosscompiler.

I have this library called libmodbus installed on Ubuntu. It conveniently uses pkg-config (which defines -I/usr/include/modbus and -lmodbus for --cflags and --libs respectively)

When I use the regular GCC:

gcc -o modbus1-release modbus1.c `pkg-config --cflags --libs libmodbus`

Everything works fine, modbus1-release is created and I can execute it.

The problem arises when I try to use the arm-linux-gcc compiler:

/usr/local/arm-linux/bin/arm-linux-gcc -o modbus1-release modbus1.c `pkg-config --cflags --libs libmodbus`
/usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/../../../../arm-linux/bin/ld: cannot find -lmodbus
collect2: ld returned 1 exit status
make: *** [release] Error 1

Apart from a direct answer, when I imagine what could 'help' me Im thinking answer to the following questions might 'help' me:

  1. how do I expand all the ../ and ../../../../? If I know where it is then maybe I can put -lmodbus in there
  2. what is -lmodbus? is it a file? where is it such that the regular gcc and ld can find it?
  3. is -l a flag and modbus the file name?

My intuition is telling me that the problem is coming from linking... the cc and ld in the arm-linux-gcc toolchain is missing infromation that the normal cc and ld has.

Any info will help!

TIA

Niko

verbose mode...

/usr/local/arm-linux/bin/arm-linux-gcc -v -o modbus1-release modbus1.c `pkg-config --cflags --libs libmodbus`
Reading specs from /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/specs
Configured with: ../configure --target=arm-linux --disable-shared --with-headers=/home/gerg/new-wave.xscale/linux-2.4.x/include --with-gnu-as --with-gnu-ld --enable-multilib
Thread model: posix
gcc version 3.3.2
 /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/cc1 -quiet -v -I/usr/include/modbus -iprefix /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=2 -D__ARM_ARCH_4T__ modbus1.c -quiet -dumpbase modbus1.c -auxbase modbus1 -version -o /tmp/ccVLqs9W.s
GNU C version 3.3.2 (arm-linux)
    compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc-lib/arm-linux/3.3.2/include"
ignoring nonexistent directory "/usr/local/arm-linux/sys-include"
ignoring duplicate directory "/usr/local/arm-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/modbus
 /usr/local/arm-linux/lib/gcc-lib/arm-linux/3.3.2/include
 /usr/local/arm-linux/arm-linux/sys-include
 /usr/local/arm-linux/arm-linux/include
End of search list.
 /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/../../../../arm-linux/bin/as -o /tmp/ccMyv4IL.o /tmp/ccVLqs9W.s
 /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/collect2 -dynamic-linker /lib/ld-linux.so.2 -X -m armelf_linux -p -o modbus1-release /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/../../../../arm-linux/lib/crt1.o /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/crti.o /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/crtbegin.o -L/usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2 -L/usr/local/arm-linux/bin/../lib/gcc-lib -L/usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/../../../../arm-linux/lib -L/usr/local/lib/../arm-linux/lib -L/usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/../../.. /tmp/ccMyv4IL.o -lmodbus -lgcc -lc -lgcc /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/crtend.o /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/crtn.o
/usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/../../../../arm-linux/bin/ld: cannot find -lmodbus
collect2: ld returned 1 exit status
make: *** [release] Error 1

Upvotes: 0

Views: 1983

Answers (1)

mfro
mfro

Reputation: 3335

If you want to use pgk_config in a cross compile situation (which is apparently supported, at least with newer versions of autotools), you need to set PKG_CONFIG_SYSROOT_DIR in your Makefile, otherwise pkg_config will set up an environment suitable for the host compiler only, later trying to combine cross compiled binaries with host libraries which obviously doesn't work.

Upvotes: 2

Related Questions