0

我正在尝试编写和编译一些 C 代码,我将使用 frm MATLAB 和 VS 2012

这是我的头文件:

#ifndef _DLLTEST_H_
#define _DLLTEST_H_

#include <iostream>
#include <stdio.h>
#include <windows.h>

extern "C" __declspec(dllexport) int Add(int a, int b);


#endif

这是实现:

#include "stdafx.h"
#include "nureader.h"

extern "C" __declspec(dllexport) int Add(int a, int b)
{
  return (a + b);
}

编译正常,但是当我尝试将 DLL 加载到 MATLAB 时,出现一个奇怪的错误:

>> [a,b] = loadlibrary('nureader.dll', 'nureader.h')
Error using loadlibrary (line 419)
Failed to preprocess the input file.
Output from preprocessor is:nureader.h
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\eh.h(27) : fatal error C1189: #error :  "eh.h
is only for C++!"
4

1 回答 1

2

看看VS的输出

fatal error C1189: #error : "eh.h is only for C++!" 

你想写一个 C 库,对吧?所以不要在其中包含 C++。或使用 G++ 编译,但由于您使用的是 Windows,我认为您没有该选项...

在任何情况下,找出包含“eh.h”的内容并尝试不使用它。如果它在没有它的情况下构建 - 很好,如果不是 - 你只需要隔离程序的 C 部分。通过查看代码,您似乎不需要任何东西

#include <stdio.h>
#include <windows.h>

所以试试吧。

于 2013-01-25T17:17:35.973 回答