# [PATCH v2 1/1] Makefile: link libcurl before openssl and crypto

2 messages from 2015-09-24 to 2015-09-25. Participants: Remi Pommarel, Junio C Hamano.
Thread: https://gitlist.dev/t/40421

## Remi Pommarel, 2015-09-24 17:43

Subject: [PATCH v2 1/1] Makefile: link libcurl before openssl and crypto
Message-ID: <1443116590-6222-1-git-send-email-repk@triplefau.lt>
URL: https://gitlist.dev/e/1443116590-6222-1-git-send-email-repk%40triplefau.lt

```
For static linking especially library order while linking is important. For
example libssl contains symbol from libcrypto so the former should be linked
before the latter.

The global link order should be libcurl then libssl then libcrypto then
libintl and finally zlib.

Signed-off-by: Remi Pommarel <repk@triplefau.lt>
---
 Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index ce0cfe2..59a0747 100644
--- a/Makefile
+++ b/Makefile
@@ -1029,7 +1029,6 @@ ifdef HAVE_ALLOCA_H
 endif
 
 IMAP_SEND_BUILDDEPS =
-IMAP_SEND_LDFLAGS = $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
 
 ifdef NO_CURL
 	BASIC_CFLAGS += -DNO_CURL
@@ -1086,6 +1085,7 @@ else
 		endif
 	endif
 endif
+IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
 
 ifdef ZLIB_PATH
 	BASIC_CFLAGS += -I$(ZLIB_PATH)/include
@@ -1971,10 +1971,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
 
 git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
-		$(LIBS) $(CURL_LIBCURL)
+		$(CURL_LIBCURL) $(LIBS)
 git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
-		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
+		$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
 
 git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \
@@ -1988,7 +1988,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
 
 $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
-		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
+		$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
 
 $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $^
-- 
2.0.1

```

## Junio C Hamano, 2015-09-25 00:15

Subject: Re: [PATCH v2 1/1] Makefile: link libcurl before openssl and crypto
Message-ID: <xmqqmvwbuzep.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqmvwbuzep.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <1443116590-6222-1-git-send-email-repk@triplefau.lt>

```
Remi Pommarel <repk@triplefau.lt> writes:

> For static linking especially library order while linking is important. For
> example libssl contains symbol from libcrypto so the former should be linked
> before the latter.

That example is not a very good one to use for two reasons:

 (1) NEEDS_SSL_WITH_CRYPTO is a conter-example of crypto wanting to
     be before the latter.

 (2) More importantly, you are not changing the order between them.

The breakage you are fixing with this patch is that libcurl want to
come before libssl when building http-push, http-fetch, and remote-curl,
so that is a very good example to use in the above sentence.

```
