【发布时间】:2013-07-31 17:51:19
【问题描述】:
我想在 ubuntu 中使用配置了 gcc 的mex 编译 C 代码。我可以在 OSX 中顺利编译代码。但是,当我想在 Linux 中编译它时,编译器会在以 // 开头的注释行中生成错误(它与 /* */ 一起工作正常。由于该程序包含来自第三方库的多个头文件,我无法替换// 和 /* */。
我想知道有没有办法解决这个问题。
MATLAB 版本:R2012b Linux 中的 gcc 版本:4.7.2 OSX 中的 gcc 版本:4.2.1
感谢任何帮助
编辑: 这是我用来编译代码的命令:
mex -g -largeArrayDims -ldl TDSVDHNGateway.c
这里是 mex 产生的错误:
In file included from TDSVDHNGateway.c:2:0:
TDS.h:17:1: error: expected identifier or ‘(’ before ‘/’ token
TDS.h:26:2: error: unknown type name ‘index_t’
TDS.h:27:2: error: unknown type name ‘index_t’
In file included from TDSVDHNGateway.c:2:0:
TDS.h:146:3: error: unknown type name ‘index_t’
TDSVDHNGateway.c:37:3: error: unknown type name ‘index_t’
TDSVDHNGateway.c: In function ‘mexFunction’:
TDSVDHNGateway.c:166:25: error: ‘index_t’ undeclared (first use in this function)
TDSVDHNGateway.c:166:25: note: each undeclared identifier is reported only once for each function it appears in
头文件第17行是:
//Defining index_t
typedef size_t index_t;
如果我将//Defining index_t 替换为/*Defining index_t*/,代码将毫无问题地编译。
【问题讨论】:
-
你能列出编译器错误吗?
-
请确定并发布
mex用来调用gcc的确切命令行。我怀疑那里有一些东西正在禁用对//-style cmets 的支持(有几个选项可以做到这一点(以及其他东西))。 -
允许 C 代码中的 C++ cmets 调用 mex 如下:
mex CFLAGS="\$CFLAGS -Wp,-lang-c-c++-comments" mymexfile.c