Tyler Tyler - 2 months ago 16
C++ Question

Dyld Library not loaded: Reason: Image not found

I know that questions on this have been asked before but I have been unable to resolve my issue using any of their solutions. I am trying to use the DISLIN plotting library on Mac with Xcode. (OS: Yosemite, Xcode Ver: 6.1.1).

I am currently just trying to run a very simple test program:

#include <stdio.h>
#include <iostream> // Required by DISLIN!
#include "dislin.h" // Required by DISLIN! Includes the
// plotting package
using namespace std;
int main(int argc, char *argv[])
{
int numberOfPoints = 2;
float x[2] = {0, 1};
float y[2] = {0, 2};

cout << x << y << endl ;
qplot(x, y, numberOfPoints);
}


The error I get when trying to run is:

dyld: Library not loaded: /usr/local/lib/libdiscpp.10.dylib
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/phys239_a2-blbdrjqdqxewuwfvvdxelytbfmzs/Build/Products/Debug/phys239_a2
Reason: image not found
Program ended with exit code: 9


The program compiles just fine, but it will not run. I have installed Dislin with a package from the dislin website (dislin.de) and openmotif via homebrew. I have the project linked with both the dislin and openmotif libraries (located in /usr/local/dislin/ and /usr/local/Cellar/openmotif/2.3.4/lib respectively).

Does anyone have any experience with this? Or, has anyone been able to get dislin working with Xcode before?

Answer

So, the point of this whole thing was to get dislin running with Xcode and it looks like I've finally made some solid headway, as I can produce an actual plot. Hopefully there are no new surprises.

In order to make this happen here's what I did.

  • Download Dislin (dislin-10.5.darwin.intel.64.tar.gz from dislin.de, in the downloads section)

  • Make sure you have an up-to-date installation of X11. This is where I got it. (http://xquartz.macosforge.org/landing/)

  • Using homebrew, I installed openmotif. This is required by dislin. I used the following command:

brew install https://gist.githubusercontent.com/steakknife/60a39a32ae84e12238a2/raw/openmotif.rb

which I found here: https://gist.github.com/steakknife/60a39a32ae84e12238a2

  • Then I added the following lines to ./bash_profile

    export DISLIN=/usr/local/dislin DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/dislin:/usr/local/Cellar/openmotif/2.3.4/lib/:/opt/X11/lib PATH=$PATH:$DISLIN/bin

I know that the whole DYLD_LIBRARY_PATH thing is maybe not the best, and I honestly don't even know if it actually matters in my installation, but it's working at the moment and I'm not going to try messing with it yet.

  • Install dislin. Change to the folder that you downloaded it to and run the command ./INSTALL

  • Now open up Xcode and start a new console application. You will need to make sure that you can link with these libraries properly. In 'Build Settings', to the header search paths I have added /usr/local/dislin/real64 (there are two 'dislin.h' files. If I don't use the one in this folder, the results I see are garbage.) To the library search paths I have added '/usr/local/dislin/liband/usr/local/Cellar/openmotif/2.3.4/lib`

  • In 'Build Phases' add the libraries from the two library folders above.

I then ran the following program:

#include <iostream>
#include <dislin.h>

double f(double aX)
{
    return aX * aX ; // Function to be plotted
}

int main()
{
    double x[11], y[11] ;
    double del = 0.1 ; 
    for( int i = 0 ; i < 11 ; i++)
    {
        x[i] = i * del ; 
        y[i] = f(x[i]) ; 
    }
    metafl("PDF") ; 
    disini() ;
    name( "X-Axis", "x" ) ;
    name( "Y-axis", "y" ) ; 
    qplsca(x, y, 11) ; 
}

And it produced this output: Dislin Output

That's where I'm at. Hopefully this can help someone at some point.