Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Calling function from dll within C-MEX

Asked by Daniel on 18 Nov 2012

Hi All,

I got this error when I'm trying to compile the mult.cpp function, which calls the showmsg():

>> mex mult.cpp dll2.lib

mult.obj : error LNK2019: unresolved external symbol showmsg referenced in function mdlOutputs mult.mexw64 : fatal error LNK1120: 1 unresolved externals

I compiled the dll in VS2010 (C++). The header:

      #ifdef __cplusplus
        extern "C" {
      #endif
    namespace dllnamesp
    {
    	class dllclass
    	{
    	public:
    		static __declspec(dllexport) void showmsg();
    	};
    }
    #ifdef __cplusplus
    }
    #endif
------------------------------------------------
*The C++ file:*
#include <iostream>
using namespace std;
#include "printer.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace dllnamesp
{
	void dllclass::showmsg()
	{
		cout << "alma\n";
	}
}
#ifdef __cplusplus
}
#endif

In the mult.cpp:

  • -I included the header: #include "printer.h"
  • -I declared the function: void __cdecl showmsg();
  • -I called the function in: static void mdlOutputs(SimStruct *S, int_T tid) { showmsg(); }

The header,lib and dll are in the same folder with the C-MEX function. What Am I doing wrong?

Regards,

Daniel

0 Comments

Daniel

Tags

Products

1 Answer

Answer by Kaustubha Govind on 19 Nov 2012
Accepted answer

If you're using 64-bit MATLAB, you might need to make sure that the DLL is also 64-bit - I believe the default configuration for Visual Studio is a 32-bit target.

0 Comments

Kaustubha Govind

Contact us