Using Coder's generated C files in Visual Studio ?

1 次查看(过去 30 天)
[EDIT: 20110608 10:34 CDT - reformat - WDR]
Hello Folks,
I have successfully changed my .m files to .c files using Matlab Coder. May you guide me on how to use these files in Visual Studio ?
my function name is faceImage.c
In my Visual Studio .cpp file, I included:
#include "faceImage.h"
#include "faceImage_initialize.h"
#include "faceImage_terminate.h"
But when i compile the file i get:
error LNK2019: unresolved external symbol "void __cdecl faceImage_initialize(void)" (?faceImage_initialize@@YAXXZ) referenced in function _wmain
Can you please give me an example or any reference that may aid me to solve such problem.
Loads of thanks

采纳的回答

John Elliott
John Elliott 2011-6-8
Assuming you're just generating the C++ code (and not creating a library), don't forget to add faceImage_initialize.cpp and faceImage_terminate.cpp to you VS project. Adding something to the linker's path won't do the job.
If you're creating a library using MATLAB Coder, then you need to add the library to the linker's input files in your VS project.

更多回答(1 个)

Kaustubha Govind
Kaustubha Govind 2011-6-8
Have you included faceImage.c in your Visual Studio project?
Note that if you are calling C functions from C++ files, you need to include the extern "C" directive: How do I call a C function from C++?
You might need to add this to the generated header files for all functions that you intend to call from a .cpp file.
  2 个评论
Chirag Gupta
Chirag Gupta 2011-6-8
As Kaustubha pointed it out, just add "C" in all the header files:
Instead of extern void face_initiallize(...), just make it
extern "C" void face_initialize(...)
Louis
Louis 2011-6-8
Thank you very much for your answers. Instead of going through the hassle of adding the C extern, i regenerated C++ files using Coder. So now i have faceImage.cpp.
So now i should be able to call it easily. I added the path(\codegen\lib\faceImage) to the Visual Studio's project. Specifically: C/C++->general-> Additional Include Directories, and to Linkers->general->Additional Library Directories.
Sadly, i still get the same LNK2019 error. Do you think i am having a problem in adding the headers or the library ?
Really appreciate your feedback. Thank you.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by