How to build PyLith and link it to external dynamic libraries in macOS?

Hi Brad,

I am trying to build Pylith from source and link it to an external dynamic library but I am facing issues.

For example, in the code below I link a simple C++ code to my dynamic library called DataLib.dylib. The executable only works if I use install_name_tool to change the relative path of the executable file (@rpath) to the absolute path of the library.

export DYLD_LIBRARY_PATH='/home/bin/maci64:/home/sys/os/maci64':$DYLD_LIBRARY_PATH

g++ -o myCodeCxx  myCodeCxx.cpp -v -std=c++11 -I/home/extern/include -L/home/extern/bin/maci64 -lDataLib 

# myCodeCxx will only work if I change from the relative path to the absolute:
install_name_tool -change @rpath/libMatlabEngine.dylib /home/extern/bin/maci64/DataLib.dylib myCodeCxx`

When building Pylith, I modified the main Makefile that is created right after calling ./configure to include also -I/home/extern/include, -L/home/extern/bin/maci64 and -lDataLib.

The whole building process finished without any errors. However, when I try to run pylith I get the following error message, which indicates that the Pylith executable did not find my dynamic library:

Traceback (most recent call last):
  File "/home/Install/pylith/bin/pylith", line 25, in <module>
    from pylith.apps.PyLithApp import PyLithApp
  File "/home/Install/pylith/lib/python2.7/site-packages/pylith/apps/PyLithApp.py", line 23, in <module>
    from PetscApplication import PetscApplication
  File "/home/Install/pylith/lib/python2.7/site-packages/pylith/apps/PetscApplication.py", line 27, in <module>
    class PetscApplication(Application):
  File "/home/Install/pylith/lib/python2.7/site-packages/pylith/apps/PetscApplication.py", line 41, in PetscApplication
    from pylith.utils.PetscManager import PetscManager
  File "/home/Install/pylith/lib/python2.7/site-packages/pylith/utils/PetscManager.py", line 29, in <module>
    import pylith.utils.petsc as petsc
  File "/home/Install/pylith/lib/python2.7/site-packages/pylith/utils/petsc.py", line 28, in <module>
    _petsc = swig_import_helper()
  File "/home/Install/pylith/lib/python2.7/site-packages/pylith/utils/petsc.py", line 24, in swig_import_helper
    _mod = imp.load_module('_petsc', fp, pathname, description)
ImportError: dlopen(/home/Install/pylith/lib/python2.7/site-packages/pylith/utils/_petscmodule.so, 2): Symbol not found: _cpp_engine_cancel_feval_with_completion
  Referenced from: /home/Install/pylith/lib/libpylith.0.dylib
  Expected in: flat namespace
 in /home/Install/pylith/lib/libpylith.0.dylib

The error message above seems in agreement with what I find with my simple C++ code if I don’t run the install_name_tool on the main executable file. Note that I am setting the DYLD_LIBRARY_PATH variable to the correct locations of my library, like I did with my simple C++ code.

My questions are:

  1. Could you please let me know how do I find the main pylith executable file so that I can try using the install_name_tool ? when I try which pylith I get a path to file that gives an error to install_name_tool.
  2. Would you have any suggestions to fix this issue ? Perhaps a way to include the install_name_tool on the main Makefile ?

Note the following: I repeated the same procedure on a Linux computer and everything went fine and I was able to link it to my external library, which unfortunately does not happen on macOS system.

Thanks in advance for you help.

Use otool -L LIBRARY.dylib to see how the paths to other dynamic libraries are being resolved. I believe DYLD_LIBRARY_PATH is no longer supported on under Mac OS X.

The PyLith executable is just a Python script, so you can’t run install_name_tool on it. The libraries and Python modules are what have paths to other dynamic libraries. You shouldn’t need to use install_name_tool unless you move libraries. Everything should be handled properly with the proper link lines. You can adjust the local Makefile.am for all of the libraries and modules making use of the external library.