0

sorry for this question that may seem trivial, but I looked at a few tutorials and SO questions and still could not figure out what is wrong.

Anyway, when using gcc, the linker is not able to find functions in the static library I have included.

Error message:

arm-none-linux-gnueabi-gcc -I. -I./include yuv.c -c -o yuv.o
arm-none-linux-gnueabi-gcc -I. -I./include main.c -c -o main.o
arm-none-linux-gnueabi-gcc -L./lib -I. -I./include yuv.o main.o -lpthread -lrt -ljpeg -o grab.elf
main.o: In function `jpegWrite':
main.c:(.text+0x118): undefined reference to `jpeg_std_error'
main.c:(.text+0x134): undefined reference to `jpeg_CreateCompress'
main.c:(.text+0x144): undefined reference to `jpeg_stdio_dest'
main.c:(.text+0x17c): undefined reference to `jpeg_set_defaults'
main.c:(.text+0x198): undefined reference to `jpeg_set_quality'
main.c:(.text+0x1a8): undefined reference to `jpeg_start_compress'
main.c:(.text+0x1e4): undefined reference to `jpeg_write_scanlines'
main.c:(.text+0x200): undefined reference to `jpeg_finish_compress'
main.c:(.text+0x20c): undefined reference to `jpeg_destroy_compress'
collect2: ld returned 1 exit status
make: *** [grab.elf] Error 1

My file structure is as follows:

Makefile

main.c

  • In Folder lib

  • libjpeg.a

My Makefile reads:

GCC=gcc

INC_PATH= -I. -I./include

LIBS_PATH = -L./lib

HEADER_FILE=./yuv.h ./include/jpeglib.h

grab.elf: yuv.o main.o
    $(CROSS_COMPILE)$(GCC) $(LIBS_PATH) $(INC_PATH) yuv.o main.o -lpthread -lrt -ljpeg -o grab.elf

yuv.o:yuv.c $(HEADER_FILE)
    $(CROSS_COMPILE)$(GCC) $(INC_PATH) yuv.c -c -o yuv.o

main.o:main.c $(HEADER_FILE)
    $(CROSS_COMPILE)$(GCC) $(INC_PATH) main.c -c -o main.o

I also tried:

nm libjpeg.a | grep jpeg_std
000001f0 T _jpeg_stdio_dest
00000140 T _jpeg_stdio_src
000001f0 T _jpeg_std_error
000012c0 R _jpeg_std_message_table

Would any kind soul care to help me? Thank you.

shock
  • 27
  • 1
  • 4
  • 1
    Possibly some clues here http://stackoverflow.com/questions/1034852/adding-leading-underscores-to-assembly-symbols-with-gcc-on-win32 – Andrew C Apr 13 '15 at 02:57

1 Answers1

1

Could it be that libjpeg.a was compiled on the platform on which you are developing, whereas the target of grab.elf is different? i.e., you are developing on x86 environment and targeting ARM?

user2551017
  • 153
  • 10
  • Thanks, the problem was that libjpeg.a was compiled for x86 but main.o was compiled for ARM. Problem was solved by using another libjpeg.a that was compiled for ARM. – shock Apr 13 '15 at 11:01