undefined reference to `jpeg_std_error(jpeg_error_mgr*)

本文介绍了解决Linux环境下使用Qt编译时遇到的BMP图片转换为JPG图片的问题。通过调整Makefile和正确引入jpeglib.h,解决了链接器无法找到JPEG库函数的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景 linux + QT BMP图片转JPG

#include <jpeglib.h>


编译错误:


root@happy-virtual-machine:/home/happy/Lee/Detector2# make
arm-linux-g++ -Wl,-O1 -Wl,-rpath,/opt/qt-4.7.1/lib -o Detector2 main.o mainwindow.o osd.o thread_preview.o preview.o thread_encode.o encode.o rtp.o power.o upload.o moc_mainwindow.o moc_thread_encode.o moc_upload.o    -L/opt/qt-4.7.1/lib -lQtGui -L/usr/local/tslib/lib -L/opt/qt-4.7.1/lib -lQtNetwork -lQtCore -lpthread  
encode.o: In function `Bmp2Jpg(char const*, char const*, int, int)':
encode.cpp:(.text+0x5ac): undefined reference to `jpeg_std_error(jpeg_error_mgr*)'
encode.cpp:(.text+0x5cc): undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int, unsigned int)'
encode.cpp:(.text+0x5f0): undefined reference to `jpeg_stdio_dest(jpeg_compress_struct*, _IO_FILE*)'
encode.cpp:(.text+0x610): undefined reference to `jpeg_set_defaults(jpeg_compress_struct*)'
encode.cpp:(.text+0x620): undefined reference to `jpeg_set_quality(jpeg_compress_struct*, int, int)'
encode.cpp:(.text+0x62c): undefined reference to `jpeg_start_compress(jpeg_compress_struct*, int)'
encode.cpp:(.text+0x6d4): undefined reference to `jpeg_write_scanlines(jpeg_compress_struct*, unsigned char**, unsigned int)'
encode.cpp:(.text+0x6dc): undefined reference to `jpeg_finish_compress(jpeg_compress_struct*)'
encode.cpp:(.text+0x738): undefined reference to `jpeg_destroy_compress(jpeg_compress_struct*)'
encode.cpp:(.text+0x7ec): undefined reference to `jpeg_write_scanlines(jpeg_compress_struct*, unsigned char**, unsigned int)'
encode.cpp:(.text+0x7f4): undefined reference to `jpeg_finish_compress(jpeg_compress_struct*)'
encode.cpp:(.text+0x850): undefined reference to `jpeg_destroy_compress(jpeg_compress_struct*)'
collect2: ld returned 1 exit status
make: *** [Detector2] 错误 1


修改

1、MakeFile

LIBS          = $(SUBLIBS)  -L/opt/qt-4.7.1/lib -lQtGui -L/usr/local/tslib/lib -L/opt/qt-4.7.1/lib -lQtNetwork -lQtCore -lpthread -ljpeg 

2、源文件:

extern "C" {
#include <jpeglib.h>
}
用extern "c" 把 jpeg 有关的头文件包含进来


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值