使用cygwin编译c ++代码的问题

时间:2010-05-17 21:20:10

标签: c++ cygwin compilation fcntl

我正在尝试在cygwin中编译一些源代码(在Windows 7中) 并在运行make文件时出现以下错误

g++ -DHAVE_CONFIG_H -I. -I..  -I..  -Wall -Wextra -Werror -g -O2 -MT libcommon_a  Fcntl.o -MD -MP -MF .deps/libcommon_a-Fcntl.Tpo -c -o libcommon_a-Fcntl.o `test -f 'Fcntl.cpp' || echo './'`Fcntl.cpp
Fcntl.cpp: In function int setCloexec(int):
Fcntl.cpp:8: error: 'F_GETFD' was not declared in this scope
Fcntl.cpp:8: error: 'fcntl' was not declared in this scope
Fcntl.cpp:11: error: 'FD_CLOEXEC' was not declared in this scope
Fcntl.cpp:12: error: 'F_SETFD' was not declared in this scope
make[4]: *** [libcommon_a-Fcntl.o] Error 1
make[4]: Leaving directory `/abyss-1.1.2/Common'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/abyss-1.1.2'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/abyss-1.1.2'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/cygdrive/c/Users/Martin/Documents/NetBeansProjects/abyss-1.1.2_1'
make: *** [.build-impl] Error 2

问题文件是: -

#include "Fcntl.h"
#include <fcntl.h>


/* Set the FD_CLOEXEC flag of the specified file descriptor. */
int setCloexec(int fd)
{
 int flags = fcntl(fd, F_GETFD, 0);
 if (flags == -1)
  return -1;
 flags |= FD_CLOEXEC;
 return fcntl(fd, F_SETFD, flags);
}

我不明白发生了什么, 文件fcntl.h是可用的,它所说的varaiables没有在这个范围内声明 我自己编译文件时不会出错

非常感谢任何帮助

非常感谢

2 个答案:

答案 0 :(得分:1)

我没有用Cygwin构建东西,所以这可能是偏离基础的,但考虑到你是在Windows上构建的,它有一个不区分大小写的文件系统,你确定编译器可以区分你的标头Fcntl.h和系统标头fcntl.h?它可能只包括你的标题两次而且永远不会得到系统标题。

答案 1 :(得分:1)

那些#include声明怎么了?您的项目中似乎有一个名为Fcntl.h的头文件,是吗?它是否包括警卫?如果是这样,也许你不小心使用了与内置标题相同的保护,结果没有得到它的内容。 Cygwin通常运行在不区分大小写的文件系统上,所以即使给这些标题提供类似名称也许很危险。