由于原先以前被vs2008以及eclipse宠坏了,vi使用又不熟悉,本来想好好学习nginx源码的我很是拙计,我亟需一个IDE来阅读以及调试源代码,于是我看上了QtCreator,,于是本博文就是介绍如何把nginx源码搞成qt creator工程。
我们要先学习一下QT Creator的工程文件.pro,因为QTCreator的qmake按照.pro文件生成Makefile的。
现在我们先来看看我们需要用到的.pro配置项
配置项的格式是:key = value
我们需要的key如下
TARGET = nginx DESTDIR = ./objs LIBS = -lpthread -lcrypt -lpcre -lcrypto -lcrypto -lz INCLUDEPATH += \ src/core \ src/event \ src/event/modules \ src/os/unix \ src/http/modules \ src/http \ objs HEADERS = src/core/nginx.h \ src/core/ngx_config.h \ src/core/ngx_core.h \ src/core/ngx_log.h \ src/core/ngx_palloc.h \ src/core/ngx_array.h \ src/core/ngx_list.h \ src/core/ngx_hash.h \ src/core/ngx_buf.h \ src/core/ngx_queue.h \ src/core/ngx_string.h \ src/core/ngx_parse.h \ src/core/ngx_inet.h \ src/core/ngx_file.h \ src/core/ngx_crc.h \ src/core/ngx_crc32.h \ src/core/ngx_murmurhash.h \ src/core/ngx_md5.h \ src/core/ngx_sha1.h \ src/core/ngx_rbtree.h \ src/core/ngx_radix_tree.h \ src/core/ngx_slab.h \ src/core/ngx_times.h \ src/core/ngx_shmtx.h \ src/core/ngx_connection.h \ src/core/ngx_cycle.h \ src/core/ngx_conf_file.h \ src/core/ngx_resolver.h \ src/core/ngx_open_file_cache.h \ src/core/ngx_crypt.h \ src/event/ngx_event.h \ src/event/ngx_event_timer.h \ src/event/ngx_event_posted.h \ src/event/ngx_event_busy_lock.h \ src/event/ngx_event_connect.h \ src/event/ngx_event_pipe.h \ src/os/unix/ngx_time.h \ src/os/unix/ngx_errno.h \ src/os/unix/ngx_alloc.h \ src/os/unix/ngx_files.h \ src/os/unix/ngx_channel.h \ src/os/unix/ngx_shmem.h \ src/os/unix/ngx_process.h \ src/os/unix/ngx_setaffinity.h \ src/os/unix/ngx_setproctitle.h \ src/os/unix/ngx_atomic.h \ src/os/unix/ngx_gcc_atomic_x86.h \ src/os/unix/ngx_thread.h \ src/os/unix/ngx_socket.h \ src/os/unix/ngx_os.h \ src/os/unix/ngx_user.h \ src/os/unix/ngx_process_cycle.h \ src/os/unix/ngx_linux_config.h \ src/os/unix/ngx_linux.h \ src/core/ngx_regex.h \ objs/ngx_auto_config.h \ src/http/ngx_http.h \ src/http/ngx_http_request.h \ src/http/ngx_http_config.h \ src/http/ngx_http_core_module.h \ src/http/ngx_http_cache.h \ src/http/ngx_http_variables.h \ src/http/ngx_http_script.h \ src/http/ngx_http_upstream.h \ src/http/ngx_http_upstream_round_robin.h \ src/http/ngx_http_busy_lock.h \ src/http/modules/ngx_http_ssi_filter_module.h SOURCES = src/core/nginx.c \ src/core/ngx_log.c \ src/core/ngx_palloc.c \ src/core/ngx_array.c \ src/core/ngx_list.c \ src/core/ngx_hash.c \ src/core/ngx_buf.c \ src/core/ngx_queue.c \ src/core/ngx_output_chain.c \ src/core/ngx_string.c \ src/core/ngx_parse.c \ src/core/ngx_inet.c \ src/core/ngx_file.c \ src/core/ngx_crc32.c \ src/core/ngx_murmurhash.c \ src/core/ngx_md5.c \ src/core/ngx_rbtree.c \ src/core/ngx_radix_tree.c \ src/core/ngx_slab.c \ src/core/ngx_times.c \ src/core/ngx_shmtx.c \ src/core/ngx_connection.c \ src/core/ngx_cycle.c \ src/core/ngx_spinlock.c \ src/core/ngx_cpuinfo.c \ src/core/ngx_conf_file.c \ src/core/ngx_resolver.c \ src/core/ngx_open_file_cache.c \ src/core/ngx_crypt.c \ src/event/ngx_event.c \ src/event/ngx_event_timer.c \ src/event/ngx_event_posted.c \ src/event/ngx_event_busy_lock.c \ src/event/ngx_event_accept.c \ src/event/ngx_event_connect.c \ src/event/ngx_event_pipe.c \ src/os/unix/ngx_time.c \ src/os/unix/ngx_errno.c \ src/os/unix/ngx_alloc.c \ src/os/unix/ngx_files.c \ src/os/unix/ngx_socket.c \ src/os/unix/ngx_recv.c \ src/os/unix/ngx_readv_chain.c \ src/os/unix/ngx_udp_recv.c \ src/os/unix/ngx_send.c \ src/os/unix/ngx_writev_chain.c \ src/os/unix/ngx_channel.c \ src/os/unix/ngx_shmem.c \ src/os/unix/ngx_process.c \ src/os/unix/ngx_daemon.c \ src/os/unix/ngx_setaffinity.c \ src/os/unix/ngx_setproctitle.c \ src/os/unix/ngx_posix_init.c \ src/os/unix/ngx_user.c \ src/os/unix/ngx_process_cycle.c \ src/os/unix/ngx_linux_init.c \ src/event/modules/ngx_epoll_module.c \ src/os/unix/ngx_linux_sendfile_chain.c \ src/core/ngx_regex.c \ src/http/ngx_http.c \ src/http/ngx_http_core_module.c \ src/http/ngx_http_special_response.c \ src/http/ngx_http_request.c \ src/http/ngx_http_parse.c \ src/http/ngx_http_header_filter_module.c \ src/http/ngx_http_write_filter_module.c \ src/http/ngx_http_copy_filter_module.c \ src/http/modules/ngx_http_log_module.c \ src/http/ngx_http_request_body.c \ src/http/ngx_http_variables.c \ src/http/ngx_http_script.c \ src/http/ngx_http_upstream.c \ src/http/ngx_http_upstream_round_robin.c \ src/http/ngx_http_parse_time.c \ src/http/modules/ngx_http_static_module.c \ src/http/modules/ngx_http_index_module.c \ src/http/modules/ngx_http_chunked_filter_module.c \ src/http/modules/ngx_http_range_filter_module.c \ src/http/modules/ngx_http_headers_filter_module.c \ src/http/modules/ngx_http_not_modified_filter_module.c \ src/http/ngx_http_busy_lock.c \ src/http/ngx_http_file_cache.c \ src/http/modules/ngx_http_gzip_filter_module.c \ src/http/ngx_http_postpone_filter_module.c \ src/http/modules/ngx_http_ssi_filter_module.c \ src/http/modules/ngx_http_charset_filter_module.c \ src/http/modules/ngx_http_userid_filter_module.c \ src/http/modules/ngx_http_autoindex_module.c \ src/http/modules/ngx_http_auth_basic_module.c \ src/http/modules/ngx_http_access_module.c \ src/http/modules/ngx_http_limit_conn_module.c \ src/http/modules/ngx_http_limit_req_module.c \ src/http/modules/ngx_http_geo_module.c \ src/http/modules/ngx_http_map_module.c \ src/http/modules/ngx_http_split_clients_module.c \ src/http/modules/ngx_http_referer_module.c \ src/http/modules/ngx_http_rewrite_module.c \ src/http/modules/ngx_http_proxy_module.c \ src/http/modules/ngx_http_fastcgi_module.c \ src/http/modules/ngx_http_uwsgi_module.c \ src/http/modules/ngx_http_scgi_module.c \ src/http/modules/ngx_http_memcached_module.c \ src/http/modules/ngx_http_empty_gif_module.c \ src/http/modules/ngx_http_browser_module.c \ src/http/modules/ngx_http_upstream_ip_hash_module.c \ src/http/modules/ngx_http_upstream_least_conn_module.c \ src/http/modules/ngx_http_upstream_keepalive_module.c \ objs/ngx_modules.c
由于nginx有很多的模块,在编译的过程中,nginx会根据系统环境的设置,生成ngx_modules.c、ngx_auto_config.h、ngx_auto_headers.h、Makefile等,然后,源代码中根据这些配置头文件,使用宏定义进行差异化编译。所以我们最重要的一步就是根据系统环境生成ngx_modules.c、ngx_auto_config.h、ngx_auto_headers.h、Makefile这几个文件。
步骤就是非常简单的,使用./configure就好了,以上文件都生成在nginx目录下的objs文件夹内。
打开QTCreator创建一个空的QTCreator项目,如下
现在把nginx文件夹下的src、objs文件夹拷贝到nginx目录下
修改.pro文件
TARGET = nginx DESTDIR = ./objs LIBS = -lpthread -lcrypt -lpcre -lcrypto -lcrypto -lz INCLUDEPATH += \ src/core \ src/event \ src/event/modules \ src/os/unix \ src/http/modules \ src/http \ objs HEADERS = src/core/nginx.h \ src/core/ngx_config.h \ src/core/ngx_core.h \ src/core/ngx_log.h \ src/core/ngx_palloc.h \ src/core/ngx_array.h \ src/core/ngx_list.h \ src/core/ngx_hash.h \ src/core/ngx_buf.h \ src/core/ngx_queue.h \ src/core/ngx_string.h \ src/core/ngx_parse.h \ src/core/ngx_inet.h \ src/core/ngx_file.h \ src/core/ngx_crc.h \ src/core/ngx_crc32.h \ src/core/ngx_murmurhash.h \ src/core/ngx_md5.h \ src/core/ngx_sha1.h \ src/core/ngx_rbtree.h \ src/core/ngx_radix_tree.h \ src/core/ngx_slab.h \ src/core/ngx_times.h \ src/core/ngx_shmtx.h \ src/core/ngx_connection.h \ src/core/ngx_cycle.h \ src/core/ngx_conf_file.h \ src/core/ngx_resolver.h \ src/core/ngx_open_file_cache.h \ src/core/ngx_crypt.h \ src/event/ngx_event.h \ src/event/ngx_event_timer.h \ src/event/ngx_event_posted.h \ src/event/ngx_event_busy_lock.h \ src/event/ngx_event_connect.h \ src/event/ngx_event_pipe.h \ src/os/unix/ngx_time.h \ src/os/unix/ngx_errno.h \ src/os/unix/ngx_alloc.h \ src/os/unix/ngx_files.h \ src/os/unix/ngx_channel.h \ src/os/unix/ngx_shmem.h \ src/os/unix/ngx_process.h \ src/os/unix/ngx_setaffinity.h \ src/os/unix/ngx_setproctitle.h \ src/os/unix/ngx_atomic.h \ src/os/unix/ngx_gcc_atomic_x86.h \ src/os/unix/ngx_thread.h \ src/os/unix/ngx_socket.h \ src/os/unix/ngx_os.h \ src/os/unix/ngx_user.h \ src/os/unix/ngx_process_cycle.h \ src/os/unix/ngx_linux_config.h \ src/os/unix/ngx_linux.h \ src/core/ngx_regex.h \ objs/ngx_auto_config.h \ src/http/ngx_http.h \ src/http/ngx_http_request.h \ src/http/ngx_http_config.h \ src/http/ngx_http_core_module.h \ src/http/ngx_http_cache.h \ src/http/ngx_http_variables.h \ src/http/ngx_http_script.h \ src/http/ngx_http_upstream.h \ src/http/ngx_http_upstream_round_robin.h \ src/http/ngx_http_busy_lock.h \ src/http/modules/ngx_http_ssi_filter_module.h SOURCES = src/core/nginx.c \ src/core/ngx_log.c \ src/core/ngx_palloc.c \ src/core/ngx_array.c \ src/core/ngx_list.c \ src/core/ngx_hash.c \ src/core/ngx_buf.c \ src/core/ngx_queue.c \ src/core/ngx_output_chain.c \ src/core/ngx_string.c \ src/core/ngx_parse.c \ src/core/ngx_inet.c \ src/core/ngx_file.c \ src/core/ngx_crc32.c \ src/core/ngx_murmurhash.c \ src/core/ngx_md5.c \ src/core/ngx_rbtree.c \ src/core/ngx_radix_tree.c \ src/core/ngx_slab.c \ src/core/ngx_times.c \ src/core/ngx_shmtx.c \ src/core/ngx_connection.c \ src/core/ngx_cycle.c \ src/core/ngx_spinlock.c \ src/core/ngx_cpuinfo.c \ src/core/ngx_conf_file.c \ src/core/ngx_resolver.c \ src/core/ngx_open_file_cache.c \ src/core/ngx_crypt.c \ src/event/ngx_event.c \ src/event/ngx_event_timer.c \ src/event/ngx_event_posted.c \ src/event/ngx_event_busy_lock.c \ src/event/ngx_event_accept.c \ src/event/ngx_event_connect.c \ src/event/ngx_event_pipe.c \ src/os/unix/ngx_time.c \ src/os/unix/ngx_errno.c \ src/os/unix/ngx_alloc.c \ src/os/unix/ngx_files.c \ src/os/unix/ngx_socket.c \ src/os/unix/ngx_recv.c \ src/os/unix/ngx_readv_chain.c \ src/os/unix/ngx_udp_recv.c \ src/os/unix/ngx_send.c \ src/os/unix/ngx_writev_chain.c \ src/os/unix/ngx_channel.c \ src/os/unix/ngx_shmem.c \ src/os/unix/ngx_process.c \ src/os/unix/ngx_daemon.c \ src/os/unix/ngx_setaffinity.c \ src/os/unix/ngx_setproctitle.c \ src/os/unix/ngx_posix_init.c \ src/os/unix/ngx_user.c \ src/os/unix/ngx_process_cycle.c \ src/os/unix/ngx_linux_init.c \ src/event/modules/ngx_epoll_module.c \ src/os/unix/ngx_linux_sendfile_chain.c \ src/core/ngx_regex.c \ src/http/ngx_http.c \ src/http/ngx_http_core_module.c \ src/http/ngx_http_special_response.c \ src/http/ngx_http_request.c \ src/http/ngx_http_parse.c \ src/http/ngx_http_header_filter_module.c \ src/http/ngx_http_write_filter_module.c \ src/http/ngx_http_copy_filter_module.c \ src/http/modules/ngx_http_log_module.c \ src/http/ngx_http_request_body.c \ src/http/ngx_http_variables.c \ src/http/ngx_http_script.c \ src/http/ngx_http_upstream.c \ src/http/ngx_http_upstream_round_robin.c \ src/http/ngx_http_parse_time.c \ src/http/modules/ngx_http_static_module.c \ src/http/modules/ngx_http_index_module.c \ src/http/modules/ngx_http_chunked_filter_module.c \ src/http/modules/ngx_http_range_filter_module.c \ src/http/modules/ngx_http_headers_filter_module.c \ src/http/modules/ngx_http_not_modified_filter_module.c \ src/http/ngx_http_busy_lock.c \ src/http/ngx_http_file_cache.c \ src/http/modules/ngx_http_gzip_filter_module.c \ src/http/ngx_http_postpone_filter_module.c \ src/http/modules/ngx_http_ssi_filter_module.c \ src/http/modules/ngx_http_charset_filter_module.c \ src/http/modules/ngx_http_userid_filter_module.c \ src/http/modules/ngx_http_autoindex_module.c \ src/http/modules/ngx_http_auth_basic_module.c \ src/http/modules/ngx_http_access_module.c \ src/http/modules/ngx_http_limit_conn_module.c \ src/http/modules/ngx_http_limit_req_module.c \ src/http/modules/ngx_http_geo_module.c \ src/http/modules/ngx_http_map_module.c \ src/http/modules/ngx_http_split_clients_module.c \ src/http/modules/ngx_http_referer_module.c \ src/http/modules/ngx_http_rewrite_module.c \ src/http/modules/ngx_http_proxy_module.c \ src/http/modules/ngx_http_fastcgi_module.c \ src/http/modules/ngx_http_uwsgi_module.c \ src/http/modules/ngx_http_scgi_module.c \ src/http/modules/ngx_http_memcached_module.c \ src/http/modules/ngx_http_empty_gif_module.c \ src/http/modules/ngx_http_browser_module.c \ src/http/modules/ngx_http_upstream_ip_hash_module.c \ src/http/modules/ngx_http_upstream_least_conn_module.c \ src/http/modules/ngx_http_upstream_keepalive_module.c \ objs/ngx_modules.c
现在来解释一下为什么这么用
主要解释一下INCLUDEPATH、LIBS,因为我在这上面吃过亏
INCLUDEPATH += \ src/core \ src/event \ src/event/modules \ src/os/unix \ src/http/modules \ src/http \ objs
LIBS = -lpthread -lcrypt -lpcre -lcrypto -lcrypto -lz
好了,现在就可以编译了