mac下的Nginx编译踩坑

背景

今天用mac编译nginx源码,因为需要编译nginx-rtmp-module,所以按照官网给的方式去编译,结果中途碰到点困难
nginx编译执行命令如下

./configure --add-module=/Users/kyolong/Desktop/workspace/nginx/nginx-rtmp-module --with-openssl=../openssl-1.0.2s

ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)

首先是这个错误,乍一看,好像是库识别不了的问题,下面提示未定义符号什么的i386,其实这个错误不在这儿,在上面,i386已经在Xcode被移除了。。。what????
简单来说就是apple不让用32位的库了,好吧,那以前让用我就用以前的版本好惹~

ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
ld: warning: could not create compact unwind for _passwd_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _s_client_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _serverinfo_cli_parse_cb: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _speed_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _print_stuff: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _s_time_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _rand_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _ocsp_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _create_query: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _serial_cb: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _srp_main: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _srp_create_user: stack subl instruction is too different from dwarf stack size
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
ld: warning: could not create compact unwind for _ERR_print_errors_cb: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _ERR_print_errors: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PEM_X509_INFO_write_bio: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PEM_read_bio_PrivateKey: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PKCS7_verify: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PKCS7_decrypt: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _RAND_load_file: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _RAND_write_file: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _read_string_inner: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _process_pci_value: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _pkey_GOST01cp_encrypt: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _pkey_GOST01cp_decrypt: stack subl instruction is too different from dwarf stack size
Undefined symbols for architecture i386:
  "__DefaultRuneLocale", referenced from:
      _show_ciphers in enc.o
      _s_server_main in s_server.o
      _s_client_main in s_client.o
      _BN_hex2bn in libcrypto.a(bn_print.o)
      _CONF_parse_list in libcrypto.a(conf_mod.o)
      _OBJ_create_objects in libcrypto.a(obj_dat.o)
      _OCSP_REQ_CTX_nbio in libcrypto.a(ocsp_ht.o)
      ...

行吧,找了找以前有没有人碰到这个错误,发现很多前辈已经踩过坑了,这个问题可以通过Xcode降级解决,不过Xcode降级总归有点麻烦,还得下载旧版本下半天,还得删掉旧版本。
没关系,前辈都替我们踩过坑了,只需要下载这个叫Command_Line_Tools_macOS_10.13_for_Xcode_10.1即可,使用方法也非常简单,如下
首先查看一下xcode-select目前指向哪儿

$ xcode-select -p
/Application/Xcode.app/Contents/Developer

然后修改掉它,指向我们刚下的CommondLineTools,这里需要root权限,所以用sudo

$ sudo xcode-select -s /path/to/CommandLineTools

Undefined symbols for architecture x86_64

上面的那个错误解决完了,又出现新的错误。。
然后是下面的这个错误,看上去似乎是找不到x86-64的库,忽略这个文件不是64位的库(晕,这个你咋能给我忽略呢,报个error也行啊)。。。。不过刚才nginx还要32位来着,怎么现在又要64位。。。所以下面一大堆报错,很明显是库文件的位数不对。

ld: warning: ignoring file ../openssl-1.0.2s/.openssl/lib/libssl.a, file was built for archive which is not the architecture being linked (x86_64): ../openssl-1.0.2s/.openssl/lib/libssl.a
ld: warning: ignoring file ../openssl-1.0.2s/.openssl/lib/libcrypto.a, file was built for archive which is not the architecture being linked (x86_64): ../openssl-1.0.2s/.openssl/lib/libcrypto.a
Undefined symbols for architecture x86_64:
  "_AES_cbc_encrypt", referenced from:
      _ngx_rtmp_mpegts_write_file in ngx_rtmp_mpegts.o
      _ngx_rtmp_mpegts_close_file in ngx_rtmp_mpegts.o
  "_AES_set_encrypt_key", referenced from:
      _ngx_rtmp_mpegts_init_encryption in ngx_rtmp_mpegts.o
  "_ASN1_GENERALIZEDTIME_print", referenced from:
      _ngx_ssl_stapling_ocsp_handler in ngx_event_openssl_stapling.o
  "_ASN1_TIME_print", referenced from:
      _ngx_ssl_get_client_v_start in ngx_event_openssl.o
      _ngx_ssl_get_client_v_end in ngx_event_openssl.o
      _ngx_ssl_get_client_v_remain in ngx_event_openssl.o
  "_ASN1_d2i_bio", referenced from:
      _ngx_ssl_stapling in ngx_event_openssl_stapling.o

我也不知道咋整啊,一看前辈又把坑踩过了,那我就不用踩了
解决方案是,在编译之前加上以下这句话

$ export KERNEL_BITS=64

openssl的config文件会根据该变量判断是否开启x86_64编译,默认是关闭的
然后正常编译,成功生成文件

发布了89 篇原创文章 · 获赞 96 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/Boring_Wednesday/article/details/100900738
今日推荐