[英]C program link error : undefined reference to `jpeg_std_error'
I use the libjpeg in my C program, and some error occurrs when the program compiled:我在我的 C 程序中使用了 libjpeg,程序编译时出现了一些错误:
/usr/bin/ld: CMakeFiles/video_capture.dir/main.c.o: in function `setup_jpeg_decompress':
/home/arthurryan/programs/video_capture/main.c:58: undefined reference to `jpeg_std_error'
/usr/bin/ld: /home/arthurryan/programs/video_capture/main.c:59: undefined reference to `jpeg_CreateDecompress'
collect2: error: ld returned 1 exit status
I have tried some solutions like:我尝试了一些解决方案,例如:
But nothing worked.但没有任何效果。 I'm sure that the libjpeg has benn installed in my computer.
我确定 libjpeg 已安装在我的计算机中。 When I execute
当我执行
find /usr -iname libjpeg\*so\*
There are several results:有几个结果:
/usr/lib/x86_64-linux-gnu/libjpeg.so.8.2.2
/usr/lib/x86_64-linux-gnu/libjpeg.so
/usr/lib/x86_64-linux-gnu/libjpeg.so.8
If there are any other ways to solve the problem?如果有其他方法可以解决问题?
I use CLion to develop, here is the content of CMakeLists.txt我用CLion开发,这里是CMakeLists.txt的内容
cmake_minimum_required(VERSION 3.17)
project(video_capture C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS -g)
set(CMAKE_C_FLAGS "-L /usr/lib/x86_64-linux-gnu")
set(CMAKE_C_FLAGS "-ljpeg")
set(CMAKE_C_FLAGS "-pthread")
add_executable(video_capture main.c camera/camera.c inc/camera.h inc/common.h camera/logi_c270.c inc/logi_c270.h encoder.c inc/encoder.h converter/jpeg2yuv.c inc/jpeg2yuv.h)
include_directories(./inc)
The way gcc/g++ search libraries changed a while ago. gcc/g++ 搜索库的方式不久前发生了变化。 It used not to matter whether your makefile had:
您的 makefile 是否有:
gcc -o stuff -ljpeg stuff.o
or或者
gcc -o stuff stuff.o -ljpeg
but now, it does matter.但现在,这很重要。 The first one won't pick up the needed functions.
第一个不会获取所需的功能。 The second one will.
第二个会。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.