1
votes

I am trying cross compile C code (outside yocto) using toolchain (/home/amruta/Downloads/poky-glibc-x86_64-core-image-weston-sdk-cortexa7hf-neon-toolchain-2.4.2.sh) for renesas G1E module. Procedure followed to cross compile :

  1. Installed given toolchain

  2. Set environment :

amruta@amruta-OptiPlex-3060:~$ . /opt/poky/2.4.2/environment-setup-cortexa7hf-neon-poky-linux-gnueabi 
  1. Compiling in same terminal :
amruta@amruta-OptiPlex-3060:~/amruta/amruta_projects/G1E/EnergyMeterApp1/src$ $CC *.c -o Energymeter -L /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib/libmosquitto -I /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/

Source files used for cross compilation :

amruta@amruta-OptiPlex-3060:~/amruta/amruta_projects/G1E/EnergyMeterApp1/src$ ls
client_shared_lib.c  EnergyMeterApp1.h  GenericFunctions.c  modbus                 ProcessHandler.c
client_shared_lib.h  FileLogger.c       GenericFunctions.h  mosq_pub_sub_client.c  ProcessHandler.h
FileLogger.h       libconfig.h         mosq_pub_sub_client.h  ReadAllConfigs.c
EnergyMeterApp1.c    GenericDefns.h     Makefile            mosquitto.h            ReadAllConfigs.h

Library files already present in lib dir

amruta@amruta-OptiPlex-3060:~$ ls /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib | grep libmos
libmosquitto.so.1
amruta@amruta-OptiPlex-3060:~$ ls /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib | grep libconf
libconfig.so.9
libconfig++.so.9
libconfig.so.9.2.0
libconfig++.so.9.2.0
amruta@amruta-OptiPlex-3060:~$ 

Header files present in include dir

amruta@amruta-OptiPlex-3060:~$ ls /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/ | grep mos
mosquitto.h

amruta@amruta-OptiPlex-3060:~$ ls /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/ | grep libconfig
libconfig.h

Build output (partial):

amruta@amruta-OptiPlex-3060:~/amruta/amruta_projects/G1E/EnergyMeterApp1/src$ $CC *.c -o Energymeter -L /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib/libmosquitto -I /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/ 

/tmp/ccBMhPYg.o: In function client_id_generate': 
client_shared_lib.c:(.text+0x64): undefined reference to mosquitto_lib_cleanup' 
client_shared_lib.c:(.text+0x144): undefined reference to `mosquitto_lib_cleanup' 

/tmp/ccRMPfVp.o: In function ReadEnergyMeterConfigs': 
ReadAllConfigs.c:(.text+0x374): undefined reference to config_init' 
ReadAllConfigs.c:(.text+0x384): undefined reference to config_read_file' 
ReadAllConfigs.c:(.text+0x3c8): undefined reference to config_destroy' 

Please suggest for successful cross compilation.

1
amruta@amruta-OptiPlex-3060:~/amruta/amruta_projects/G1E/EnergyMeterApp1/src$ $CC *.c -o Energymeter -L /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib/libmosquitto -I /opt/poky/2.4.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/ /tmp/ccBMhPYg.o: In function client_id_generate': client_shared_lib.c:(.text+0x64): undefined reference to mosquitto_lib_cleanup' client_shared_lib.c:(.text+0x144): undefined reference to `mosquitto_lib_cleanup'APS
/tmp/ccRMPfVp.o: In function ReadEnergyMeterConfigs': ReadAllConfigs.c:(.text+0x374): undefined reference to config_init' ReadAllConfigs.c:(.text+0x384): undefined reference to config_read_file' ReadAllConfigs.c:(.text+0x3c8): undefined reference to config_destroy' Those are partial errors. Couldn't post all error messagesAPS
Do not use comments for information that should be in your question; they are limited length, limited formatting capability and are for neither answers nor questions. Edit the question to fix or improve your question. I have added the logs to your question and fixed other Markdown formatting issues.Clifford

1 Answers

1
votes

Specifying a library directory (-L <dir>) will not cause any libraries therein to be linked. The -L switch only tells the linker where to look for libraries specified by -l <lib> switches, of which you have none.

You need to add -l mosquitto to link libmosquitto.so for example. Similarly -l config for libconfig.so.

In general for any library libXXX.so or libXXX.a you link it with -l XXX. Where the libraries are versioned as in this case, the latest version will be linked. To link a specific version, you don't use -l <lib> but simply specify the path to the specific .so file as an input without a '-' switch.