Compile ngx_resty to statically link some libs?

Hey agentzh, could you provide tips on how I could cut down this list of
dynamically linked libs:

[david@dev-3 ngx_openresty-1.0.8.26]$ ldd
/usr/local/encap/nginx-resty-1.0.8.26/nginx/sbin/nginx
linux-vdso.so.1 => (0x00007fff079fd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003aac200000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003e08a00000)
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00000033d9c00000)
libdrizzle.so.0 => /usr/lib64/libdrizzle.so.0 (0x00007fd4bcdf1000)
libm.so.6 => /lib64/libm.so.6 (0x0000003e12000000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x0000003710800000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x0000003e13400000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003e11000000)
libz.so.1 => /lib64/libz.so.1 (0x0000003e11c00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003e10c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003e10800000)
libfreebl3.so => /lib64/libfreebl3.so (0x0000003e08e00000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00000033d9400000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00000033d9800000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00000033d9000000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x000000374a800000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x000000374a000000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003e13800000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003e12c00000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003749c00000)

Specifically, I’d really like to remove libdrizzle as a dependency on
the target machine and just have the compile pull it in at link time.

Posted at Nginx Forum:

On Tue, Nov 15, 2011 at 10:30 AM, dannynoonan [email protected]
wrote:

Hey agentzh, could you provide tips on how I could cut down this list of
dynamically linked libs:

[snip]

Specifically, I’d really like to remove libdrizzle as a dependency on
the target machine and just have the compile pull it in at link time.

Try

./configure --with-ld-opt="-static" ...

while building ngx_openresty :slight_smile:

Regards,
-agentzh

I’d tried that, but figured I was invoking it wrong, the error it
yields:

checking for --with-ld-opt="-static" ... not found ./configure: error: the invalid value in --with-ld-opt="-static"

failed to run command: ./configure
–prefix=/data/local/nginx-resty-1.0.8.26/nginx \

Reading up on the man page for ld caused me to try
–with-ld-opt=“-Bstatic” which gets me past configure, but gmake still
yields an ELF binary that dynamically links out to libdrizzle. The final
gcc linking step looked like this:

