2

I'm building a project using the gnu autotools on the mac. Everything compiles fine but I'm having issues linking in with dynamic libraries. How do I specify install_name in my Makefile.am scripts. I thought it might be something like the following:

    lib_LTLIBRARIES = libphysics.la

    libphysics_la_SOURCES = PhysicsEngine.cpp\
       PointMass.cpp\
       Spring.cpp\
       WaterForceGenerator.cpp

    AM_CPPFLAGS=  @CXXFLAGS@\
        -I../include\
        -Iinclude\
        -I../evolutionaryStuff/include\
        -I../geom/include\
        -I../model/include\
        -I../paramsReader/include\
        -I../ctrnn/include\
        -I../simulationSystem/include

    AM_LDFLAGS= @LDFLAGS@ \
        -install_name "./.libs/libphysics.0.dylib"

...yet when I do:

otool -D libphysics.0.dylib

in the .libs directory I get

/usr/local/lib/libphysics.0.dylib

(but I want it to something like .libs/libphysics.0.dylib)

I know it must be something simple, any ideas?

Thanks,

Ben.

Ben J
  • 1,367
  • 2
  • 15
  • 33

1 Answers1

1

After hacking around, it seems that the correct entry in the Makefile.am file should be:

    AM_LDFLAGS= @LDFLAGS@\
             -Xlinker -rpath -Xlinker "`pwd`/.libs"\
             -Xlinker -install_name -Xlinker "`pwd`/.libs/libphsyics.0.dylib"

I don't know why this works. The trick was to add pairs of '-Xlinker' flags before and after each of '-rpath' and '-install_name'. If anyone can tell me why this is necessary, I'd be grateful.

Thanks,

Ben.

EDIT: I should point out that the post How to set the runtime path (-rpath) of an executable with gcc under Mac OSX? was helpful in working this out.

Community
  • 1
  • 1
Ben J
  • 1,367
  • 2
  • 15
  • 33