C - 将 base64 方法添加到我的文件中

标签 c makefile base64

我找到了这些库:http://svn.opendnssec.org/trunk/OpenDNSSEC/common/用于c中的编码。我想使用它们,但我不知道如何添加它们。

如果我添加#include "b64_ntop.c"我对#include <config.h>有疑问在 b64_ntop.c 中(没有这样的文件或目录)。如何添加这些模块?

My makefile:
CC=gcc
CFLAGS=-std=gnu99 -Wall -pedantic

all: rdtclient

rdtclient: b64_ntop.o rdtclient.o 
    $(CC) $(CFLAGS) b64_ntop.o rdtclient.o -o rdtclient

感谢帮助

最佳答案

对于该特定文件,您可以删除除 <stdlib.h> 之外的所有 header ( abort() 需要),但您可以添加 <stdint.h>获取uint8_t .

#include <config.h>      // Remove

#include <sys/types.h>   // Remove
#include <sys/param.h>   // Remove
#include <sys/socket.h>  // Remove

#include <netinet/in.h>  // Remove
#include <arpa/inet.h>   // Remove

#include <ctype.h>       // Remove
#include <stdio.h>       // Remove
#include <stdlib.h>      // Keep
#include <string.h>      // Remove
#include <stdint.h>      // Add

不需要我能看到的其他内容,当我测试它时,GCC 同意我的观点。

我不确定引入了哪个 header uint8_t ;最有可能的是<sys/types.h> ,但 C 标准说 <stdint.h>这样做(或 <inttypes.h> 这样做)。

您还应该有一个声明函数的 header ,并且该 header 应包含在该文件中以确保函数声明和定义一致,并且 header 应包含在使用该函数的每个源文件中。显然,又是一个#include源文件中的行。

<小时/>

一般来说,如果文件使用<config.h> (或者,更常见的是 "config.h" ),那么您需要使用配置工具(通常 autoconfautomake )或 configure由工具生成的脚本来创建 config.h header 。在这个文件中,没有受配置头影响的条件代码,因此可以将其删除。

<小时/>

清理完 header 列表后,您可以像对待项目中的任何其他源文件一样对待该文件。最好将其编译为单独的目标文件(不需要特殊选项)并添加到构建中。这就是你的makefile似乎做得很好。有时,在另一个源文件中包含一个源文件(而不是头文件)是明智的或必要的。不过,合理的次数是受到严格限制的。

关于C - 将 base64 方法添加到我的文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364787/

相关文章:

php - 有人可以解码这个脏代码吗?

c++ - "-x c"后返回 native 文件处理

loops - 在makefile或CMake文件中的列表上并行迭代

linux - 具有多个命令的 Sublime Text 构建系统

ansible - 如何使用 Ansible 模块将 Base64 var 解码为二进制文件

javascript - Base64 html图像不能复制和粘贴

c - 子进程的文件权限

c - 简单计算的问题

c - c中 float 的精确表示

c - 如何有意创建 .dep 文件?