gcc -o objs/nginx
objs/src/core/nginx.o
objs/src/core/ngx_log.o
objs/src/core/ngx_palloc.o
objs/src/core/ngx_array.o
objs/src/core/ngx_list.o
objs/src/core/ngx_hash.o
objs/src/core/ngx_buf.o
objs/src/core/ngx_queue.o
objs/src/core/ngx_output_chain.o
objs/src/core/ngx_string.o
objs/src/core/ngx_parse.o
objs/src/core/ngx_inet.o
objs/src/core/ngx_file.o
objs/src/core/ngx_crc32.o
objs/src/core/ngx_murmurhash.o
objs/src/core/ngx_md5.o
objs/src/core/ngx_rbtree.o
objs/src/core/ngx_radix_tree.o
objs/src/core/ngx_slab.o
objs/src/core/ngx_times.o
objs/src/core/ngx_shmtx.o
objs/src/core/ngx_connection.o
objs/src/core/ngx_cycle.o
objs/src/core/ngx_spinlock.o
objs/src/core/ngx_cpuinfo.o
objs/src/core/ngx_conf_file.o
objs/src/core/ngx_resolver.o
objs/src/core/ngx_open_file_cache.o
objs/src/core/ngx_crypt.o
objs/src/event/ngx_event.o
objs/src/event/ngx_event_timer.o
objs/src/event/ngx_event_posted.o
objs/src/event/ngx_event_busy_lock.o
objs/src/event/ngx_event_accept.o
objs/src/event/ngx_event_connect.o
objs/src/event/ngx_event_pipe.o
objs/src/os/unix/ngx_time.o
objs/src/os/unix/ngx_errno.o
objs/src/os/unix/ngx_alloc.o
objs/src/os/unix/ngx_files.o
objs/src/os/unix/ngx_socket.o
objs/src/os/unix/ngx_recv.o
objs/src/os/unix/ngx_readv_chain.o
objs/src/os/unix/ngx_udp_recv.o
objs/src/os/unix/ngx_send.o
objs/src/os/unix/ngx_writev_chain.o
objs/src/os/unix/ngx_channel.o
objs/src/os/unix/ngx_shmem.o
objs/src/os/unix/ngx_process.o
objs/src/os/unix/ngx_daemon.o
objs/src/os/unix/ngx_setproctitle.o
objs/src/os/unix/ngx_posix_init.o
objs/src/os/unix/ngx_user.o
objs/src/os/unix/ngx_process_cycle.o
objs/src/os/unix/ngx_linux_init.o
objs/src/event/modules/ngx_epoll_module.o
objs/src/os/unix/ngx_linux_sendfile_chain.o
objs/src/event/ngx_event_openssl.o
objs/src/core/ngx_regex.o
objs/src/http/ngx_http.o
objs/src/http/ngx_http_core_module.o
objs/src/http/ngx_http_special_response.o
objs/src/http/ngx_http_request.o
objs/src/http/ngx_http_parse.o
objs/src/http/ngx_http_header_filter_module.o
objs/src/http/ngx_http_write_filter_module.o
objs/src/http/ngx_http_copy_filter_module.o
objs/src/http/modules/ngx_http_log_module.o
objs/src/http/ngx_http_request_body.o
objs/src/http/ngx_http_variables.o
objs/src/http/ngx_http_script.o
objs/src/http/ngx_http_upstream.o
objs/src/http/ngx_http_upstream_round_robin.o
objs/src/http/ngx_http_parse_time.o
objs/src/http/modules/ngx_http_static_module.o
objs/src/http/modules/ngx_http_index_module.o
objs/src/http/modules/ngx_http_chunked_filter_module.o
objs/src/http/modules/ngx_http_range_filter_module.o
objs/src/http/modules/ngx_http_headers_filter_module.o
objs/src/http/modules/ngx_http_not_modified_filter_module.o
objs/src/http/ngx_http_busy_lock.o
objs/src/http/ngx_http_file_cache.o
objs/src/http/modules/ngx_http_gzip_filter_module.o
objs/src/http/ngx_http_postpone_filter_module.o
objs/src/http/modules/ngx_http_ssi_filter_module.o
objs/src/http/modules/ngx_http_charset_filter_module.o
objs/src/http/modules/ngx_http_userid_filter_module.o
objs/src/http/modules/ngx_http_autoindex_module.o
objs/src/http/modules/ngx_http_auth_basic_module.o
objs/src/http/modules/ngx_http_access_module.o
objs/src/http/modules/ngx_http_limit_zone_module.o
objs/src/http/modules/ngx_http_limit_req_module.o
objs/src/http/modules/ngx_http_geo_module.o
objs/src/http/modules/ngx_http_map_module.o
objs/src/http/modules/ngx_http_split_clients_module.o
objs/src/http/modules/ngx_http_referer_module.o
objs/src/http/modules/ngx_http_rewrite_module.o
objs/src/http/modules/ngx_http_ssl_module.o
objs/src/http/modules/ngx_http_proxy_module.o
objs/src/http/modules/ngx_http_fastcgi_module.o
objs/src/http/modules/ngx_http_uwsgi_module.o
objs/src/http/modules/ngx_http_scgi_module.o
objs/src/http/modules/ngx_http_memcached_module.o
objs/src/http/modules/ngx_http_empty_gif_module.o
objs/src/http/modules/ngx_http_browser_module.o
objs/src/http/modules/ngx_http_upstream_ip_hash_module.o
objs/addon/src/ndk.o
objs/addon/src/ngx_http_echo_module.o
objs/addon/src/ngx_http_echo_util.o
objs/addon/src/ngx_http_echo_timer.o
objs/addon/src/ngx_http_echo_var.o
objs/addon/src/ngx_http_echo_handler.o
objs/addon/src/ngx_http_echo_filter.o
objs/addon/src/ngx_http_echo_sleep.o
objs/addon/src/ngx_http_echo_location.o
objs/addon/src/ngx_http_echo_echo.o
objs/addon/src/ngx_http_echo_request_info.o
objs/addon/src/ngx_http_echo_subrequest.o
objs/addon/src/ngx_http_echo_foreach.o
objs/addon/src/ngx_http_xss_filter_module.o
objs/addon/src/ngx_http_xss_util.o
objs/addon/src/ngx_http_set_base32.o
objs/addon/src/ngx_http_set_default_value.o
objs/addon/src/ngx_http_set_hashed_upstream.o
objs/addon/src/ngx_http_set_quote_sql.o
objs/addon/src/ngx_http_set_quote_json.o
objs/addon/src/ngx_http_set_unescape_uri.o
objs/addon/src/ngx_http_set_misc_module.o
objs/addon/src/ngx_http_set_escape_uri.o
objs/addon/src/ngx_http_set_hash.o
objs/addon/src/ngx_http_set_local_today.o
objs/addon/src/ngx_http_set_hex.o
objs/addon/src/ngx_http_set_base64.o
objs/addon/src/ngx_http_set_random.o
objs/addon/src/ngx_http_set_hmac.o
objs/addon/src/ngx_http_form_input_module.o
objs/addon/src/ngx_http_encrypted_session_module.o
objs/addon/src/ngx_http_encrypted_session_cipher.o
objs/addon/src/ngx_http_drizzle_module.o
objs/addon/src/ngx_http_drizzle_handler.o
objs/addon/src/ngx_http_drizzle_processor.o
objs/addon/src/ngx_http_drizzle_upstream.o
objs/addon/src/ngx_http_drizzle_util.o
objs/addon/src/ngx_http_drizzle_output.o
objs/addon/src/ngx_http_drizzle_keepalive.o
objs/addon/src/ngx_http_drizzle_quoting.o
objs/addon/src/ngx_http_drizzle_checker.o
objs/addon/src/ngx_http_lua_script.o
objs/addon/src/ngx_http_lua_log.o
objs/addon/src/ngx_http_lua_subrequest.o
objs/addon/src/ngx_http_lua_ndk.o
objs/addon/src/ngx_http_lua_control.o
objs/addon/src/ngx_http_lua_time.o
objs/addon/src/ngx_http_lua_misc.o
objs/addon/src/ngx_http_lua_variable.o
objs/addon/src/ngx_http_lua_string.o
objs/addon/src/ngx_http_lua_output.o
objs/addon/src/ngx_http_lua_headers.o
objs/addon/src/ngx_http_lua_req_body.o
objs/addon/src/ngx_http_lua_uri.o
objs/addon/src/ngx_http_lua_args.o
objs/addon/src/ngx_http_lua_ctx.o
objs/addon/src/ngx_http_lua_regex.o
objs/addon/src/ngx_http_lua_module.o
objs/addon/src/ngx_http_lua_headers_out.o
objs/addon/src/ngx_http_lua_headers_in.o
objs/addon/src/ngx_http_lua_directive.o
objs/addon/src/ngx_http_lua_consts.o
objs/addon/src/ngx_http_lua_exception.o
objs/addon/src/ngx_http_lua_util.o
objs/addon/src/ngx_http_lua_cache.o
objs/addon/src/ngx_http_lua_conf.o
objs/addon/src/ngx_http_lua_contentby.o
objs/addon/src/ngx_http_lua_rewriteby.o
objs/addon/src/ngx_http_lua_accessby.o
objs/addon/src/ngx_http_lua_setby.o
objs/addon/src/ngx_http_lua_capturefilter.o
objs/addon/src/ngx_http_lua_clfactory.o
objs/addon/src/ngx_http_lua_pcrefix.o
objs/addon/src/ngx_http_lua_headerfilterby.o
objs/addon/src/ngx_http_lua_shdict.o
objs/addon/src/ngx_http_headers_more_filter_module.o
objs/addon/src/ngx_http_headers_more_headers_out.o
objs/addon/src/ngx_http_headers_more_headers_in.o
objs/addon/src/ngx_http_headers_more_util.o
objs/addon/src/ngx_http_srcache_filter_module.o
objs/addon/src/ngx_http_srcache_util.o
objs/addon/src/ngx_http_srcache_var.o
objs/addon/src/ngx_http_srcache_store.o
objs/addon/src/ngx_http_srcache_fetch.o
objs/addon/src/ngx_http_array_var_module.o
objs/addon/src/ngx_http_array_var_util.o
objs/addon/src/ngx_http_memc_module.o
objs/addon/src/ngx_http_memc_request.o
objs/addon/src/ngx_http_memc_response.o
objs/addon/src/ngx_http_memc_util.o
objs/addon/src/ngx_http_memc_handler.o
objs/addon/src/ngx_http_redis2_module.o
objs/addon/src/ngx_http_redis2_handler.o
objs/addon/src/ngx_http_redis2_reply.o
objs/addon/src/ngx_http_redis2_util.o
objs/addon/upstream-keepalive-nginx-module-0.3/ngx_http_upstream_keepalive_module.o

