/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or 的解决办法

本文详细解析了在使用FastDFS分布式文件系统时,遇到的Nginx扩展模块编译错误“fatal error:common_define.h:No such file or directory”。通过调整Nginx扩展模块的路径配置,成功解决了这一问题。

问题概述

在项目使用到了分布式文件服务器FastDFS,FastDFS的Tracker Server 和 Storage Server 安装完成后,需要外部的 Web Server来提供访问,有人可能会疑问,为什么不使用FastDFS内部的Web Server呢,我的另一篇文章非常详细的阐述了这个问题,请参看 《 FastDFS分布式文件系统内部架构及其原理解析 》

这儿使用的是FastDFS的Nginx扩展模块,但是在Nginx编译时出现了错误,“ fatal error: common_define.h: No such file or directory

如下图:

 

 

解决办法

经过了系统的排查,最终得知,在安装FastDFS的时候,其中的函数声明、宏定义、函数原型被指到了 “ /usr/include/fastdfs /usr/include/fastcommon ” 目录下,如下图:

 

而Nginx的扩展模块配置文件默认指定的目录为 “ /usr/include ”,找不到文件,才导致的上面的错误 “ 致命错误: common_define.h 的文件或目录不存在 ” ,解决这个问题,只需要将Nginx扩展模块的路径目录修改为上面正常的 “ /usr/include/fastdfs ” 即可,输入命令 “ vi /usr/local/fastdfs-nginx-module/src/config ” ,总共修改两项即可:

ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"

》》》

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

缺省的:

ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_incs="/usr/include"
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
    CORE_INCS="$CORE_INCS /usr/include"
    CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi

修改后的:

ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
    CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi

现在再去编译安装Nginx就可以了。

 

 

 

 

 


 好了,关于 fatal error: common_define.h: No such file or directory 的解决办法 就写到这儿了,如果还有什么疑问或遇到什么问题欢迎扫码提问,也可以给我留言哦,我会一一详细的解答的。 
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。


