Use Octave in msvc 2010

686 Views Asked by At

I am using Octave within MSVC 2010. First I downloaded Octave latest version at this link. After installing, I tried to run this simple code:

#include <iostream>
#include<octave-3.6.4\octave\oct.h>
#include<octave-3.6.4\octave\config.h>
#include<octave-3.6.4\octave\octave.h>

using namespace std;


int main (void)
{
  std::cout << "Hello Octave world!\n";   

  system("PAUSE");
  return 0;
  }

Note that I added these links to my project as well:

  1. C:\Software\Octave-3.6.4\include\octave-3.6.4\octave--->Includ. Dir.,
  2. C:\Software\Octave-3.6.4\include--->Includ. Dir.
  3. C:\Software\Octave-3.6.4\lib--->Lib. Dir.
  4. C:\Software\Octave-3.6.4\lib\octave\3.6.4--->Lib Dir.
  5. I also added 1 and 2 to Additional Inc Dir!!
  6. C:\Software\Octave-3.6.4\lib\octave\3.6.4--->Additional Lib. Dir in Linker.

First, I got this error that it cannot find math.h in Program Files while this file was in my Program Files (x86). So, I changed it to: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h and it solved this error. However, now I get this error:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall octave_value::~octave_value(void)" (__imp_??1octave_value@@QAE@XZ) referenced in function "public: void * __thiscall octave_value::`vector deleting destructor'(unsigned int)" (??_Eoctave_value@@QAEPAXI@Z)
1

There are 1 best solutions below

7
On

It is not sufficient to add the library path to the project.

You have to add the library name(s) (including .lib) to the "Additional Dependencies" in the Linker/Input tab.

Edit

To verify what library has been searched you can enable the Linker/General/Show Progress option. Then you can see in the Build Output what library has actually be used in symbol search.

Edit

Your example code doesn't show any instance of an array of octave_value instances. So it's a bit surprising that you need to link with any library with the code you've shown. But anyway you want to have these externals resolved.

If there is no other resource (manual, ...) you should detect where the octave_value class is implemented. This can be a static library or a DLL.

You can detect the DLL implementation with a dumpbin /exports on the DLLs. In that case you need the corresponding import libraries. The LIB should have the same base name as the DLL. Verify that you have added that dependency and how the linker searches this library for symbols.

The name of the symbols __imp_??1octave_value@@QAE@XZ indicates that it should be in a DLL. But since you have a problem you might want to search LIBs too. You can detect the LIB implementation with a dumpbin /symbols. In that case you have to add the LIB directly. Again verify it with the Build Output.

The dumpbin output will probably very verbose. You should use either findstr to limit the output or redirect the output to a file and search the symbols with an editor of your choice.

Search for ocatave_value. If you find a different decoration of the constructor and destructor you might have missed to set an option. A preprocessore directory could be used to define how the library is use. E.g. if you find octave_value::octave_value without the __imp_ prefix you have accidentily compiled for a DLL version altough the class is implemented in a static library. In that case, read the manual and ask at the octave mailing list forum or whatever.