fletcher / MultiMarkdown-4

This project is now deprecated. Please use MultiMarkdown-6 instead!
https://github.com/fletcher/MultiMarkdown-5
Other
307 stars 59 forks source link

Building static binary #84

Closed ghost closed 10 years ago

ghost commented 10 years ago

I compiled mmd-4 on a local Ubuntu machine and transferred it to a remote Debian Wheezy server. When I try to run the binary on the remote,

./multimarkdown: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by ./multimarkdown)

The error simply means that Glibc libc6 was being linked dynamically instead of statically. GCC accepts -static option to create a standlone, statically-linked binaries. I got it working by changing the top-level Makefile to:

$(PROGRAM) : $(OBJS)
        $(CC) $(CFLAGS) -static -static-libgcc -o $@ $(OBJS)

So, this bug report is for requesting to add this functionality. The default makefile target could be changed to build statically or may be create separate target, say, make static which will build the static version. Either of them are fine with me.

EDIT: The following patch seems to work for enabling make static:

diff --git a/Makefile b/Makefile
index 9e8b8e0..433af0e 100644
--- a/Makefile
+++ b/Makefile
@@ -17,10 +17,14 @@ exec_prefix = $(prefix)
 # Where to put the executable
 bindir = $(exec_prefix)/bin

+ifeq ($(MAKECMDGOALS),static)
+LDFLAGS += -static -static-libgcc
+endif

 GREG= greg/greg

 ALL : $(PROGRAM) enumMap.txt
+static: $(PROGRAM) enumMap.txt

 %.o : %.c parser.h
    $(CC) -c $(CFLAGS) -o $@ $<
@@ -32,7 +36,7 @@ $(GREG): greg
    $(MAKE) -C greg

 $(PROGRAM) : $(OBJS)
-   $(CC) $(CFLAGS) -o $@ $(OBJS)
+   $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS)

 install: $(PROGRAM) | $(prefix)/bin
    install -m 0755 multimarkdown $(prefix)/bin
fletcher commented 10 years ago

MMD-4 doesn't use glibc (and it never did... Nor does MMD-3 for quite a while). So you're doing something incorrectly.

ghost commented 10 years ago

Oops. I meant libc6 not glibc. I believe libc6 is being linked in. For example, the question here refers to the same.

nm ./multimarkdown | grep libc
   :
0000000000728820 B __libc_argc
0000000000728828 B __libc_argv
  :   
fletcher commented 10 years ago

nm multimarkdown | grep libc on Mac OS X is empty. On Ubuntu 13.10, it results in __libc_csu_fini, __libc_csu_init, and __libc_start_main@@GLIBC_2.2.5.

It appears that everything is handled differently based on the environment/OS. The changes you suggest fail when run on Mac OS X, but seem to work on Ubuntu 13.10. I don't know whether this is an entirely good idea, but I added the changes to the Makefile to allow make static.

ghost commented 10 years ago

Thanks, I just pulled in your commit, confirm that it works.

fletcher commented 10 years ago

Glad to hear it!