help-octave
[Top][All Lists]
Advanced

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

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


From: hkhauke
Subject: Octave stand-alone and Octave 3.6.2 compiled for Visual Studio 2010
Date: Wed, 19 Dec 2012 00:39:03 -0800 (PST)

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?

Thank you for any help and best regards

Hauke



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Octave-stand-alone-and-Octave-3-6-2-compiled-for-Visual-Studio-2010-tp4648069.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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