Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing a static build curl, but curl don't link static libraries. #503

Closed
KangLin opened this issue Oct 22, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@KangLin
Copy link

commented Oct 22, 2015

I am doing a static build curl, but curl don't link static libraries, it link dynamic library. libtool does not use parameters -static. What should I do?

Configure:
../configure --enable-static --disable-shared LDFLAGS="-static" --enable-sse --prefix=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --disable-manual --enable-verbose --with-ssl=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static --with-sysroot=/d/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static

Link output:
_/bin/sh ../libtool --tag=CC --mode=link gcc_ -O2 -Wno-system-headers -static -LD:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib -o curl.exe curl-slist_wc.o curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_strdup.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o ../lib/libcurl.la -lssh2 -lssl -lcrypto -lssl -lws2_32 -lgdi32 -lcrypt32 -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lgdi32 -lwldap32 -lz -lws2_32
_libtool: link: gcc_ -O2 -Wno-system-headers -o curl.exe curl-slist_wc.o curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_strdup.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o -LD:/source/rabbitim/ThirdLibary/build_script/../windows_mingw_static/lib ../lib/.libs/libcurl.a -lssh2 -lssl -lcrypto -lcrypt32 -lgdi32 -lwldap32 -lz -lws2_32

@bagder

This comment has been minimized.

Copy link
Member

commented Oct 22, 2015

Well, I see -static getting passed to libtool. I'm not sure what else we can do so I question how this is curl issue... Also note that libtool has a -all-static option as well that might be different, I'm not that into static linking.

@bagder bagder added the build label Oct 22, 2015

@jay

This comment has been minimized.

Copy link
Member

commented Oct 23, 2015

I can reproduce that here. libtool strips -static. LDFLAGS=-all-static I don't get very far:

configure:4259: gcc   -all-static conftest.c  >&5
gcc.exe: error: unrecognized command line option '-all-static'

However I can do it by overriding curl_LDFLAGS for make, then libtool will work it properly. Here is how I have a static build of curl in MinGW with OpenSSL and zlib:

LDFLAGS="-static" PKG_CONFIG="pkg-config --static" ./configure --disable-shared --enable-static --prefix=/x/j/curl/mingw/root --with-ssl=/x/j/curl/mingw/root >config.out 2>&1
make V=1 curl_LDFLAGS=-all-static > make.out 2>&1
make install curl_LDFLAGS=-all-static
curl 7.46.0-DEV (i686-pc-mingw32) libcurl/7.46.0-DEV OpenSSL/1.0.2d zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s
 rtsp smb smbs smtp smtps telnet tftp
Features: Largefile NTLM SSL libz TLS-SRP

It will depend on Windows system DLLs like wldap, ws2_32 etc, but there shouldn't be any third party dependences if and only if there are static versions available of those dependencies. For example I have OpenSSL both static and dynamic libs installed, same for zlib. And curl.exe was built with the static zlib and openssl via this method.

This also makes libcurl a static library libcurl.a, but if you want to link it in your program then you're going to have to use -static for gcc and pkg-config --static so you know what libraries are needed, like this

cat << EOF > a.c
#include <curl/curl.h>
int main() {
printf("%s\n", curl_version());
return 0;
}
EOF
export PKG_CONFIG_PATH=/x/j/curl/mingw/root/lib/pkgconfig
gcc -static -o a a.c `pkg-config --static --cflags libcurl` `pkg-config --static --libs libcurl`
./a
unset PKG_CONFIG_PATH

@jay jay closed this Oct 23, 2015

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.