gcc - Including lib in arm-elf cross compile: undefined reference -
so, i'm trying build small program using libmodbus using arm-elf cross compiler, , keep getting undefined reference errors libmodbus though built cross compiler , in lib folder.
i have built libmodbus
./configure --host=arm-elf --prefix=/usr/local/arm-elf make && make install
then, wrote program, making sure include modbus header
#include <modbus/modbus.h>
and compiled it
arm-elf-gcc -o modbus_read_register -wl,-elf2flt -v -lmodbus modbus_read_register.c
but fails at, think, linking phase
/usr/local/lib/gcc-lib/arm-elf/2.95.3/collect2 -x -o modbus_read_register /usr/local/arm-elf/lib/crt0.o -l/usr/local/lib/gcc-lib/arm-elf/2.95.3 -l/usr/local/arm-elf/lib -elf2flt -lmodbus /tmp/cc000bvc.o -lgcc -lc -lgcc modbus_read_register.elf2flt(.text+0x88): in function `main': : undefined reference `modbus_new_tcp' modbus_read_register.elf2flt(.text+0x98): in function `main': : undefined reference `modbus_connect' modbus_read_register.elf2flt(.text+0xb0): in function `main': : undefined reference `modbus_strerror' modbus_read_register.elf2flt(.text+0xcc): in function `main': : undefined reference `modbus_free' modbus_read_register.elf2flt(.text+0x11c): in function `main': : undefined reference `modbus_read_registers' modbus_read_register.elf2flt(.text+0x13c): in function `main': : undefined reference `modbus_strerror' modbus_read_register.elf2flt(.text+0x1cc): in function `main': : undefined reference `modbus_close' modbus_read_register.elf2flt(.text+0x1d4): in function `main': : undefined reference `modbus_free' collect2: ld returned 1 exit status make: *** [modbus_read_register] error 1
i can't figure out why linker isn't working, since libmodbus.a file @ correct path , being provided in args.
since libmodbus package installed in location provided prefix, in
--prefix=/usr/local/arm-elf
you should specify path when compiling program modbus_read_register.c
arm-elf-gcc -o modbus_read_register -wl,-elf2flt -v -lmodbus modbus_read_register.c
-l/usr/local/arm-elf/lib
here -l option redirect linker search files in specified directory
Comments
Post a Comment