【问题标题】:Header inclusion problems标头包含问题
【发布时间】:2012-07-18 02:14:53
【问题描述】:

在稍微修改一下 Tor 后,我在编译 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是如何声明的代码吗?而使用rend_service_t的代码呢?

标签: c gcc makefile tor


【解决方案1】:

rend_service_trendservice.c 私有的结构 - 它似乎不打算在该 .c 文件之外使用,并且它没有在 rendservice.h 中声明。 (请参阅我正在查看的rendservice.c 版本:https://doxygen.torproject.org/rendservice_8c_source.html)。

所以这不是标题包含问题 - 该结构根本没有在标题中删除。

您应该问一个关于您打算使用struct rend_service_t 做什么的问题。

【讨论】:

  • 是否可以“公开”结构?还是我应该在rendservice.crendservice.h 中编写函数并从control.c 调用它?
  • @Kevin:我对代码库一点也不熟悉。您可能可以将结构移动到两个源文件都使用的某些头文件中,但我怀疑会涉及更多的重构。看起来许多处理该结构的函数在rendservice.c 中标记为static,所以我猜你至少需要使部分或全部这些函数可以从外部访问。此外,rend_service_t 结构可能会聚合需要类似处理的其他几个结构...
【解决方案2】:

您的文件 control.c 正在编译并产生编译错误。不管是在之前还是之后编译rendservice.c。编译器查看的只是 control.c 及其引入的任何头文件。

可能 rend_service_t 的定义在 ifdef 部分中,因此编译器正在跳过它。您可能需要#define REND_SERVICE 或类似的东西...查看rendservice.h 并查看read_service_t 定义是否在ifdef 块内。

【讨论】:

  • 我检查了任何 ifndefs/ifdefs,唯一存在的就是防止包含两次标头,#ifndef _TOR_RENDSERVICE_H... #define _TOR_RENDSERVICE_H
猜你喜欢
  • 2011-09-29
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2021-06-02
  • 1970-01-01
  • 2011-12-21
  • 2023-03-29
相关资源
最近更新 更多