Dynamic libraries and make install

by raulzito234

I finally solved the problem that has been hunting me since the beginning of this week. There are some lessons that I’ve learned doing this work:

Dynamic linking libraries at compiling time is different than dynamic linking then at runtime. Both need to be done.

To link during compile time you need to do the following:

Add the header files to the directories of header files that are included, the option -I does that.

For adding dynamic libraries, the option -L adds directories to the list of directories that the compiler will look for the libraries. The -l will add the library itself (the name)

For resolving the linking issues when running the binary:

Either you can create a install option, by doing the following:

1. Copying the libraries to the common library directorye

>> install:
>> cp ./lib/libsegmentImage.dylib /usr/lib


2. Change the $DYLD_LIBRARY_PATH to the directory of the libraries:

>> export DYLD_LIBRARY_PATH=/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/runtime/maci64/

Other tips:

To debug problems when running a binary file, the following tool can help to find what and where the problem is happening:

>> dtruss ./KinectVideoHandler 2> out
>> less out

Another way of doing that is to:

Create a text file:

>>  #!/bin/sh
>>  # set dynamic preload library path
>>  export DYLD_LIBRARY_PATH=/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/runtime/maci64/
>>  ./KinectVideoHandler