c - Mex 在 Linux 中编译 C 代码时生成错误//

标签 c gcc mex

我想在 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*/,代码将可以毫无问题地编译。

最佳答案

来自 the gcc docs ;

In GNU C, you may use C++ style comments, which start with ‘//’ and continue until the end of the line. Many other C implementations allow such comments, and they are included in the 1999 C standard. However, C++ style comments are not recognized if you specify an -std option specifying a version of ISO C before C99, or -ansi (equivalent to -std=c90).

在 Linux 下,默认情况下 mex 添加了 -ansi,这会禁用 C++ 注释。更新您的 mexopts 文件,将 -ansi 替换为 -std=c99 或运行 mex ;

mex -g -largeArrayDims -ldl CFLAGS="\$CFLAGS -std=c99" TDSVDHNGateway.c

关于c - Mex 在 Linux 中编译 C 代码时生成错误//,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17977442/

相关文章:

c - 结构中出现意外的 C 函数指针定义语法错误

python - 海湾合作委员会错误 : command 'gcc-4.0' failed with exit status 1

具有多种功能的 C++ SSE 优化

c - 在源代码中部分禁用 gcc 中的迂腐警告

c - 在 64 位 Windows 7 机器上使用 GCC 作为 MATLAB 2014a 的默认 MEX 编译器

matlab - 如何使用 CMake 和 Visual Studio 2010(64 位)构建 MATLAB R2011a(64 位)mex 文件?

使用 libssh 复制文件

c - 如何在 SSE/AVX 中使用融合乘加 (FMA) 指令

matlab - 为什么在Matlab中发生有关gcc的错误?

c - 掷骰子直方图