Hi,
I'm trying to make c code to read a .mat file. Here it is:
#include <stdio.h>
#include "c:\MATLAB\R2015b-x64\extern\include\mat.h"
int main(){
MATFile * pMF;
printf("Abrindo arquivo .mat...\n"); /*check (1)*/
pMF = matOpen("teste.mat","r");
printf("Arquivo .mat aberto.\n"); /*check (2)*/
getch();
end
When I compile this in Visual Studio 2010, I get the following message:
matread.obj : error LNK2019: unresolved external symbol _matOpen referenced in function _main
matread.exe : fatal error LNK1120: 1 unresolved externals
I'm using VS 2010, which is not supported by R2015b (the indicated version is VS 2010 SP1). Could it be caused by a compatibility issue with this compiler, or it's just coding error?
Thanks in advance,
Porto

댓글 수: 4

James Tursa
James Tursa 2017년 4월 4일
This is a linking error. The linker can't find the _matOpen function, which means you have not linked in all of the necessary MATLAB library files.
I've searched for the matOpen function on the include folder, in the Matlab installation folder. Then I found two libraries that refer this to function, and added both to the code:
#include "C:\MATLAB\R2015b-x64\extern\include\mat.h"
#include "C:\MATLAB\R2015b-x64\extern\include\mclmcrrt.h"
But it stills returning the error message.
Thank you for answering.
James Tursa
James Tursa 2017년 4월 4일
편집: James Tursa 2017년 4월 4일
name.h files are text header files meant for the compiler. They are not compiled object library files meant for the linker. The library files meant for the linker would be ending in .lib for example. And you need to give these names to the linker ... not #include them as part of your source code.
Tiago Portolon
Tiago Portolon 2017년 4월 5일
편집: Tiago Portolon 2017년 4월 5일
You are right, I just didn't write a .h file to refer to the libraries. Thanks for your answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Tiago Portolon
Tiago Portolon 2017년 4월 7일

0 개 추천

  • The intent was to make a C-function, to be included later in a block on simulink, using the Legacy Code Tool. After it, compile the simulink model with the block. The main goal of this actions was to have a compiled model able to read different inputs in .mat format.

카테고리

도움말 센터File Exchange에서 Write C Programs to Read MAT File Data에 대해 자세히 알아보기

질문:

2017년 4월 4일

답변:

2017년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by