编译 c++ 时出现问题使用 cygwin 的代码
我正在尝试在 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 可用,并且它所说的变量未在此范围内声明 当我自己编译文件时不要给出错误
任何帮助将不胜感激
非常感谢
I am trying to compile some source code in cygwin (in windows 7)
and get the following error when I run the make file
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
The problem file is:-
#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);
}
I don't understand what is going on,
the file fcntl.h is available and the varaiables that it says were not declared in this scope
do not give an error when I compile the file on its own
Any help would be much appreciated
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有用 Cygwin 构建过东西,所以这可能是偏离基础的,但考虑到你是在 Windows 上构建的,它有一个不区分大小写的文件系统,你确定编译器可以区分你的头文件
Fcntl.h
和系统头fcntl.h
?它可能只是包含您的标头两次而从未获得系统标头。I've not built things with Cygwin, so this might be off-base, but considering that you're building on Windows, which has a case-insensitive filesystem, are you sure that the compiler can tell the difference between your header
Fcntl.h
and the system headerfcntl.h
? It might just be including your header twice and never getting the system header.这些
#include
语句是怎么回事?您的项目中似乎有一个名为Fcntl.h
的头文件,是吗?里面有警卫吗?如果是这样,也许您不小心使用了与内置标头相同的保护,因此无法获取其内容。 Cygwin 通常在不区分大小写的文件系统上运行,因此即使为这些标头提供类似的名称也可能很危险。What's up with those
#include
statements? It seems like you have a header file in your project calledFcntl.h
, is that right? Does it have include guards in it? If it does, maybe you're accidentally using the same guard as the built-in header, and as a result not getting its contents. Cygwin normally runs on a case-insensitive filesystem, so even giving those headers similar names like that is probably dangerous.