Kali Linux下C项目引入libexif失败,编译报错求助
在Kali Linux的C项目中引入libexif库的编译错误解决
问题描述
我在Kali Linux的C语言项目中尝试引入libexif库,已将完整的libexif文件夹放入项目目录,并按照README执行了./configure和make命令,但编译程序时仍报错。
报错信息
In file included from main.c:5:
libexif-0.6.24/libexif/exif-data.h:31:10: fatal error: libexif/exif-byte-order.h: Nie ma takiego pliku ani katalogu
31 | #include <libexif/exif-byte-order.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
注:上述报错中的波兰语意为“没有该文件或目录”
项目目录结构:包含libexif-0.6.24文件夹和main.c文件。
项目代码
#include<stdlib.h> #include<stdio.h> #include<ncurses.h> #include<string.h> #include"libexif-0.6.24/libexif/exif-data.h" //#include"DevIL/include/IL/il.h" //Function that allow user to open folder where he want to do something with photos. It returns pointer to file with list of all files that are in folder pointed by user FILE *openFolder(char* destination){ char c; char *systemInput=malloc(sizeof(char)*123); strcat(systemInput,"ls "); strcat(systemInput,destination); strcat(systemInput," > systemOutput.txt"); system(systemInput); FILE *file=fopen("systemOutput.txt","r"); free(systemInput); return file; } //Function that allows to show photo void showPhoto(char* userInput, char* destination){ char *systemInput=malloc(sizeof(char)*150); strcat(systemInput,"open "); strcat(systemInput,destination); strcat(systemInput,userInput); system(systemInput); free(systemInput); free(userInput); return; } int main(){ //defining variables char* userInput=malloc(sizeof(char)*100); char* destination=malloc(sizeof(char)*100); char c; //opening ncurses window initscr(); refresh(); //asking user for folder path which contain photos printw("EXIF file reader\n\n"); printw("Please enter the folder path where the photos are located:\n"); scanw("%s", destination); FILE *file=openFolder(destination); while(1){ clear(); printw("EXIF file reader\n\nType numer of action that you want to perform\n\n"); printw("1. Open photo\n"); printw("\n\n\n\n\n\n\n\n Press q to exit programm"); c=getch(); if(c=='1'){ clear(); userInput=malloc(sizeof(char)*100); printw("EXIF file reader\n\n"); if(file){ while((c=getc(file))!=EOF){ printw("%c", c); } } printw("\n\n"); printw("Please enter photo that you want to open:\n"); scanw("%s", userInput); showPhoto(userInput,destination); } else if(c=='q'){ free(destination); free(userInput); endwin(); } } }
解决步骤
1. 系统包管理器安装(推荐)
直接通过Kali的包管理器安装libexif开发库,无需手动编译:
sudo apt update && sudo apt install libexif-dev
修改代码中的头文件引用为标准形式:
#include <libexif/exif-data.h>
编译时链接库文件:
gcc main.c -o exif_reader -lexif -lncurses
2. 手动编译安装libexif
如果坚持手动编译,需要完成完整的安装流程:
- 进入libexif目录:
cd libexif-0.6.24 - 配置编译参数:
./configure - 编译并安装到系统:
make && sudo make install - 更新系统库缓存:
sudo ldconfig
之后即可使用标准头文件引用,编译命令同步骤1。
3. 不安装直接编译(临时方案)
若不想安装到系统,编译时指定头文件和库的搜索路径:
gcc main.c -o exif_reader -I./libexif-0.6.24 -L./libexif-0.6.24/libexif/.libs -lexif -lncurses
说明:-I指定头文件根目录,让编译器能找到<libexif/exif-byte-order.h>;-L指定编译生成的库文件所在路径。
额外代码问题提示
openFolder和showPhoto函数中,malloc后的内存未初始化就调用strcat会导致未定义行为,需先初始化空字符串:char *systemInput=malloc(sizeof(char)*123); *systemInput = '\0'; strcat(systemInput,"ls ");main函数中userInput被多次malloc但仅最后一次被free,存在内存泄漏,需调整内存管理逻辑。
内容的提问来源于stack exchange,提问作者czakub
相关产品推荐
相关产品推荐

