|
Hello,
I have a similar problem. i want to call matlab from C++,
to creat a .dll but the matlab engine closes as soon as it
open before executing any command.
Do you have any idea to resolve this problem?
Thanks
thin_bruce@my-deja.com wrote in message
<7jiqlr$h9b$1@nnrp1.deja.com>...
> Hi
> I have been trying (unsuccessfully and for some time
now) to build a
> .dll containing functions which call the Matlab Engine
Interface. The
> reason I want to do this is to link the .dll to a Java
GUI using the
> Java Native interface.To test this I only use a few
lines of code:
>
> #include <stdio.h>
> #include "engine.h"
> #include "JMatTest.h"
> #define BUFSIZE 256
>
> JNIEXPORT
> void JNICALL
> Java_JMatTest_evalString(JNIEnv *env,jobject obj,jstring
message)
> {
> Engine *ep;
> const char *command;
> char buffer[BUFSIZE];
>
> if (!(ep = engOpen(" ")))
> {
> printf("Can't start MATLAB engine");
> }
>
> command =(*env)->GetStringUTFChars(env,message,0);
>
> engOutputBuffer(ep,buffer,BUFSIZE);
>
> engEvalString(ep,command);
>
> printf("%s", buffer+2);
>
> engEvalString(ep, "close;");
>
> engClose(ep);
>
> }
>
> All this does is takes a String command in Java, and
passes it to the
> Matlab engine which then evaluates it.(the Java/JNI
stuff is sound it
> works with other function calls)
> I then compile it in Matlab with the following (using
MSVC5.0):
>
> mex -v -f msvc50engmatopts.bat -ID:\MATLABR11
\extern\include -ID:
> \MATLABR11\bin -IC:\jdk1.2\lib -IC:\jdk1.2\include -
IC:\jdk1.2
> \include\win32 D:\JMatTest.c libeng.dll C:\jdk1.2
\lib\jvm.lib D:
> \MATLABR11\sys\lcc\lib\ntdll.lib D:\MATLABR11
\sys\lcc\mex\libmex.lib
>
> but the Matlab engine function calls cause the following
(in Matlab):
>
> JMatTest.obj : error LNK2001: unresolved external symbol
mexFunction
> _lib7798.lib : fatal error LNK1120: 1 unresolved
externals
> LINK : fatal error LNK1141: failure during build of
exports file
>
> and the following under the MSVC5.0 IDE:
>
> --------------------Configuration: Matlib - Win32
> Debug--------------------
> Linking...
> JMatTest.obj: error LNK2001: unresolved external symbol
_engClose
> JMatTest.obj: error LNK2001: unresolved external symbol
_engEvalString
> JMatTest.obj: error LNK2001: unresolved external symbol
_engOutputBuffer
> JMatTest.obj : error LNK2001: unresolved external symbol
_engOpen
> Debug/JMatTest.dll : fatal error LNK1120: 4 unresolved
externals
> Error executing link.exe.
>
> JMatTest.dll - 5 error(s), 0 warning(s)
>
> and with GCC at the command line:
>
> JMatTest.o: In function `Java_JMatTest_evalString':
> /tmp/JMatTest.c:18: undefined reference to `engOpen'
> /tmp/JMatTest.c:27: undefined reference to
`engOutputBuffer
> /tmp/JMatTest.c:29: undefined reference to
`engEvalString'
> /tmp/JMatTest.c:33: undefined reference to
`engEvalString'
> /tmp/JMatTest.c:35: undefined reference to `engClose'
> collect2: ld returned 1 exit status
> dllwrap: gcc exited with status 1
>
> (NB all paths were correct in both of the above).
>
> if I add a main method which calls this function (this
is a dll mind)
> it works fine but I dont want an .exe.If I add an empty
mexFunction
> method it also compiles fine but the JNI function cant
be called from
> the resulting .dll.
> I am at a loss as to what is wrong here, is building an
Engine
> Interface .dll impossible? has anyone done this before?
> I am using WinNT4.0 (with SP4) and Matlab 5.2 and 5.3R11
with Borland
> BCC5.2,5.3 and 5.4, the Mathworks LCC compiler as well
as GCC 2.8.1 and
> MS Visual C++ 5.0 and 4.2 (in all possible combinations
both within
> IDEs where applicable and within Matlab using 'mex')
> Any help (v.gratefully) appreciated
>
> thanks
>
> Bruce
>
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
|