Board: imx6qsabresd
host: ubuntu 12.04
FS: yocto project 1.5 (Dora)
Description:
When i try to compile application using poky toolchain installed via meta-toolchain, i am getting below linker errors. Please let me know how can i fix this
ERROR Log:
-------------------
/opt/poky/1.4.3/sysroots/i686-pokysdk-linux/usr/libexec/armv7a-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.7.2/ld: cannot find /lib/libc.so.6
/opt/poky/1.4.3/sysroots/i686-pokysdk-linux/usr/libexec/armv7a-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.7.2/ld: cannot find /usr/lib/libc_nonshared.a
/opt/poky/1.4.3/sysroots/i686-pokysdk-linux/usr/libexec/armv7a-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.7.2/ld: cannot find /lib/ld-linux-armhf.so.3
collect2: error: ld returned 1 exit status
Also,
While building multi-threaded gstreamer application, we are getting pthread linker errors as shown below:
ERROR Log:
-------------------
/opt/poky/1.4.3/sysroots/i686-pokysdk-linux/usr/libexec/armv7a-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.7.2/ld: cannot find /lib/libpthread.so.0
/opt/poky/1.4.3/sysroots/i686-pokysdk-linux/usr/libexec/armv7a-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.7.2/ld: cannot find /usr/lib/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
Below is my code test.c:
-----------------------------------
#include <pthread.h>
#include <stdio.h>
/* this function is run by the second thread */
void *inc_x(void *x_void_ptr)
{
/* increment x to 100 */
int *x_ptr = (int *)x_void_ptr;
while(++(*x_ptr) < 100);
printf("x increment finished\n");
/* the function must return something - NULL will do */
return NULL;
}
int main()
{
int x = 0, y = 0;
/* show the initial values of x and y */
printf("x: %d, y: %d\n", x, y);
/* this variable is our reference to the second thread */
pthread_t inc_x_thread;
/* create a second thread which executes inc_x(&x) */
if(pthread_create(&inc_x_thread, NULL, inc_x, &x)) {
fprintf(stderr, "Error creating thread\n");
return 1;
}
/* increment y to 100 in the first thread */
while(++y < 100);
printf("y increment finished\n");
/* wait for the second thread to finish */
if(pthread_join(inc_x_thread, NULL)) {
fprintf(stderr, "Error joining thread\n");
return 2;
}
/* show the results - x is now 100 thanks to the second thread */
printf("x: %d, y: %d\n", x, y);
return 0;
}
Command used to build:
-----------------------------------
/opt/poky/1.4.3/sysroots/i686-pokysdk-linux/usr/bin/armv7a-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -L/opt/fsl-imx6-sysroot/lib -L/opt/fsl-imx6-sysroot/usr/lib -lpthread test.c
are you sourcing the environment script before compilation? the env script should be located somewhere on /opt/poky/<VERSION>/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
Hi Leonardo,
I am getting this error too when I try to compile GStreamer Sample Application. I did source the environment script.I am able to compile and run a HelloWorld.c Application.
Sample application is from Chapter 10. Your first application link. The makefile I am using is attached below,
Makefile:
------------------------------------------------------------------------------------------------------------------------------------
# define the C compiler to use
CC = /opt/poky/1.4+snapshot/sysroots/i686-pokysdk-linux/usr/bin/cortexa9hf-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
# define any compile-time flags
CFLAGS = -Wall -g
# define any directories containing header files other than /usr/include
INCLUDES = -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/glib-2.0 -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/lib/glib-2.0/include/ -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/gstreamer-0.10/ -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/libxml2
LFLAGS = -L/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/lib
# define any libraries to link into executable:
LIBS = -lglib-2.0 -lxml2 -lgstreamer-0.10 -lgobject-2.0 -lz -lgmodule-2.0 -lffi
# define the C source files
SRCS = hellogst.c
# define the C object files
OBJS = $(SRCS:.c=.o)
# define the executable file
MAIN = hellogst
.PHONY: depend clean
all: $(MAIN)
@echo Simple compiler named simple has been compiled
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
# this is a suffix replacement rule for building .o's from .c's
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
------------------------------------------------------------------------------------------------------------------------------------
Compilation Error:
------------------------------
$ make
/opt/poky/1.4+snapshot/sysroots/i686-pokysdk-linux/usr/bin/cortexa9hf-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -Wall -g -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/glib-2.0 -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/lib/glib-2.0/include/ -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/gstreamer-0.10/ -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/libxml2 -c hellogst.c -o hellogst.o
/opt/poky/1.4+snapshot/sysroots/i686-pokysdk-linux/usr/bin/cortexa9hf-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -Wall -g -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/glib-2.0 -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/lib/glib-2.0/include/ -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/gstreamer-0.10/ -I/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/include/libxml2 -o hellogst hellogst.o -L/home/suman/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd/usr/lib -lglib-2.0 -lxml2 -lgstreamer-0.10 -lgobject-2.0 -lz -lgmodule-2.0 -lffi
/opt/poky/1.4+snapshot/sysroots/i686-pokysdk-linux/usr/libexec/cortexa9hf-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.8.1/ld: cannot find /lib/libc.so.6
/opt/poky/1.4+snapshot/sysroots/i686-pokysdk-linux/usr/libexec/cortexa9hf-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.8.1/ld: cannot find /usr/lib/libc_nonshared.a
/opt/poky/1.4+snapshot/sysroots/i686-pokysdk-linux/usr/libexec/cortexa9hf-vfp-neon-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.8.1/ld: cannot find /lib/ld-linux-armhf.so.3
collect2: error: ld returned 1 exit status
make: *** [hellogst] Error 1
This issue has been resolved after manually editing the libpthread.so and libc.so file generated during yocto build. These files point to /usr/lib i.e. host pc libraries instead of current directory[/build-fb/tmp/sysroots/imx6qsabresd/usr/lib] which was causing the problem.
Hi Suman Ranjan,
what do u mean with "manualy editing libpthread.so and libc.so file"? Using an hex editor.
I am running exactly into your same problem.
What is strange is that I can successfully compile QT applications with qt creator following the instruction in Setup QT Creator with Yocto Build
Thanks in advance,
i.
Solved,
my problem was in the Makefile, pls refer to 5.2. of Yocto Project Application Developer's Guide
CC and CFLAGS must be set properly.
i.
You are right. I changed my CFLAGS accordingly and it worked too.
Makefile:
SYSROOT_PATH=/home/suman/svndump/fsl-community-bsp/build-fb/tmp/sysroots/imx6qsabresd
# define any compile-time flags
#CFLAGS = -fPIC -Wall -Wextra -O2 -g # old CFLAG
CFLAGS="--sysroot=$(SYSROOT_PATH)" # New CFLAG fixes the problem