# [PATCH v4 1/1] Makefile: link libcurl before zlib

2 messages from 2015-10-21 to 2015-10-21. Participants: Remi Pommarel, Jonathan Nieder.
Thread: https://gitlist.dev/t/40609

## Remi Pommarel, 2015-10-21 17:01

Subject: [PATCH v4 1/1] Makefile: link libcurl before zlib
Message-ID: <1445446873-21294-1-git-send-email-repk@triplefau.lt>
URL: https://gitlist.dev/e/1445446873-21294-1-git-send-email-repk%40triplefau.lt

```
For static linking especially library order while linking is important. For
example, libcurl wants symbols from zlib when building http-push, http-fetch
and remote-curl. So for these programs libcurl has to be linked before zlib.

Signed-off-by: Remi Pommarel <repk@triplefau.lt>
---
Changes to v3:
	- Initialize IMAP_SEND_LDFLAGS so that no environment leak could occur
	- Rephrase the description to use zlib example instead of libcurl

 Makefile | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 04c2231..8f1fa6c 100644
--- a/Makefile
+++ b/Makefile
@@ -1036,7 +1036,7 @@ ifdef HAVE_ALLOCA_H
 endif
 
 IMAP_SEND_BUILDDEPS =
-IMAP_SEND_LDFLAGS = $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
+IMAP_SEND_LDFLAGS =
 
 ifdef NO_CURL
 	BASIC_CFLAGS += -DNO_CURL
@@ -1093,6 +1093,7 @@ else
 		endif
 	endif
 endif
+IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
 
 ifdef ZLIB_PATH
 	BASIC_CFLAGS += -I$(ZLIB_PATH)/include
@@ -1978,10 +1979,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) \
@@ -1995,7 +1996,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) $(ARFLAGS) $@ $^
-- 
2.0.1

```

## Jonathan Nieder, 2015-10-21 19:35

Subject: Re: [PATCH v4 1/1] Makefile: link libcurl before zlib
Message-ID: <20151021193514.GB7881@google.com>
URL: https://gitlist.dev/e/20151021193514.GB7881%40google.com
In-Reply-To: <1445446873-21294-1-git-send-email-repk@triplefau.lt>

```
Remi Pommarel wrote:

> Signed-off-by: Remi Pommarel <repk@triplefau.lt>

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.

```
