help-octave
[Top][All Lists]
Advanced

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

Re: Octave stand-alone and Octave 3.6.2 compiled for Visual Studio 2010


From: Michael Goffioul
Subject: Re: Octave stand-alone and Octave 3.6.2 compiled for Visual Studio 2010
Date: Thu, 20 Dec 2012 10:37:13 -0500

On Wed, Dec 19, 2012 at 3:39 AM, hkhauke <address@hidden> wrote:
Hi everyone,

I tried to test this with Octave 3.6.2, Visual Studio 2010 Build:

http://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html#Standalone-Programs

hence, to control Octave from within a C/C++ programm by using the Octave
C++ API.
I use Visual Studio 2010 and have managed to set all references to find the
headers and also
the Octave libraries. First, I had to modify the Octave math.h file since it
uses an ABSOLUTE path to the Microsoft math.h which is no longer in
C:\Program Files but in C:\Program Files (x86) on a 64 bit machine.

When compiling, I get a lot of warnings such as

c:\program files
(x86)\octave-3.6.2\include\octave-3.6.2\octave\idx-vector.h(109): warning
C4251: 'idx_vector::idx_base_rep::count' : class 'octave_refcount<T>' needs
to have dll-interface to be used by clients of class
'idx_vector::idx_base_rep'
1>          with
1>          [
1>              T=int
1>          ]
1>c:\program files
(x86)\octave-3.6.2\include\octave-3.6.2\octave\sparse.h(72): warning C4251:
'Sparse<T>::SparseRep::count' : class 'octave_refcount<T>' needs to have
dll-interface to be used by clients of class 'Sparse<T>::SparseRep'
1>          with
1>          [
1>              T=int
1>          ]
1>          c:\program files
(x86)\octave-3.6.2\include\octave-3.6.2\octave\sparse.h(63) : see reference
to class template instantiation 'Sparse<T>::SparseRep' being compiled
1>          c:\program files
(x86)\octave-3.6.2\include\octave-3.6.2\octave\sparse.h(593) : see reference
to class template instantiation 'Sparse<T>' being compiled

Yes, it finally compiles and links but as soon as I start it, it gives me a
segmentation fault:
The code of the application is very simple and it crashes in the second
line,




     #include <iostream>
     #include <octave/oct.h>
     #include <octave/octave.h>
     #include <octave/parse.h>

     int
     main (void)
     {
       string_vector argv (2);

CRASH ---->             argv(0) = "embedded";    <---- CRASH

       argv(1) = "-q";

       octave_main (2, argv.c_str_vec(), 1);

       octave_idx_type n = 2;
       Matrix a_matrix = Matrix (1, 2);

       std::cout << "GCD of [";
       for (octave_idx_type i = 0; i < n; i++)
         {
           a_matrix (i) = 5 * (i + 1);
           if (i != 0)
             std::cout << ", " << 5 * (i + 2);
           else
             std::cout << 5 * (i + 2);
         }
       std::cout << "] is ";

       octave_value_list in = octave_value (a_matrix);
       octave_value_list out = feval ("gcd", in, 1);

       if (!error_state && out.length () > 0)
         {
           a_matrix = out(0).matrix_value ();
           if (a_matrix.numel () == 1)
             std::cout << a_matrix(0) << "\n";
           else
             std::cout << "invalid\n";
         }
       else
         std::cout << "invalid\n";

       return 0;
     }

It seems that the string_vector which is defined in Octave is not compatible
with the
rest of the program.

My personal assumption is that it does not work to reach STL data from DLL
to the rest of the code.
According to my experience, the same happens for other functions using STL
types such as std::string. That is why I tend to use C-APIs and datatypes
always when interfacing DLLs..
Or maybe there is a conflict between the library and my main routines.

In order to compile everything, I have not set any PREPROCESSOR directives
such as OCTAVE_DLL. If I would do so, the code would not link. I set code
generation to MD.

Has anybody ever got this application running with Visual Studio?

Yes, I just did. However, I'm using the octave-provided tools to do it. From octave prompt:

mkoctfile --link-stand-alone test-embed.cc -o test-embed.exe
system('test-embed.exe')

The program doesn't crash, but doesn't produce correct results either, because it ends up calling "gcd([10, 15])", which is invalid. It should be "gcd(10, 15)" instead, but that's another story.

The mkoctfile utility is a wrapper around cc-msvc, which itself is a wrapper around cl (the visual studio compiler). Your problem is most probably due to incorrect compilation flags. Here's the expansion of the compilation commands that are executed:

cl -nologo -c -D_WIN32 -DWIN32 -D__WIN32__ -IC:\Software\Octave-3.6.2\include\octave-3.6.2\octave\.. -IC:\Software\Octave-3.6.2\include\octave-3.6.2\octave -IC:\Software\Octave-3.6.2\include -Ic:/Software/VC10Libs/include -Ic:/Software/VC10Libs/include/freetype2 -Ic:/Software/VC10Libs/include -Ic:/Software/VC10Libs/include -O2 -MD -EHsc -wd4244 -fp:strict -fp:except- -Tptest-embed.cc -Fotest-embed.o

link -nologo -EHsc -wd4244 -fp:strict -fp:except- -LIBPATH:c:/Software/VC10Libs/lib -out:test-embed.exe test-embed.o -LIBPATH:C:\Software\Octave-3.6.2\lib\octave\3.6.2 -LIBPATH:C:\Software\Octave-3.6.2\lib octinterp.lib octave.lib cruft.lib dirent.lib msvcmath.lib

If you're using the Visual Studio interface to make the compilation, be sure that your settings are such that the compilation command matches these above. In particular, pay special attention to the -MD flag, if you're in debug mode Visual Studio will use -MDd, which is not compatible.

Michael.


reply via email to

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