CMake编译Nginx源码
背景
最近打算学习nginx源码,但使用clion IDE查看不支持跳转。因为源码是使用autotool维护的,而clion需要CMake管理项目。着手编译nginx源码。
环境
os : ubuntu 18.04
nginx: nginx-1.16.1
cmake: 3.10.2
clion: 2019.2
原生编译
- 解压源码包后,执行configure命令。
./configure --prefix=/hcloud/service/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module
- 执行命令后会发现目录下多出来一个文件夹objs。里边有autotool根据这次configure自动生产的宏配置(ngx_auto_config.h、ngx_auto_headers.h)以及Makefile文件。
objs├── autoconf.err├── Makefile├── ngx_auto_config.h├── ngx_auto_headers.h├── ngx_modules.c
- 之后就是make && make install
CMake编译
使用 这篇博客里的方法,发现代码大部分虽然能跳转了,但是不能编译通过。某些变量结构体还是无法解析。在此基础上进行修改。
project(nginx)
cmake_minimum_required(VERSION 3.1)INCLUDE_DIRECTORIES(./)
INCLUDE_DIRECTORIES(/usr/include/libxml2)
INCLUDE_DIRECTORIES(./objs)
INCLUDE_DIRECTORIES(./src/core)
INCLUDE_DIRECTORIES(./src/event)
#INCLUDE_DIRECTORIES(./src/event/modules) # 平台相关不能加入所有的源码
INCLUDE_DIRECTORIES(./src/os/unix)
INCLUDE_DIRECTORIES(./src/http)
INCLUDE_DIRECTORIES(./src/http/modules)
INCLUDE_DIRECTORIES(./src/mail)aux_source_directory(. SRC_LIST)
aux_source_directory(./src/core SRC_LIST)
aux_source_directory(./src/event SRC_LIST)
#aux_source_directory(./src/event/modules SRC_LIST) # 平台相关不能加入所有的源码
aux_source_directory(./src/os/unix SRC_LIST)
aux_source_directory(./src/http SRC_LIST)
aux_source_directory(./src/http/modules SRC_LIST)# modify src list
set(SRC_LIST ${SRC_LIST} ./src/event/modules/ngx_epoll_module.c)
set(SRC_LIST ${SRC_LIST} ./objs/ngx_modules.c)# 此次configure不关心的 源码需要剔除掉
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_darwin_init.c ./src/os/unix/ngx_darwin_sendfile_chain.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_freebsd_init.c ./src/os/unix/ngx_freebsd_sendfile_chain.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_solaris_init.c ./src/os/unix/ngx_solaris_sendfilev_chain.c)
list(REMOVE_ITEM SRC_LIST ./src/core/ngx_thread_pool.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_file_aio_read.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_linux_aio_read.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_thread_cond.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_thread_mutex.c)
list(REMOVE_ITEM SRC_LIST ./src/os/unix/ngx_thread_id.c)
list(REMOVE_ITEM SRC_LIST ./src/http/modules/ngx_http_dav_module.c)
list(REMOVE_ITEM SRC_LIST ./src/http/modules/ngx_http_geoip_module.c)
list(REMOVE_ITEM SRC_LIST ./src/http/modules/ngx_http_degradation_module.c)
list(REMOVE_ITEM SRC_LIST ./src/http/modules/ngx_http_grpc_module.c)
list(REMOVE_ITEM SRC_LIST ./src/http/modules/ngx_http_image_filter_module.c)
list(REMOVE_ITEM SRC_LIST ./src/http/modules/ngx_http_stub_status_module.c)add_executable(${PROJECT_NAME} ${SRC_LIST})# 引入lib包
TARGET_LINK_LIBRARIES (${PROJECT_NAME} dl pthread crypt ldap lber pcre ssl crypto dl pthread z xml2 xslt exslt)
心得
- 官方autotool生成的Makefile文件作为对照。遇到问题先去看看Makefile是怎么写的。
- 依赖包可以去翻objs/Makefile 。
- 每次make发现编译不通过,首先去 objs/Makefile 看该*.c是否需要编译。
- ngx_auto_headers.h和ngx_auto_config.h其实就是一些宏定义,在编译时充当开关。
CMake编译Nginx源码相关推荐
- 记一次失败的Windows环境编译Nginx源码
最近想学习下nginx的源码,之前在linux环境编译安装过多次,在windows环境还是第一次尝试,遇到了不少问题,记录一下.可惜的是编译成功后,在最后运行的时候还是会报错,如果有人遇到类似的问题希 ...
- 龙芯3a5000下编译nginx源码
1.nginx源码获取 http://hg.nginx.org/nginx 选择tag,选择稳定版本1.22,点击gz下载gz压缩格式的源码. 2.编译环境需要安装一大堆依赖,不过我测试这台机器因为之 ...
- Ubuntu 14.04上使用CMake编译MXNet源码操作步骤(Python)
MXNet源码版本号为1.3.0,其它依赖库的版本号可参考:https://blog.csdn.net/fengbingchun/article/details/84997490 . 为了通过编译源码 ...
- Ubuntu 14.04上使用CMake编译MXNet源码操作步骤(C++)
MXNet源码版本号为1.3.0,其它依赖库的版本号可参考:https://blog.csdn.net/fengbingchun/article/details/84997490 build.sh脚本 ...
- cmake 编译curl源码_OpenCV4.0 源码编译
之前写过几篇关于OpenCV的博客,都是基于openCV 3.14写的,10月份OpenCV发布了4.0的bate版本,我就切换到4.0版本上来.之后的博客都会是基于4.0版本的.本文主要介绍一下三个 ...
- Ubuntu下使用CMake编译OpenSSL源码操作步骤(C语言)
OpenSSL的版本为1.0.1g,在ubuntu下通过CMake仅编译c代码不包括汇编代码,脚本内容如下: build.sh内容: #! /bin/bashreal_path=$(realpath ...
- 用Cmake编译Opencv源码,生成动态库
前期准备:安装Cmake和VS2010 一安装Cmake 1 . 2. 3. 二. 1. 将OpenCV2.4.9安装于以下目录: G:/opencv2.4.9 2. 使用CMake建立VS工程文件 ...
- windows上使用cmake 编译yaml-cpp源码,生成yam-cpp.lib
1.打开cmake-gui 2.添加CmakeList 3.建立build 4.进入工程中生成debug和release版本的lib
- LNMP架构详解(2)——Mysql、PHP、Nginx源码编译过程
前言 本文将介绍LNMP架构中Mysql.PHP.Nginx的源码编译过程:这时有人不仅会问:在我们使用的Linux系统中,可以从yum源中获得mysql.php,为什么要进行如此漫长复杂的过程进行编 ...
最新文章
- 静态嵌套类(Static Nested Class)和内部类(Inner Class)的不同?
- 抛硬币 直到连续出现两次字为止
- Android插件化开发之解决OpenAtlas组件在宿主的注冊问题
- MPICH 完整配置存档
- 深度学习训练的时候gpu占用0_26秒单GPU训练CIFAR10,Jeff Dean也点赞的深度学习优化技巧...
- python关键词提取源码_Python 结巴分词 关键词抽取分析
- HTML head 头标签
- 服务器怎么用u盘传文件进去_云服务器无法使用USB设备?一文读懂如何在云服务器上使用优盘...
- 修改java bean,java – 以编程方式修改Spring bean
- 计算机四级网络工程师考过指南
- 仿宋小二在html中怎么设置,HTML简短设置字体
- jenkins启动后无法连接网络解决方法
- Wireshark 64位中文版(抓包工具)
- 《Adobe Premiere Pro CS5经典教程》——2.5 导入素材
- ubuntu16.04+七彩虹GTX1060的NVIDIA驱动+Cuda8.0+cudnn5.1+tensorflow+keras搭建深度学习环境【学习笔记】【原创】
- Stm8 串口重定向及问题解决
- macbookair有没有touchbar_苹果电脑购买建议:2018新款MacBook Pro买不买带Touch Bar的?...
- linux 造字程序下载,truetype造字程序下载
- gen阻抗 pcie_PCIe Gen3/Gen4接收端链路均衡测试(上篇:理论篇)
- 从零到一编写一个 spark 程序并提交到集群中运行
热门文章
- 复制模仿是成功最佳的捷径?
- Cloud Computing HCIP④-Fusion Access 桌面云
- 大数据周会-本周学习内容总结013
- java 异常 不抛,java中不捕获或抛出的异常
- 什么是视频点播(VOD)?
- 怎样辨别内部晶振与外部晶振
- 【点云3D目标检测】IA-SSD报错:Expected isFloatingType(grads[i].scalar_type()) to be true, but got false.
- Java基础编程题(API阶段测试)(答案)
- nagios报警信息,发送到微信端
- c语言程序设计 北京理工,北京理工大学《C语言程序设计》期末试题.pdf