I am trying to use libjpeg in my application. Creating a project gives libjpeg.a in the .libs folder. I would like to use this file at the build stage. I tried the following: I copied libjpeg.a to the folder where my C code is located. Trying to contact
gcc libjpeg.a mycode.c -o executable_name
fails. If I do gcc -ljpeg mycode.c, compilation will succeed when I change the title to specify instead of "libjpeg.h", but this is obviously due to the system-wide dynamic version of the library.
An attempt to establish a connection with a relative or absolute path also fails:
gcc ./libjpeg.a mycode.c -o executable_name
I also tried a static parameter:
gcc -static libjpeg.a mycode.c -o executable_name
The linker error is as follows:
Linking... gcc -std=c99 -Wall -Wextra -g -pedantic ./libjpeg.a ./libjpeg.a -lm obj/read_jpeg.o obj/utils.o -o test_jpeg obj/read_jpeg.o: In function `read_JPEG_file': /home/ustun/Downloads/jpeg_test/read_jpeg.c:37: undefined reference to `jpeg_std_error' /home/ustun/Downloads/jpeg_test/read_jpeg.c:45: undefined reference to `jpeg_CreateDecompress' /home/ustun/Downloads/jpeg_test/read_jpeg.c:46: undefined reference to `jpeg_stdio_src' /home/ustun/Downloads/jpeg_test/read_jpeg.c:47: undefined reference to `jpeg_read_header' /home/ustun/Downloads/jpeg_test/read_jpeg.c:48: undefined reference to `jpeg_start_decompress' /home/ustun/Downloads/jpeg_test/read_jpeg.c:62: undefined reference to `jpeg_read_scanlines' /home/ustun/Downloads/jpeg_test/read_jpeg.c:74: undefined reference to `jpeg_finish_decompress' /home/ustun/Downloads/jpeg_test/read_jpeg.c:75: undefined reference to `jpeg_destroy_decompress' obj/read_jpeg.o: In function `read_JPEG_file_props': /home/ustun/Downloads/jpeg_test/read_jpeg.c:93: undefined reference to `jpeg_std_error' /home/ustun/Downloads/jpeg_test/read_jpeg.c:100: undefined reference to `jpeg_CreateDecompress' /home/ustun/Downloads/jpeg_test/read_jpeg.c:101: undefined reference to `jpeg_stdio_src' /home/ustun/Downloads/jpeg_test/read_jpeg.c:102: undefined reference to `jpeg_read_header' /home/ustun/Downloads/jpeg_test/read_jpeg.c:103: undefined reference to `jpeg_start_decompress' /home/ustun/Downloads/jpeg_test/read_jpeg.c:113: undefined reference to `jpeg_read_scanlines' /home/ustun/Downloads/jpeg_test/read_jpeg.c:116: undefined reference to `jpeg_finish_decompress' /home/ustun/Downloads/jpeg_test/read_jpeg.c:117: undefined reference to `jpeg_destroy_decompress' collect2: ld returned 1 exit status make: *** [test_jpeg] Error 1
You can download a simple project using the Makefile here .
source share