C-source /usr/include header 的文件(例如 stdio.h)

C-source file for /usr/include header (e.g. stdio.h)

我想尝试使用 openssl,因此想更改源代码。 我找到了包含 #include <openssl/ec.h> 的代码,并且显然使用了 header 中的函数。但是我找不到文件 ec.c,据我所知,C 通常位于 header(在 /usr/include/openssl/ec.h 处)。同样在openssl (https://github.com/openssl/openssl)的github源中,ec.h位于openssl-master/include/openssl但没有ec.c

所以:gcc 在哪里寻找 ec.h 中定义的方法?

感谢您的解答!

对于大型库项目(如 openssl),通常将 header 文件放在 include 目录中,将源文件放在单独的源目录中。客户端应用程序需要包含文件和已编译的库 - 但它们不需要库源文件。

回答你的问题:

https://github.com/openssl/openssl/blob/master/apps/ec.c

此外,ec.h 中的函数 定义 。它们在那里声明,并在相应的.c 文件中定义。声明和定义之间的区别在 C 和 C++ 中都很重要。

最后,没有 ec.h header 相对应的单个 ec.c 文件。这是一个常见的约定,但其他库的结构可能只有一个 header(为了便于用户使用),但有许多单独的源文件(以帮助组织库)。所以你可能有 ec_core.c, ec_sign.c, ec_encrypt.c, ec_key_exchange.c.

我了解到您想修改 OpenSSL 源代码。在 C 编程中,并非所有 /h 文件都必须有相应的 .c 文件。

There must be one to many mappings between header files and source files. Even though you din't have corresponding ec.c for ec.h file under OpenSSL, the functionalities declared in ec.h might be defined some where else(in any other source file of openSSL or some other dependency). Finally your OpenSSL binaries that is libeay.lib/.so and SSLeay.lib/.so (Considering linux platform) would have the symbols defined for the corresponding function declarations.

我假设您正在尝试查看系统安装的 OpenSSL 库,您只能在其中找到头文件和二进制文件,而不是源代码。您可以从 git 存储库下载 OpenSSL 源代码并尝试对源代码进行更改并构建它。

如前所述,您可能在某些地方以源格式或二进制格式定义了函数,以便最终输出(二进制文件)链接到定义。