编译c ++文件失败,因为找不到`ssize_t`的定义 [英] compile c++ file failed because can not find the definition of `ssize_t`
问题描述
我有一个c ++头文件 socket_client.h
和一个c ++源文件 socket_client.cc
。在 socket_client.h
中,我有这样的代码示例:
#包括< limits.h>
#include< string>
ssize_t Send(const void * msg,const size_t msg_size / * send msg size * /);
...
在 socket_client.cc $ c
$ p $ #includesomewhere / socket_client.h
#include <$ c $>,我有这样的代码片段:
...
当我用gcc 4.8编译时,编译器会说error 并抱怨说它找不到 ssize_t
的定义;但是,当我在 socket_client.h
中添加 #include
时,它会编译成功。
有人在没有使用gcc 4.4添加 #include< sys / types.h>
的情况下成功编译它。
我完全对此感到困惑。是否有必要添加该行?收集方式是什么?
ps:我使用一个名为blade的工具进行编译,该工具基于scons(对于那些使用gcc 4.4的工具也是如此)。
答案很简单,看看你的包含顺序。在包含 types.h
之前,您可以包含 socket_client.h
。这会导致你的错误。只需更改订单,一切都应该没问题。
I have a c++ header file socket_client.h
together with a c++ source file socket_client.cc
. In socket_client.h
, I have code samples like this:
#include <limits.h>
#include <string>
ssize_t Send(const void *msg, const size_t msg_size/*send msg size*/);
...
In socket_client.cc
, I have code snippet like this:
#include "somewhere/socket_client.h"
#include <sys/types.h>
...
When I compile this with gcc 4.8, the compiler will say "error" and complains that it can not find the definition of ssize_t
; However, when I add #include <sys/types.h>
in socket_client.h
, it will compile success.
There is someone else compile it successfully without add #include <sys/types.h>
with gcc 4.4.
I'm totally confused about this. Is it necessary to add that line? What is the collect way to handle this?
ps:I compile with a tool called blade which is based on scons(and so do those with gcc 4.4).
The answer is simple, have a look at your include order. You include socket_client.h
before you include types.h
. This causes your error. Simply change the order and everything should be fine.
这篇关于编译c ++文件失败,因为找不到`ssize_t`的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!