C中对mat.h的未定义引用

DumbCoder21

我正在尝试运行在matlab的extern examples目录下的examples文件夹中的示例代码。

/*
 * Create a simple MAT-file to import into MATLAB.
 * Calling syntax:
 *
 *   matimport
 *
 * Simplified version of the matcreat.c program.
 * See the MATLAB External Interfaces Guide for 
 * compiling information.
 *
 * Copyright 2010 The MathWorks, Inc.
 */
#include <stdio.h>
#include <string.h> /* For memcpy() */
#include <stdlib.h> /* For EXIT_FAILURE, EXIT_SUCCESS */
#include "mat.h"

int main() {

  /* MAT-file */
  MATFile *pmat;
  const char *myFile = "matimport.mat";

  /* Data from external source */
  const char *extString = "Data from External Device";
  double extData[9] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };

  /* Variables for mxArrays  */
  mxArray *pVarNum, *pVarChar;

  /* MATLAB variable names */
  const char *myDouble = "inputArray";
  const char *myString = "titleString";

  int status; 

  /* Create and open MAT-file */
  printf("Creating file %s...\n\n", myFile);
  pmat = matOpen(myFile, "w");
  if (pmat == NULL) {
    printf("Error creating file");
    return(EXIT_FAILURE);
  }

  /* Create mxArrays and copy external data */
  pVarNum = mxCreateDoubleMatrix(3,3,mxREAL);
  if (pVarNum == NULL) {
      printf("Unable to create mxArray with mxCreateDoubleMatrix\n");
      return(EXIT_FAILURE);
  }
  memcpy((void *)(mxGetPr(pVarNum)), (void *)extData, sizeof(extData));

  pVarChar = mxCreateString(extString);
  if (pVarChar == NULL) {
      printf("Unable to create mxArray with mxCreateString\n");
      return(EXIT_FAILURE);
  }

  /* Write data to MAT-file */
  status = matPutVariable(pmat, myString, pVarChar);
  if (status != 0) {
      printf("Error writing %s.\n", myString);
      return(EXIT_FAILURE);
  } 

  status = matPutVariable(pmat, myDouble, pVarNum);
  if (status != 0) {
      printf("Error writing %s.\n", myDouble);
      return(EXIT_FAILURE);
  }  

  if (matClose(pmat) != 0) {
    printf("Error closing file %s.\n", myFile);
    return(EXIT_FAILURE);
  }

  /* Clean up */
  mxDestroyArray(pVarNum);
  mxDestroyArray(pVarChar);

  printf("Done\n");
  return(EXIT_SUCCESS);
}

但是我收到以下错误:

> c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0x6b): undefined reference to `matOpen_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0xa8): undefined reference to `mxCreateDoubleMatrix_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0xd5): undefined reference to `mxGetPr_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0xfb): undefined reference to `mxCreateString_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0x138): undefined reference to `matPutVariable_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0x17d): undefined reference to `matPutVariable_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0x1af): undefined reference to `matClose_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0x1da): undefined reference to `mxDestroyArray_800'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\aashi\AppData\Local\Temp\ccCh9dHA.o:main.c:(.text+0x1e6): undefined reference to `mxDestroyArray_800'
collect2.exe: error: ld returned 1 exit status

我已经使用GCC如下编译该程序:

gcc main.c -IC:/Progra~1/MATLAB/R2019a/extern/include -LC:\Progra~1\MATLAB\R2019a\extern\lib -LC:\Progra~1\MATLAB\R2019a\bin\win64\libmat.dll -o output

有什么帮助吗?

FangQ

您需要添加-lmx或添加-lC:\Path\to\libmx.dllgcc命令。您可能还需要-lmex -lm

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

C ++未定义的引用

来自分类Dev

C Opengl中的未定义引用

来自分类Dev

对C ++中函数的未定义引用

来自分类Dev

对C ++中函数的未定义引用

来自分类Dev

在子文件夹中编译.h和.cpp时的C ++未定义引用

来自分类Dev

包含math.h和链接libm时的C sinhl未定义引用

来自分类Dev

JavaScript中未定义的对象引用

来自分类Dev

主Makefile中的未定义引用

来自分类Dev

Cygwin中对WinMain的未定义引用

来自分类Dev

在componentDidUpdate引用中未定义

来自分类Dev

构造函数中的未定义引用

来自分类Dev

主Makefile中的未定义引用

来自分类Dev

在main()中未定义对函数的引用

来自分类Dev

未定义对Makefile中的“函数”的引用

来自分类Dev

在Qt中未定义对QDeclarativePropertyMap的引用

来自分类Dev

GSL中的未定义引用

来自分类Dev

在 make 中对“main”的未定义引用

来自分类Dev

C编译-“未定义引用”?

来自分类Dev

C- Readline()未定义引用

来自分类Dev

C ++对模板方法的未定义引用

来自分类Dev

对WinMain的未定义引用(C ++ Mingw)

来自分类Dev

未定义对函数的引用?C ++

来自分类Dev

对C头文件的未定义引用

来自分类Dev

C-未定义的引用

来自分类Dev

C ++:对构造函数的未定义引用

来自分类Dev

未定义对函数c的引用

来自分类Dev

C ++对模板方法的未定义引用

来自分类Dev

C ++ Singleton:“未定义引用”错误

来自分类Dev

C ++“未定义引用”错误