-
December 6th, 2012, 04:48 PM
#1
Problem using matlab function in visual studio c++?
I am trying to use the linprog function in visual studio 2010. I have used the matlab compiler according to the walkthrough at
http://blogs.mathworks.com/loren/201...ries-and-dlls/.
When I start writing the C++ document however, I cannot get things to work. The mclInitializeApplication function is undefined, and I do not know what I have to add to define it.
Any help here would be much appreciated!
-
December 6th, 2012, 05:14 PM
#2
Re: Problem using matlab function in visual studio c++?
![Quote](images/misc/quote_icon.png) Originally Posted by gugge444
When I start writing the C++ document however
You are not writing a "document" -- you're writing a C++ program. A program requires you to know the programming language you're using. Using C++ isn't like using HTML, where all you need is a cheat sheet and a half-hour of free time. You have to learn the rules, syntax, nuances, etc. of the language.
I cannot get things to work. The mclInitializeApplication function is undefined, and I do not know what I have to add to define it.
The basic rule of C++ is that all functions that are called must be prototyped before the actual call, or the entire body of the function must appear before the call. That's how you get that function to be recognized by the compiler.
Regards,
Paul McKenzie
-
December 6th, 2012, 05:21 PM
#3
Re: Problem using matlab function in visual studio c++?
Thank you for your reply Paul.
Although I am new to C++ I understand the concept of prototyping. I apologize for the confusing formulation of my question. I believe this function I am trying to use is supposed to be called from an outside library of some kind, if you have a look at the page I referenced I am sure that will become clearer.
If anyone can aid me further than to simply dismiss me as a lazy/incompetent, that would be much appreciated.
-
December 6th, 2012, 05:49 PM
#4
Re: Problem using matlab function in visual studio c++?
![Quote](images/misc/quote_icon.png) Originally Posted by gugge444
Thank you for your reply Paul.
Although I am new to C++ I understand the concept of prototyping. I apologize for the confusing formulation of my question. I believe this function I am trying to use is supposed to be called from an outside library of some kind, if you have a look at the page I referenced I am sure that will become clearer.
It is the compilation that is failing. Where that function exists isn't important when compiling a module. The time where that function exists becomes important is when it's time to link, which is a separate step than compilation.
Code:
#include "libvigenere.h"
#include <iostream>
#include <cstring>
int main(int ac, const char *av[])
{
bool enc = strcmp(av[1], "-e") == 0;
if (!mclInitializeApplication(NULL,0))
{
std::cerr << "Could not initialize the application properly."
<< std::endl;
return -1;
}
}
It doesn't matter at this point where that function actually exists. The only thing required by the compiler is that the function is prototyped, meaning it knows the parameter types and return type. That's all -- the compiler doesn't care if that function really exists or not, whether it really is contained in another library, whether you're using MatLab or not, etc.. So take Matlab out of the loop -- your problem is compilation.
The header file "libvigenere.h" -- what does it contain? Does it contain the prototype to the function? If not, then where is that function prototyped.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; December 6th, 2012 at 05:55 PM.
-
December 6th, 2012, 06:31 PM
#5
Re: Problem using matlab function in visual studio c++?
Thank you Paul!
I needed to rethink what I was doing and am now on the right track! It is annoying however that now I have stumbled upon:
1>C:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\extern\include\mclcppclass.h(1905): fatal error C1001: An internal error has occurred in the compiler.
This is an incredibly confusing error message as I am sure the compiler is not at fault, but at the same time it is difficult for me to try and solve this...
-
December 7th, 2012, 06:21 AM
#6
Re: Problem using matlab function in visual studio c++?
![Quote](images/misc/quote_icon.png) Originally Posted by gugge444
Thank you Paul!
I needed to rethink what I was doing and am now on the right track! It is annoying however that now I have stumbled upon:
1>C:\Program Files\MATLAB\MATLAB Compiler Runtime\v80\extern\include\mclcppclass.h(1905): fatal error C1001: An internal error has occurred in the compiler.
Compiler error messages need to be accompanied by the code that doesn't compile. No one can tell you what is wrong without seeing the code.
So please post the code, including all third-party header files and what they contain.
Regards,
Paul McKenzie
-
December 7th, 2012, 08:08 AM
#7
Re: Problem using matlab function in visual studio c++?
![Quote](images/misc/quote_icon.png) Originally Posted by Paul McKenzie
The basic rule of C++ is that all functions that are called must be prototyped before the actual call, or the entire body of the function must appear before the call. That's how you get that function to be recognized by the compiler.
And that is only half the story.
prototyping the function is what makes the C++ code compile.
You also need to provide the linker with the necessary libraries, objects, or references to actually produce an executable.
And when you have the above 2 sorted.
There's still the matter of making things actually run properly, which may need you to have .dll files or other resources (COM objects, ports, mailslots, pipes) operational/accessible.
programming is easy... honest.
-
December 7th, 2012, 01:09 PM
#8
Re: Problem using matlab function in visual studio c++?
Cheers Paul ![Smilie](images/smilies/smile.gif)
You are right about the fact that I do not know enough about c++ yet, as I keep getting into trouble... I have now moved onto trying to add the gnu glpk library to my code, but I keep getting unresolved external symbol errors, suggesting that I need to add some kind of library or something...
In visual studio 2010, what I have done to try and incorporate the library is to add the additional include directory so that I can include #include <glpk.h>, but I have a feeling I need to use a linker aswell... From what I understand, I need to go to linker --> input --> additional dependencies, but when in there, all I seem to be able to do is write the name of library files... and just writing glpk_4_47.lib here does not solve the problem either.
Once again, thank you for all your help so far!
-
December 7th, 2012, 01:23 PM
#9
Re: Problem using matlab function in visual studio c++?
Ah once again I moved on, I simply took all the files in the folder, such as dlls and libs and put them under resources, now the error that appears is that the file "glpk_4_47.dll is missing" so I wander how to change the directory under which this file is looked for
-
December 7th, 2012, 01:49 PM
#10
Re: Problem using matlab function in visual studio c++?
![Quote](images/misc/quote_icon.png) Originally Posted by gugge444
Ah once again I moved on, I simply took all the files in the folder, such as dlls and libs and put them under resources, now the error that appears is that the file "glpk_4_47.dll is missing" so I wander how to change the directory under which this file is looked for
Are you running your app now? If you are, then the Windows OS is responsible for finding DLL's, unless somewhere your application has given a full path to the DLL (for example, if the code calls LoadLibrary( ) and gives a full path name, then the system will only use that name to load the DLL).
If however it is just a DLL name that Windows has to load (no full path name), then Windows does a somewhat extensive but standard search for the DLL file.
See here and look at the Remarks section:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
So the simplest solution is to place the DLL either in a directory that is specified by your PATH environment variable, or place the DLL in the same directory as your executable file.
Regards,
Paul McKenzie
-
December 7th, 2012, 06:44 PM
#11
Re: Problem using matlab function in visual studio c++?
I got the code to work! Thank you for all your help! ![Smilie](images/smilies/smile.gif)
By the way, I created a 1d array using the trick double* x = new double[var]; which seems to be the only way of creating an array with a variable size. However, I now need to use the parts of x --> (x[1], x[2], ..., x[i]) in a function that requires a double input, and I cannot do that with a double*.
Is there a way of solving this without entering the source code and trying to change the input method, or rather, is there a way of turning a double* to a double, or better yet, create a double with a variable input?
Thanks in advance.
-
December 7th, 2012, 08:06 PM
#12
Re: Problem using matlab function in visual studio c++?
Sorry, that is suppose to be char* and char, not double* and double
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|