3

I have written a very very simple program in Visual C++ 2008 SP1. It just adds up two numbers. The DLLTest.cpp is:

#include "DllTest.h"
 __declspec(dllexport) double Add(double a, double b)
 {
 return( a + b );
}

And DllTest.h is:

#ifndef _DLL_TEST_H_
#define _DLL_TEST_H_
#endif
__declspec(dllexport) double Add( double, double);

I build the DLL using Visual C++ 2008. When I try to load the library using loadlibrary, I get the following error:

??? Error using ==> loadlibrary at 422 Building DllTest_thunk_pcwin64 failed. Compiler output is: DllTest_thunk_pcwin64.c C:\Users\Admin\Desktop\DllTest.h(5) : error C2054: expected '(' to follow 'EXPORTED_FUNCTION' C:\Users\Admin\Desktop\DllTest.h(5) : error C2085: 'Add' : not in formal parameter list DllTest_thunk_pcwin64.c(40) : error C2085: 'int8' : not in formal parameter list DllTest_thunk_pcwin64.c(41) : error C2085: 'uint8' : not in formal parameter list DllTest_thunk_pcwin64.c(42) : error C2085: 'int16' : not in formal parameter list DllTest_thunk_pcwin64.c(43) : error C2085: 'uint16' : not in formal parameter list DllTest_thunk_pcwin64.c(44) : error C2085: 'int32' : not in formal parameter list DllTest_thunk_pcwin64.c(45) : error C2085: 'uint32' : not in formal parameter list DllTest_thunk_pcwin64.c(46) : error C2085: 'int64' : not in formal parameter list DllTest_thunk_pcwin64.c(47) : error C2085: 'uint64' : not in formal parameter list DllTest_thunk_pcwin64.c(48) : error C2085: 'voidPtr' : not in formal parameter list DllTest_thunk_pcwin64.c(49) : error C2085: 'string' : not in formal parameter list DllTest_thunk_pcwin64.c(51) : error C2082: redefinition of formal parameter 'EXPORTED_FUNCTION' DllTest_thunk_pcwin64.c(51) : error C2143: syntax error : missing ';' before 'type' DllTest_thunk_pcwin64.c(52) : error C2085: 'EXPORTED_FUNCTIONdoubledoubledoubleThunk' : not in formal parameter list DllTest_thunk_pcwin64.c(52) : error C2143: syntax error : missing ';' before '{'

I want just to load a simple program, written in Visual C++, in MATLAB. How can I fix this problem?

HebeleHododo
3,6361 gold badge32 silver badges39 bronze badges
asked Jan 22, 2013 at 6:53
1
  • What OS (32/64bit) and version of Matlab are you using? Commented Jan 22, 2013 at 9:27

1 Answer 1

1

Thanks for considering my question. I found the problem. Actually, there were two problems: 1) The MATLAB is 64 bit but I made 32-bit DLL and I had to change the settings in Visual Studio to make 64-bit DLL. 2) It seems the compiler that MATLAB uses for loading the DLL, has problem with 'extern "C"' command. So, I changed the header like this:

#ifndef DllTest_h
#define DllTest_h
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) double Add( double, double);
#ifdef __cplusplus
}
#endif
#endif

And Finally it worked.

answered Jan 22, 2013 at 16:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.