質問

Context:

I have downloaded the source code for "Discount", which is a simple C program. The code is online here: http://www.pell.portland.or.us/~orc/Code/discount/

What I Need:

I want to turn this code into a .dylib file that I can then bundle with my Cocoa app. Once I HAVE the dylib file, I'm fine. What I'm struggling with is how to CREATE the dylib file in the first place.

Before you yell at me, YES I have Googled my ass off. But I cannot find a straightforward explanation of exactly what I need to do at the command line to compile this collection of C source files into a .dylib. Everything I come across is convoluted or talks about building a dylib project in Xcode or is outdated. (I've found some references for doing it with GCC, but I'd like to use LLVM.)

Make Install

From what I gather, running the typical "make install" is supposed to put a .dylib file into /usr/lib, but that does not seem to be happening for me.

Bottom Line:

Once I've downloaded the Discount source code, what do I need to do at the command line to create a .dylib file on OS X 10.8.2? Thank you.

役に立ちましたか?

解決

That project by default doesn't create a dynamic library on Mac OS X. I made a quick patch to the makefile that seems to work:

From a3d6793c5f291d253b8e7aa99e5534503808c325 Mon Sep 17 00:00:00 2001
From: Carl Norum <carl@norum.ca>
Date: Thu, 31 Jan 2013 16:59:24 -0800
Subject: [PATCH] Patch to generate a dynamic library.

---
 Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 8532e70..11805dd 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@ install: $(PGMS) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR)
    /usr/bin/install -s -m 755 $(PGMS) $(DESTDIR)$(BINDIR)
    ./librarian.sh install libmarkdown VERSION $(DESTDIR)$(LIBDIR)
    /usr/bin/install -m 444 mkdio.h $(DESTDIR)$(INCDIR)
+   /usr/bin/install -m 755 $(MKDLIB).dylib $(DESTDIR)$(LIBDIR)

 install.everything: install install.samples install.man

@@ -82,7 +83,7 @@ theme:  theme.o $(MKDLIB) mkdio.h
 mkd2html:  mkd2html.o $(MKDLIB) mkdio.h
    $(CC) $(LFLAGS) -o mkd2html mkd2html.o -lmarkdown 

-markdown: main.o pgm_options.o $(MKDLIB)
+markdown: main.o pgm_options.o $(MKDLIB) $(MKDLIB).dylib
    $(CC) $(LFLAGS) -o markdown main.o pgm_options.o -lmarkdown 

 makepage:  makepage.c pgm_options.o $(MKDLIB) mkdio.h
@@ -94,6 +95,9 @@ pgm_options.o: pgm_options.c mkdio.h config.h
 main.o: main.c mkdio.h config.h
    $(CC) -I. -c main.c

+$(MKDLIB).dylib: $(OBJS)
+   $(CC) -dynamiclib -o $(MKDLIB).dylib $(OBJS)
+
 $(MKDLIB): $(OBJS)
    ./librarian.sh make $(MKDLIB) VERSION $(OBJS)

-- 
1.7.12.1

You can apply that to your tree after running the configure script and before building and it should work out. If you just want the easy part, running:

cc -Wno-implicit-int -I. -dynamiclib -o libmarkdown.dylib mkdio.o markdown.o dumptree.o generate.o resource.o docheader.o version.o toc.o css.o xml.o Csio.o xmlpage.o basename.o emmatch.o github_flavoured.o setup.o tags.o html5.o flags.o 

on your command line after building the regular package should generate the dynamic library for you. You can then install it yoursef.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top