help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linking to .mex file's library from c++


From: gOS
Subject: Linking to .mex file's library from c++
Date: Thu, 7 Aug 2008 13:26:01 -0700 (PDT)

Hello all,

I've got a problem that I'm hitting a brick wall with. As usual, I'm on a
Windows XP machine. I'm running Octave 3.0.1 and I'm working with mex files.
There appears to be precidence for doing what I want to do, which is getting
C++ to be able to call Octave code. I wanted to start by linking to the .lib
of a simple .mex file.

So, I created the following code (addLib.cpp):

_________________________________________________________________________

#include "mex.h"
#include <iostream>

class addLib {
private:

public:
        addLib();
        double add(double* v1, double* v2);
        void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[]);
};

addLib::addLib() {}

void addLib::mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[]) {
        double *a, *b;
        a = mxGetPr(prhs[0]);
        b = mxGetPr(prhs[1]);
        
        plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); // Works
        double* result = (double*) mxGetPr(plhs[0]);
        result[0] = add(a,b);   
}

double addLib::add(double* v1, double* v2) {
        return v1[0] + v2[0];
}

_________________________________________________________________________

Using Tatsuro's guide I had previously set up a compiler, and with more help
was able to get debugging to work too. The next thing I'd like to do is go
the other other direction and call Octave and its libraries from c++.
Anyway, compilation went through and was entirely successful. I can run
addLib from Octave without a problem and debug it as well.

Unfortunately, the next step was more of a problem.

I created a c++ file called incl in a project called inclMex.

_________________________________________________________________________

#include "C:\Documents and
Settings\bkirklin\SVN\trunk\octave\SRC\addLib.cpp"
#include <stdio.h>

int main() {
        
        printf("Hello");
        
        double *a, *b, *res;
        addLib *ab = new addLib();

        a[0] = 1;
        b[0] = 1;
        printf("%d",ab->add(a,b));
        return 0;
}

_________________________________________________________________________

After adding several paths to the linker into Octave's inerds, I was able to
get this to compile without a fault detected. Then I began receiving errors
when running the program. At first it complained about not being able to
find the Octave dlls. So I copied them all into the same location as my
.exe. Then it complained about windows dlls. So I copied all of those.
Here's the resulting collection of files located in my debug directory:

_________________________________________________________________________

[.]                           libjasper-1.dll
[..]                          libjpeg-62.dll
ATL80.dll                     liblapack.dll
cruft.dll                     libMagick++-10.dll
gluegen-rt.dll                libMagick-10.dll
inclMex.exe                   libncurses-5.dll
inclMex.exp                   libnetcdf-4.dll
inclMex.ilk                   libpango-1.0-0.dll
inclMex.lib                   libpangocairo-1.0-0.dll
inclMex.pdb                   libpangowin32-1.0-0.dll
jogl.dll                      libpcre-0.dll
jogl_awt.dll                  libpng13.dll
jogl_cg.dll                   libportaudio-2.dll
libarpack.dll                 libreadline-5.dll
libblas.dll                   libtiff.dll
libbz2.dll                    libwmflite-0-2-7.dll
libcairo-2.dll                libxml2-2.dll
libcurl.dll                   mfc80.dll
libfftw3-3.dll                mfc80u.dll
libfreetype-6.dll             mfcm80.dll
libgd-2.dll                   mfcm80u.dll
libglib-2.0-0.dll             Microsoft.VC80.ATL.manifest
libglpk-0.dll                 Microsoft.VC80.CRT.manifest
libgmodule-2.0-0.dll          Microsoft.VC80.MFC.manifest
libgobject-2.0-0.dll          msvcm80.dll
libgsl-0.dll                  msvcp80.dll
libgslcblas-0.dll             msvcr80.dll
libgthread-2.0-0.dll          octave.dll
libhdf5-0.dll                 octinterp.dll
libiconv-2.dll                zlib1.dll
libintl-8.dll

_________________________________________________________________________

Well, that effectively took care of all of the errors reflecting anything
specific. The next
error said this: (appears 2xs)

"The application failed to initialize properly (0x80000003). Click Ok to
terminate the aplication."

Further research led me to believe that this was the result of either more
missing dlls or a bad manifest file somewhere. I'm not sure, however, which
manifest file is missing where or similarly which dll. I'm using Microsoft
Visual Studios 2005 and the version of Octave compiled with Microsoft Visual
Studios 2005.

This page here seemed it might be of use, but did not result in any
improvement:
http://forums.msdn.microsoft.com/en-US/vcgeneral/thread/eb134e02-5d32-44ae-aa26-c106c082c72a/

This page seemed relevant as well, and seems to confirm my diagnoses of the
problem, but does not appear to have a solution to help me:
http://www.nabble.com/Re:-mkoctave-MSVC-2008-Express-td15912053.html

I'm going on 6 hours of trying to figure this out, so help would be greatly
appreciated. Thanks.

I'm slightly concerned that this may be the wrong mailing list, but I'm not
sure another forum would have the information necessary to understand the
problem in relation to Octave.

As a side note, I tried to use OctaveEmbedded, for similar reasons,
(http://wiki.octave.org/wiki.pl?OctaveEmbedded) from Octave forge, which
indeed has another mailing list. I added its files to my project and
recieved the same error code after removing the bit about addLib. So this
problem appears to be of wider scope and just what I was trying to do.
-- 
View this message in context: 
http://www.nabble.com/Linking-to-.mex-file%27s-library-from-c%2B%2B-tp18878959p18878959.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]