作       者:华    仔
联系作者:who.seek.me@java98k.vip
来        源:优快云 (Chinese Software Developer Network)
原        文:https://blog.youkuaiyun.com/Hello_World_QWP/article/details/95318414
版权声明:本文为博主原创文章,请在转载时务必注明博文出处!
<think>我们遇到了FastDFSNginx模块编译错误,主要涉及三个问题:1.`FDFS_CONNECT_TIMEOUT`、`FDFS_NETWORK_TIMEOUT`和`FDFS_BASE_PATH_STR`未声明2.`fdfs_get_ini_context_from_tracker`函数调用参数不足3.缺少头文件`/usr/include/fastcommon/fdfs_define.h`###解决方案####1.解决符号未声明问题这些符号通常在FastDFS的头文件中定义。请检查以下步骤:**步骤1:确认头文件路径**-查找`fdfs_define.h`文件:```bashfind/-namefdfs_define.h2>/dev/null```常见路径:-`/usr/include/fastcommon/fdfs_define.h`-`/usr/local/include/fastcommon/fdfs_define.h`**步骤2:添加宏定义(备用方案)**若头文件确实不存在或版本较旧,可在`common.c`文件开头添加临时定义:```c//添加在common.c的#include之后#ifndefFDFS_CONNECT_TIMEOUT#defineFDFS_CONNECT_TIMEOUT30//默认连接超时30秒#endif#ifndefFDFS_NETWORK_TIMEOUT#defineFDFS_NETWORK_TIMEOUT60//默认网络超时60秒#endif#ifndefFDFS_BASE_PATH_STR#defineFDFS_BASE_PATH_STR"base_path"//基础路径字符串#endif```####2.修复函数参数问题`fdfs_get_ini_context_from_tracker`函数在FastDFS6.x版本中增加了参数[^4]:```diff-result=fdfs_get_ini_context_from_tracker(&g_tracker_group,&iniContext,&continue_flag,NULL);+result=fdfs_get_ini_context_from_tracker(&g_tracker_group,&iniContext,&continue_flag,NULL,0);//增加最后一个参数```####3.解决头文件缺失问题**方案A:创建符号链接**若头文件存在于非标准路径:```bash#示例:将实际路径链接到编译器搜索路径sudoln-s/usr/local/include/fastcommon/usr/include/fastcommon```**方案B:修改编译配置**在Nginx编译配置中显式指定头文件路径:```bash./configure\...\--with-cc-opt="-I/usr/local/include/fastcommon-I/usr/local/include/fastdfs"\--with-ld-opt="-L/usr/local/lib"```###验证步骤1.**确认头文件存在**:```bashls/usr/include/fastcommon/fdfs_define.h#或ls/usr/local/include/fastcommon/fdfs_define.h```2.**检查函数声明**:在`tracker_proto.h`中确认函数签名:```cintfdfs_get_ini_context_from_tracker(TrackerServerGroup*pTrackerGroup,\IniContext*pIniContext,bool*continue_flag,int*storage_server_index,\constinttimeout);```3.**重新编译**:```bashmakecleanmake-j$(nproc)```>**注意**:以上修改需根据实际FastDFS版本调整。建议使用FastDFS6.07+和fastdfs-nginx-module1.22+[^3]。###相关问题1.如何检查FastDFS存储节点的同步状态?2.Nginx集成FastDFS后如何配置缓存策略?3.如何优化FastDFS在高并发场景下的性能?4.FastDFS集群扩容时需要注意哪些关键点?[^1]:关键配置项需与实际部署环境匹配[^2]:头文件路径配置直接影响编译结果[^3]:版本兼容性是部署成功的关键因素[^4]:函数接口变更需同步修改调用代码</think>### 解决 FastDFS Nginx 模块编译错误指南 以下是针对您遇到的编译错误的完整解决方案,按照问题类型分类处理: --- #### **1. 解决符号未声明错误(FDFS_*)** 这些符号在 FastDFS 6.0+ 版本中已被重构,需要手动定义或修复包含路径: **步骤 1:添加缺失的宏定义** 在 `common.c` 文件开头添加以下代码(通常在 `#include` 语句之后): ```c // 添加在 common.c 文件顶部 #ifndef FDFS_CONNECT_TIMEOUT #define FDFS_CONNECT_TIMEOUT 30 // 默认30秒 #endif #ifndef FDFS_NETWORK_TIMEOUT #define FDFS_NETWORK_TIMEOUT 60 // 默认60秒 #endif #ifndef FDFS_BASE_PATH_STR #define FDFS_BASE_PATH_STR "base_path" // 基础路径标识 #endif ``` **步骤 2:修复头文件包含路径** 修改模块配置文件(关键步骤): ```bash sudo nano /usr/local/fastdfs-nginx-module/src/config ``` ```diff ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/ \ - /usr/local/include/fastdfs" + /usr/include/fastcommon /usr/include/libfastcommon/" ``` **步骤 3:验证头文件存在性** 执行以下命令检查关键头文件: ```bash # 检查必须存在的头文件 ls -l /usr/include/fastcommon/fdfs_define.h ls -l /usr/include/fastdfs/fdfs_global.h # 若不存在则创建符号链接 sudo ln -s /usr/local/include/fastcommon /usr/include/fastcommon sudo ln -s /usr/local/include/fastdfs /usr/include/fastdfs ``` --- #### **2. 解决函数参数错误(fdfs_get_ini_context_from_tracker)** 此函数在 FastDFS 6.x 版本中增加了新参数: **修改调用代码** 在 `common.c` 中找到此函数调用(约 1601 行),修改为: ```diff - fdfs_get_ini_context_from_tracker(&g_tracker_group, &iniContext, &continue_flag, NULL); + fdfs_get_ini_context_from_tracker(&g_tracker_group, &iniContext, &continue_flag, NULL, 0); ``` 新增的 `0` 是 `storage_server_index` 参数,表示默认存储服务器索引[^4]。 --- #### **3. 完整编译流程验证** ```bash # 进入 Nginx 源码目录 cd /www/server/nginx/src/nginx-1.24.0 # 清理旧编译 make clean # 重新配置(关键参数) ./configure \ --add-module=/usr/local/fastdfs-nginx-module/src \ --with-cc-opt="-I/usr/include/fastcommon -I/usr/include/fastdfs" \ --with-ld-opt="-L/usr/local/lib" # 编译安装 make -j$(nproc) sudo make install ``` --- #### **4. 验证修复结果** 检查关键点: ```bash # 查看编译日志 tail -n 100 objs/autoconf.err # 检查模块是否加载 nginx -V 2>&1 | grep fastdfs # 应显示:--add-module=/usr/local/fastdfs-nginx-module/src ``` --- ### 相关问题 1. 如何确认 FastDFS 存储节点与 tracker 服务器的连接状态? 2. Nginx 集成 FastDFS 后如何配置防盗链功能? 3. 升级 FastDFS 版本时如何保证已有数据的兼容性? 4. FastDFS 集群中如何实现存储节点的负载均衡? > **关键提示**: > - 所有修改基于 FastDFS ≥ 6.07 和 fastdfs-nginx-module ≥ 1.22 版本[^3] > - 环境变量 `LD_LIBRARY_PATH` 应包含 `/usr/local/lib` > - 配置文件 `/etc/fdfs/mod_fastdfs.conf` 需与存储节点配置一致[^4] [^1]: 配置参数必须与实际部署环境匹配 [^2]: 头文件路径错误是编译失败的常见原因 [^3]: 版本兼容性是部署成功的关键因素 [^4]: 函数接口变更需同步修改调用代码
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TechBro华仔

日拱一卒无有尽,功不唐捐终入海

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值