objs/addon/auth-request-nginx-module-0.2/ngx_http_auth_request_module.o

objs/addon/src/ngx_http_rds_json_filter_module.o
objs/addon/src/ngx_http_rds_json_processor.o
objs/addon/src/ngx_http_rds_json_util.o
objs/addon/src/ngx_http_rds_json_output.o
objs/addon/src/ngx_http_rds_json_handler.o
objs/addon/src/ngx_http_rds_csv_filter_module.o
objs/addon/src/ngx_http_rds_csv_processor.o
objs/addon/src/ngx_http_rds_csv_util.o
objs/addon/src/ngx_http_rds_csv_output.o
objs/ngx_modules.o
-Bstatic -Wl,-E -lpthread -lcrypt -lssl -ldrizzle
-L/home/david/src/third-party/ngx_openresty-1.0.8.26/build/lua-root/data/local/nginx-resty-1.0.8.26/lua/lib
-llua -lm -lpcre -lssl -lcrypto -ldl -lz

Here’s the full configure line:
./configure --prefix=/data/local/nginx-resty-loko-1.0.8.26
–with-ld-opt=“-Bstatic” --with-http_drizzle_module

Any ideas? Is trying to statically link a never ending struggle I should
give up on early?

Posted at Nginx Forum:

I replied to this, but it seems my reply got lost. I had some responses
and follow-up questions, but I’ll wait a bit to see if this BB will just
post it after a few hours.

