Generating .dylib from C source On the command line

Context:

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

What I need:

I want to turn this code into a .dylib file that can then be linked to my Cocoa application. Once I have the dylib file, I'm fine. What I am struggling with is how to CREATE the dylib file in the first place.

Before you yell at me, yeah, my ass is gone. But I cannot find a direct explanation of what I need to do on the command line in order to compile this collection of C source files to .dylib. Everything I am running into is collapsed or talking about creating a dylib project in Xcode or is outdated. (I found several links for this with GCC, but I'd like to use LLVM.)

Make installation

From what I'm about, running a typical "make install" should put the .dylib file in / usr / lib, but that doesn't seem to be happening for me.

Bottom line:

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

+3


source to share


1 answer


This project does not create a dynamic link library by default on Mac OS X. I made a quick patch to the makefile which 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 this to your tree after running the configure script and before building it and it should work. If you just want the lightweight part, run:



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 the command line after creating a regular package, you need to create a dynamic library for you. Then you can install it to your file.

+1


source







All Articles