找不到头文件,即使它位于 -I 指定的目录中

Header file not found even though it is in a directory specified by -I

我正在尝试使用 Mingw 编译 Simulink S-Function。

我的 Makefile 包含以下内容:

MINGWPATH=D:/Mingw
MATLABROOT=C:\PROGRA~1\MATLAB\R2014b
CC=$(MINGWPATH)/bin/gcc 
MEXFLAG=-shared -DMATLAB_MEX_FILE -I$(MATLABROOT)\simulink\include -I$(MATLABROOT)\extern\include -Wl,--export-all-symbols $(LIBS) $(MEXSRC) -o $(MEXTGT).mexw64

LIBS= -L$(MATLABROOT)/bin/win64 -L$(MATLABROOT)/extern/lib/win64/microsoft -lmex -lmx -lmwlapack -lmwblas -leng

MEXTGT=SFCN_Block
MEXSRC=SFCN_Block.cpp
all:$(MEXTGT)

$(MEXTGT): $(MEXSRC)
    $(CC) $(MEXFLAG) -ladvapi32 -luser32 -lgdi32 -lkernel32 -lmingwex

SFCN_Block.cpp 文件在 C:\PROGRA~1\MATLAB\R2014b\simulink\include.

中包含一个 #include 'simstruc.h'simstruc.h

但是我收到以下错误:

SFCN_Block.cpp:12:22: fatal error: simstruc.h: No such file or directory
 #include "simstruc.h"
                      ^

怎么可能出错?

(我的 Matlab 版本是 Windows 7 下的 R2014b(64 位),我正在尝试使用 Mingw 进行编译。我的 Makefile 基于 this question 上接受的答案)。

以下是遇到的一些类似问题:http://www.mathworks.com/matlabcentral/newsreader/view_thread/150266

问题(来自link以上):

I'm using S-Function Builder to read files into my simulink model. I inherited the code and model from another developer. I have to rebuild the S-Function every time I want to change the filename. So it stopped working today for, as far as I can tell, no reason whatsoever. When I press the build button, I get something to the effect of "Linker Error 1083. No such file or Directory "simstruc.h" Every S-function Builder in every model now fails with this same error. I searched for simstruc.h and found it in a couple of directories in the matlab path. I'm thinking that the MEX linker or compiler or whatever is building the S-function for some reason now doesn't know where to look for simstruc.h, maybe it's path was somehow corrupted?

回答(来自同link):

Hi, Here is the fix, you can overwrite the r2010b for the following file from release r2010a

  • C:\Program Files\MATLAB\R2010b\bin\mex.bat

  • C:\Program Files\MATLAB\R2010b\bin\mex.pl

  • C:\Program Files\MATLAB\R2010b\bin\mexext.bat

  • C:\Program Files\MATLAB\R2010b\bin\mexsetup.pm

  • C:\Program Files\MATLAB\R2010b\bin\mexutils.pm

I am not sure which one is the problem file, but it work this way.

将 Makefile 的第一行更改为:

MINGWPATH=D:/Mingw
MATLABROOT="C:\Program Files\MATLAB\R2014b"
SIMULINK_INCLUDE_PATH=$(MATLABROOT)/simulink/include
MATLAB_EXTERN_INCLUDE_PATH=$(MATLABROOT)/extern/include
CC=$(MINGWPATH)/bin/gcc 
MEXFLAG=-shared -DMATLAB_MEX_FILE -IBlocks -IDesignPatterns -ILogging -I$(SIMULINK_INCLUDE_PATH) -I$(MATLAB_EXTERN_INCLUDE_PATH) -Wl,--export-all-symbols $(LIBS) $(MEXSRC) -o $(MEXTGT).mexw64

解决了 No such file or directory 错误。谁能解释一下为什么?

现在我得到以下错误:

C:\Program Files\MATLAB\R2014b/bin/win64/libmex.dll: file not recognized: File format not recognized

但这是另一个问题。