Using Octave Libraries (DLLs and so on) in C++ without installing Octave (just copying the installation folder) -
in c++ solution have dll. dll uses octave c++ classes , uses octave "embedded" engine. using following steps (1st method) can build c++ solution , run built executable , output results in text files without problem:
the steps of using octave libraries in visual studio c++ 2008: 1- download octave 3.6.1 visual studio 2008 following link. notice there 2 options download, 1 vs2010 , 1 vs2008, should download vs2008 option. http://sourceforge.net/projects/octave/files/octave%20windows%20binaries/octave%203.6.1%20for%20windows%20microsoft%20visual%20studio/ 2- install octave 3.6.1 on system in following directory (which contains no white spaces): c:\software\octave-3.6.1 3- while installing, on installation wizard, select available packages of octave 3.6.1 installed, select "gnuplot.exe" graphics engine. 4- after installing octave 3.6.1, include octave 3.6.1 header files in c++ code below: #include <octave/oct.h> #include <octave/octave.h> #include <octave/config.h> 5- configure vs2008: add following directories "property pages > configuration properties > c/c++ > general >additional include directories:" c:\software\octave-3.6.1\include c:\software\octave-3.6.1\include\octave-3.6.1 6- configure vs2008: add following directories "property pages > configuration properties > linker > general > additional library directories:" c:\software\octave-3.6.1\lib c:\software\octave-3.6.1\lib\octave\3.6.1 7- configure vs2008: change "property pages > configuration properties > linker > general > enable incremental linking" "no." 8- configure vs2008: add following files "property pages > configuration properties > linker > input > additional dependencies:" octave.lib octinterp.lib cruft.lib 9- configure vs2008: enter following path "property pages > configuration properties > debugging > environment:" path=%path%;c:\software\octave-3.6.1\bin; 10- use following command before loading dll: setdlldirectory((lpcwstr)l"c:\\software\\octave-3.6.1\\bin\\");
but when try use following steps (2nd method), have problem (i'll explain problem):
the steps of using octave libraries in visual studio c++ 2008: 1- download octave 3.6.1 visual studio 2008 following link. notice there 2 options download, 1 vs2010 , 1 vs2008, should download vs2008 option. http://sourceforge.net/projects/octave/files/octave%20windows%20binaries/octave%203.6.1%20for%20windows%20microsoft%20visual%20studio/ 2- install octave 3.6.1 on system in following directory (which contains no white spaces): c:\software\octave-3.6.1 3- while installing, on installation wizard, select available packages of octave 3.6.1 installed, select "gnuplot.exe" graphics engine. 4- after installing octave 3.6.1, copy folder "octave-3.6.1" @ address "c:\software\octave-3.6.1" next solution file of visual studio 2008 project (*.sln) , include octave 3.6.1 header files in c++ code below: #include <octave/oct.h> #include <octave/octave.h> #include <octave/config.h> 5- configure vs2008: add following directories "property pages > configuration properties > c/c++ > general >additional include directories:" ..\octave-3.6.1\include ..\octave-3.6.1\include\octave-3.6.1 6- configure vs2008: add following directories "property pages > configuration properties > linker > general > additional library directories:" ..\octave-3.6.1\lib ..\octave-3.6.1\lib\octave\3.6.1 7- configure vs2008: change "property pages > configuration properties > linker > general > enable incremental linking" "no." 8- configure vs2008: add following files "property pages > configuration properties > linker > input > additional dependencies:" octave.lib octinterp.lib cruft.lib 9- configure vs2008: enter following path "property pages > configuration properties > debugging > environment:" path=%path%;..\octave-3.6.1\bin; 10- use following command before loading dll: setdlldirectory((lpcwstr)l"..\\octave-3.6.1\\bin\\");
the problem when use 2nd method, works perfect far keep installation folder of c:\software\octave-3.6.1
untouched. mean when rename installation folder or when remove it, or when uninstall octave, solution compiles , builds executable, when running executable, not generate results (the results bunch of text files , output files empty). wondering if knows reason , solution. thanks.
@andy andy requested, showed below section of c++ code uses octave embedded engine. variables m_
prefix members of fdd
class getcpsd
method implemented below.
void fdd::getcpsd(){ int argc=int(2); string_vector argv=string_vector(argc); argv(0)="embedded"; argv(1)="-q"; octave_main(argc,argv.c_str_vec(),1);//start octave interpreter embedded engine, because cpsd command "m file" not c++ class octave_value_list ovl_in_pkg; ovl_in_pkg(0)="load"; ovl_in_pkg(1)="signal"; feval("pkg",ovl_in_pkg,0);//load signal package of octave (cpsd command inside signal package) octave_value_list ovl_in_hanning; octave_value_list ovl_out_hanning; ovl_in_hanning(0)=m_int_samplingfreq * nfft_fs_ratio;//nfft ovl_out_hanning=feval("hanning",ovl_in_hanning,1); octave_value_list ovl_in_cpsd; octave_value_list ovl_out_cpsd; ovl_in_cpsd(2)=ovl_out_hanning(0);//window (get hanning) ovl_in_cpsd(3)=cpsd_overlap;//overlap ovl_in_cpsd(4)=m_int_samplingfreq * nfft_fs_ratio;//nfft ovl_in_cpsd(5)=m_int_samplingfreq;//fs for(int i=int(0);i<m_int_numchann;i++){ ovl_in_cpsd(0)=m_matrixofchannels.column(i); for(int j=int(0);j<m_int_numchann;j++){ ovl_in_cpsd(1)=m_matrixofchannels.column(j); ovl_out_cpsd=feval("cpsd",ovl_in_cpsd,2); m_ovl_amplitudesandphasefromcpsd(i*m_int_numchann+j) =ovl_out_cpsd(0).complex_column_vector_value(); m_ovl_freqfromcpsd(i*m_int_numchann+j) =ovl_out_cpsd(1).column_vector_value(); } } m_columnvector_f = m_ovl_freqfromcpsd(0).column_vector_value(); m_int_numoffreqindexpoints = m_ovl_freqfromcpsd(0).column_vector_value().length(); //clean_up_and_exit(0);//for closing embedded octave engine, instead, closes whole program! therefore, skipped line! }
Comments
Post a Comment