稍加修改后,我在编译Tor时遇到问题。
在名为control.c
的文件中,我添加了代码,该代码引用名为rend_service_t
的结构(位于rendservice.h
中)。我将rendservice.h
包含在control.c
的顶部,因为以前没有包含它。
如果尝试使用随附的Makefile,则会出现此错误:
control.c:2841: error: 'rend_service_t' undeclared (first use in this function)
我猜想
rendservice.c
没有被包含或没有被首先编译,所以我检查目录,并且没有用于rendservice的目标文件。我对此感到有些困惑,因为它显然已包含在内。是什么导致这种情况发生?
我还尝试编辑
Makefile.am/.in
,以使rendservice.c/h
在control.c/h
之前,但这没有任何区别。在
control.c
中:...
#include "rendservice.h"
...
static int
handle_control_addservice(control_connection_t *conn, uint32_t len,
const char *body)
{
smartlist_t *args;
rend_service_t *service;
...
在
rendservice.c
中:...
/** Represents a single hidden service running at this OP. */
typedef struct rend_service_t {
/* Fields specified in config file */
char *directory; /**< where in the filesystem it stores it */
smartlist_t *ports; /**< List of rend_service_port_config_t */
rend_auth_type_t auth_type; /**< Client authorization type or 0 if no client
* authorization is performed. */
smartlist_t *clients; /**< List of rend_authorized_client_t's of
* clients that may access our service. Can be NULL
* if no client authorization is performed. */
/* Other fields */
crypto_pk_env_t *private_key; /**< Permanent hidden-service key. */
char service_id[REND_SERVICE_ID_LEN_BASE32+1]; /**< Onion address without
* '.onion' */
char pk_digest[DIGEST_LEN]; /**< Hash of permanent hidden-service key. */
smartlist_t *intro_nodes; /**< List of rend_intro_point_t's we have,
* or are trying to establish. */
time_t intro_period_started; /**< Start of the current period to build
* introduction points. */
int n_intro_circuits_launched; /**< Count of intro circuits we have
* established in this period. */
rend_service_descriptor_t *desc; /**< Current hidden service descriptor. */
time_t desc_is_dirty; /**< Time at which changes to the hidden service
* descriptor content occurred, or 0 if it's
* up-to-date. */
time_t next_upload_time; /**< Scheduled next hidden service descriptor
* upload time. */
/** Map from digests of Diffie-Hellman values INTRODUCE2 to time_t of when
* they were received; used to prevent replays. */
digestmap_t *accepted_intros;
/** Time at which we last removed expired values from accepted_intros. */
time_t last_cleaned_accepted_intros;
} rend_service_t;
...
最佳答案
rend_service_t
是rendservice.c
专用的结构-似乎不打算在该.c文件之外使用,并且未在rendservice.h
中声明。 (请参阅我在此处查看的rendservice.c
版本:https://doxygen.torproject.org/rendservice_8c_source.html)。
因此,这不是标题包含问题-根本没有在标题中添加结构。
您应该问一个问题,您打算将struct rend_service_t
用于什么。
关于c - header 包含问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11533413/