2
votes

i was trying to learn matlab to C workflow and i used a matlab coder to generate C/C++ code from this .m file

  function c = simpleProduct(a,b) %#codegen
  c=a*b;

and after the code has been generated my visual win32 c++ project looks like this.

#include <iostream>
#include "simpleProduct.h"  //matlab generated header file.
using namespace std;
void main(){
    cout<<simpleProduct(34,55);   //matlab generated funcion
}

i even configured "addition library" and "additional dependency" from project properties to my generated static library but the same problem occurs again and again.

and from this code i generated a static library. and the operation is success on matlab. but when i included the generated header file and linked the static library inside visual studio and compiled it it gives me this error.

Error   1   error LNK2019: unresolved external symbol "float __cdecl simpleProduct(float,float)" (?simpleProduct@@YAMMM@Z) referenced in function _main C:\Users\serakpc\Documents\Visual Studio 2010\Projects\chiraq\chiraq\source.obj chiraq

development environments---- Matlab 2012b, Visual Studio 2012, Visual Studio 2010,

1
Where's the function definition? This sounds like you either aren't linking properly or are missing the function definition code.Justin
here is simpleproduct.c look like real32_T simpleProduct(real32_T a, real32_T b) { return a * b; } Serak Shiferaw

1 Answers

0
votes

The reason is that your visual studio project cannot found simpleProduct.dll.

Solution: When you distribute MATLAB into visual studio, it will generate (at least) four files namely

  1. simpleProduct.h

  2. simpleProduct.lib

  3. simpleProduct.dll

  4. simpleProduct.ctf

You need to copy these 4 files to your visual studio solution directory and add simpleProduct.lib to [Properties > Linker > Input].