<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Sorry to have cluttered the list with all this nonsense, but I
    solved my problem all by my lonesome. It is all kludge, but it
    works. The elegant solution (I think) is to write a nice .configure
    script that will generate exactly the right makefile regardless of
    os and configuration, but I don't know how to do that.<br>
    <br>
    So, in the meantime one way to link libraries when building Pd
    externs (this is for Mac, but it should be pretty much the same on
    any Unix outfit) is like this:<br>
    modify the file <br>
    <br>
    '/'whatever'/Pd.etc/Contents/Resources/extra/makefile' <br>
    <br>
    so that the first line reads:<br>
    <br>
    'current: pd_darwin'<br>
    <br>
    then in the section that sets the rules and recipes for building on
    make it looks so:<br>
    <br>
    'pd_darwin: $(NAME).pd_darwin<br>
    <br>
    .SUFFIXES: .pd_darwin<br>
    <br>
    DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \<br>
    &nbsp;&nbsp;&nbsp; -Wno-unused -Wno-parentheses -Wno-switch<br>
    <br>
    .c.pd_darwin:<br>
    &nbsp;&nbsp;&nbsp; $(CC) -arch i386&nbsp; $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c
    $*.c<br>
    &nbsp;&nbsp;&nbsp; $(CC) -arch i386 $(LIBS) -bundle -undefined suppress
    -flat_namespace \<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -o $*.pd_darwin $*.o <br>
    &nbsp;&nbsp;&nbsp; rm -f $*.o'<br>
    <br>
    I took out all the '.d_ppc' and '-arch ppc' stuff that's in the
    makefile that comes with Pd (vanilla) because I have an intel core
    so ppc junk is irrelevant. I changed .d_fat to .pd_darwin, because
    somebody who actually knows stuff (unlike me) told me that
    .pd_darwin is the current convention. The variable 'LINUXINCLUDE' is
    simply '-I../../src' and is here recycled from a previous definition
    in the makefile. It has nothing to do with linux whatsoever. It just
    tells the compiler to look at the Pd source code when you hit make
    on your external. The other big change I made is inserting the
    'LIBS' variable in the second build phase instruction which I shall
    explain below. It is a simple matter to implement analogous
    modifications in the other unix-ish portions of the makefile, but I
    haven't tested it yet. I don't know anything about Windows...<br>
    <br>
    Now that the pd makefile is ready to go, go into your extern project
    directory and make a makefile there that looks like so:<br>
    <br>
    'NAME=awesomeExtern<br>
    CSYM=awesomeExtern<br>
    <br>
    include /'whatever'/Pd.etc/Contents/Resources/extra/makefile&nbsp;&nbsp; <br>
    <br>
    DARWINCFLAGS += -I/path/to/awesome-library/headers etc.<br>
    LIBS = -L/path/to/awesome-library -lawesomelibrary etc.'<br>
    <br>
    I put 'etc.' in there because there may be more than one header file
    or library that you want to use. You can discover what you need by
    putting<br>
    <br>
    'pkg-config --cflags awesomelibraryA awesomelibraryB etc.'<br>
    <br>
    into the command line. These return values are what you want to <i>add</i>
    (note the '+=') to the 'DARWINCFLAGS' variable. Likewise the return
    of <br>
    <br>
    'pkg-config --libs awesomelibraryA awesomelibraryB etc.'<br>
    <br>
    is what you want to be associated with the 'LIBS' variable. On Mac
    osx 5 (don't know about 6), the path is usually /opt/local/include
    and /opt/local/lib. On Unix/Linux I believe it is typically
    /usr/local/include and /usr/local/lib where libraries get installed.<br>
    <br>
    Sorry if this is old-hat to all the C honchos out there and
    irrelevant to everyone else (as I suspect is the case). I'm sure it
    is about a million times easier if you use Xcode to develop your
    externs, but then you would have to use Xcode. If this is
    helpful/relevant to people I'd be happy to clean up this little
    tutorial and post it to the Pd wiki.<br>
    <br>
    Best,<br>
    David<br>
    <br>
    <br>
    On 1/20/11 4:55 PM, david medine wrote:
    <blockquote cite="mid:4D38D96C.1040609@ucsd.edu" type="cite">
      <br>
      OK, nuts to that. First, I must correct myself, the makefile I am
      referring to is in the Pd.etc.app/Contents/Resources/extra folder.
      (By the way, I am at home working on my Mac right now, I haven't
      tried this on my beastly linux box at all yet and so I am not sure
      what all the details of this issue are there off the top of my
      head.)
      <br>
      <br>
      Also, I went ahead and dropped the -c flag from the makefile (this
      flag stops linking altogether when make is run) and apparently
      when you do this, the extern won't build at all! I think this has
      something to do with the fact that in this mode, gcc needs to link
      with all the Pd objects also, (because terminal tells me so...)
      but this explanation doesn't really make sense to me.
      <br>
      <br>
      Does anyone know how to tweak the makefile (or any clean method,
      for that matter) so that one can link libraries to externals?
      <br>
      Thanks again,
      <br>
      David
      <br>
      <br>
      On 1/20/11 4:02 PM, david medine wrote:
      <br>
      <blockquote type="cite">Dear folks,
        <br>
        Does anybody know a good way to link libraries in a Pd extern
        build? I am using plain ol' command line and makefiles. It would
        be nice to be able to do this without modifying the Makefile in
        the Pd.etc./Contents/Resources/ directory, but due to my general
        ignorance of programming lore, I don't really know how to do
        this. Any suggestions?
        <br>
        Thanks,
        <br>
        David Medine
        <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>