do not add common-main to lib
PATCH 1/1 do not add common-main to lib
From: Christian Hesse <[email protected]>
Commit 08aade70 (mingw: declare main()'s argv as const) changed declaration of main function. This breaks linking external projects (e.g. cgit) to libgit.a with:
error: Multiple definition of `main'
So do not add common-main to lib and let projects have their own main function.
--- Makefile | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
Makefile +13 -12
@@ -953,7 +953,8 @@ BUILTIN_OBJS += builtin/verify-tag.o BUILTIN_OBJS += builtin/worktree.o BUILTIN_OBJS += builtin/write-tree.o -GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) +GITLIBS = $(LIB_FILE) $(XDIFF_LIB) +GITCOMMON = common-main.o $(GITLIBS) EXTLIBS = GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -1593,15 +1594,15 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH)) DIFF_SQ = $(subst ','\'',$(DIFF)) PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA)) -# We must filter out any object files from $(GITLIBS), +# We must filter out any object files from $(GITCOMMON), # as it is typically used like: # -# foo: foo.o $(GITLIBS) +# foo: foo.o $(GITCOMMON) # $(CC) $(filter %.o,$^) $(LIBS) # # where we use it as a dependency. Since we also pull object files # from the dependency list, that would make each entry appear twice. -LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS) +LIBS = $(filter-out %.o, $(GITCOMMON)) $(EXTLIBS) BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \ $(COMPAT_CFLAGS)
@@ -1741,7 +1742,7 @@ git.sp git.s git.o: EXTRA_CPPFLAGS = \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ '-DGIT_INFO_PATH="$(infodir_relative_SQ)"' -git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) +git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \ $(filter %.o,$^) $(LIBS)
@@ -2033,21 +2034,21 @@ compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \ compat/nedmalloc/nedmalloc.sp: SPARSE_FLAGS += -Wno-non-pointer-null endif -git-%$X: %.o GIT-LDFLAGS $(GITLIBS) +git-%$X: %.o GIT-LDFLAGS $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) -git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS) +git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(IMAP_SEND_LDFLAGS) -git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS) +git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(CURL_LIBCURL) $(LIBS) -git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS) +git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS) -git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB) +git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITCOMMON) $(VCSSVN_LIB) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \ $(VCSSVN_LIB)
@@ -2057,7 +2058,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY) ln -s $< $@ 2>/dev/null || \ cp $< $@ -$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS) +$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
@@ -2271,7 +2272,7 @@ t/helper/test-svn-fe$X: $(VCSSVN_LIB) .PRECIOUS: $(TEST_OBJS) -t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) +t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITCOMMON) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS) check-sha1:: t/helper/test-sha1$X
Signature · 1 line
2.9.3
Quoted 7 lines · Christian Hesse
From: Christian Hesse <[email protected]>
Commit
08aade70(mingw: declare main()'s argv as const) changed declaration of main function. This breaks linking external projects (e.g. cgit) to libgit.a with:error: Multiple definition of `main'
I'd expect the culprit is actually 3f2e229 (add an extra level of indirection to main(), 2016-07-01).
Quoted 2 lines
So do not add common-main to lib and let projects have their own main function.
That is certainly an option, but I think it means that those projects are potentially buggy in the same way that some git commands were prior to the common-main series. Namely, the common main() may do some run-time setup that parts of libgit.a assume has been done.
I would not be surprised if cgit crashes on Windows, for instance, for the reasons detailed in 650c449 (common-main: call git_extract_argv0_path(), 2016-07-01). I would also not be surprised if nobody actually builds cgit on Windows. :)
The "right" way to do it (according to the way libgit.a views the world) is for cgit's main to become cmd_main(), and let libgit.a do its run-time startup before getting there.
-Peff
Hi Christian,
Quoted 10 lines · Christian Hesse
From: Christian Hesse <[email protected]>
Commit
08aade70(mingw: declare main()'s argv as const) changed declaration of main function. This breaks linking external projects (e.g. cgit) to libgit.a with:error: Multiple definition of `main'
So do not add common-main to lib and let projects have their own main function.
I am opposed to this change.
For one, libgit.a is *not* a library with an API, for a good reason:
nothing in Git's development guarantees any kind of stable API. For that reason, libgit.a is not installed, either, and neither are any headers.
And even more importantly: *iff* you *insist* on using libgit.a in your project *despite* having been told not to, it is your responsibility to stay up-to-date with the requirements of it.
One such requirement is that you now implement cmd_main() instead of main().
So if you want to continue to have an out-of-tree project that links against the (private) libgit.a, it is your out-of-tree project that needs changing, not libgit.a.
Ciao,
Johannes
Johannes Schindelin <[email protected]> on Mon, 2016/08/15 14:20:
Quoted 10 lines
Hi Christian,
Quoted 6 lines · Christian Hesse
From: Christian Hesse <[email protected]>
Commit
08aade70(mingw: declare main()'s argv as const) changed declaration of main function. This breaks linking external projects (e.g. cgit) to libgit.a with:
Quoted 6 lines
Quoted 4 lines
error: Multiple definition of `main'
So do not add common-main to lib and let projects have their own main function.
I am opposed to this change.
Me too. :-p
Quoted 7 lines
For one, libgit.a is *not* a library with an API, for a good reason:
nothing in Git's development guarantees any kind of stable API. For that reason, libgit.a is not installed, either, and neither are any headers.And even more importantly: *iff* you *insist* on using libgit.a in your project *despite* having been told not to, it is your responsibility to stay up-to-date with the requirements of it.
cgit pulls in the git tree as a subproject. We are aware that the API changes all the time and that's fine. Usually we just fix it, this time I missed the background information of the change.
Quoted 6 lines
One such requirement is that you now implement
cmd_main()instead ofmain().So if you want to continue to have an out-of-tree project that links against the (private) libgit.a, it is your out-of-tree project that needs changing, not libgit.a.
Already updated my code. ;)
Thanks!
Signature · 3 lines
main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH"
"CX:;",b;for(a/* Best regards my address: */=0;b=c[a++];)
putchar(b-1/(/* Chris cc -ox -xc - && ./x */b/42*2-3)*42);}Jeff King <[email protected]> on Mon, 2016/08/15 08:02:
Quoted 12 lines · Christian Hesse
Quoted 8 lines
From: Christian Hesse <[email protected]>
Commit
08aade70(mingw: declare main()'s argv as const) changed declaration of main function. This breaks linking external projects (e.g. cgit) to libgit.a with:error: Multiple definition of `main'
I'd expect the culprit is actually 3f2e229 (add an extra level of indirection to
main(), 2016-07-01).
Ah, probably you are right...
Quoted 7 lines
Quoted 2 lines
So do not add common-main to lib and let projects have their own main function.
That is certainly an option, but I think it means that those projects are potentially buggy in the same way that some git commands were prior to the common-main series. Namely, the common
main()may do some run-time setup that parts of libgit.a assume has been done.
Ok, got it.
Quoted 4 lines
I would not be surprised if cgit crashes on Windows, for instance, for the reasons detailed in 650c449 (common-main: call
git_extract_argv0_path(), 2016-07-01). I would also not be surprised if nobody actually builds cgit on Windows. :)
I never tried and probably nobody else did. :-p
Quoted 3 lines
The "right" way to do it (according to the way libgit.a views the world) is for cgit's main to become
cmd_main(), and let libgit.a do its run-time startup before getting there.
Looks like that does the job. I will give it some more testing.
Please ignore my patch... ;)
Thanks a lot!
Signature · 3 lines
main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH"
"CX:;",b;for(a/* Best regards my address: */=0;b=c[a++];)
putchar(b-1/(/* Chris cc -ox -xc - && ./x */b/42*2-3)*42);}