Posted at Nginx Forum:

This forum can’t keep up w/ my posts.

Anyway, I figured out how to build a libdrizzle.a, now I need to figure
out how to tell the ngx resty congfigure or gmake steps to slurp it in.

Posted at Nginx Forum:

On Tue, Nov 15, 2011 at 6:35 PM, dannynoonan [email protected]
wrote:

Reading up on the man page for ld caused me to try
–with-ld-opt=“-Bstatic” which gets me past configure, but gmake still
yields an ELF binary that dynamically links out to libdrizzle.

Could you confirm that the file libdrizzle.a indeed exists in your
system?

Any ideas? Is trying to statically link a never ending struggle I should
give up on early?

What’s your gcc’s version? And what does your “uname -a” say? Do you
have the libdrizzle.a file in the right place?

Regards,
-agentzh

On Fri, Nov 18, 2011 at 10:20 AM, dannynoonan [email protected]
wrote:

This forum can’t keep up w/ my posts.

Anyway, I figured out how to build a libdrizzle.a, now I need to figure
out how to tell the ngx resty congfigure or gmake steps to slurp it in.

When you have libdrizzle.a in the right place, then passing proper
–with-ld-opt option for your system (like -static on my system) to
the configure script should be sufficient :slight_smile:

Regards,
-agentzh

To close out the thread, here’s some shell snippets that produce an
nginx binary with libdrizzle statically liniked in:

curl http://agentzh.org/misc/nginx/ngx_openresty-1.0.9.10.tar.gz | tar -zxvf - cd ngx_openresty-1.0.9.10 curl http://agentzh.org/misc/nginx/drizzle7-2011.07.21.tar.gz | tar -zxvf -

build librizzle statically

(cd drizzle7-2011.07.21 && ./configure --without-server
–enable-static && make libdrizzle-1.0)
find . -name libdrizzle.a -exec cp {} . ;
export LIBDRIZZLE_INC=pwd/drizzle7-2011.07.21/libdrizzle-1.0/
export LIBDRIZZLE_LIB=pwd
./configure --prefix=/data/local/nginx-resty-1.0.9.10
–with-http_drizzle_module
–add-module=$HOME/src/third-party/nginx-gridfs
–add-module=$HOME/src/third-party/nginx_upload_module-2.2.0
–with-ld-opt=“-Bstatic”
gmake

[david@dev-3 ngx_openresty-1.0.9.10]$ ldd build/nginx-1.0.9/objs/nginx |
grep drizzle
[david@dev-3 ngx_openresty-1.0.9.10]$

Huzzah!

Posted at Nginx Forum: