我的基本问题是,我想使用某些在头文件中定义的结构体和函数,但不想在我的代码中包含该头文件。
该头文件是由一个工具生成的。由于我无法访问该头文件,因此无法将其包含在我的程序中。
以下是我的情况的简单示例:
first.h
#ifndef FIRST_H_GUARD
#define FIRST_H_GUARD
typedef struct ComplexS {
float real;
float imag;
} Complex;
Complex add(Complex a, Complex b);
// Other structs and functions
#endif
first.c
#include "first.h"
Complex add(Complex a, Complex b) {
Complex res;
res.real = a.real + b.real;
res.imag = a.imag + b.imag;
return res;
}
my_program.c
// I cannot/do not want to include the first.h header file here
// but I want to use the structs and functions from the first.h
#include <stdio.h>
int main() {
Complex a; a.real = 3; a.imag = 4;
Complex b; b.real = 6; b.imag = 2;
Complex c = add(a, b);
printf("Result (%4.2f, %4.2f)\n", c.real, c.imag);
return 0;
}
我的意图是为my_program构建一个目标文件,然后使用链接器将目标文件链接成可执行文件。在C语言中,我想实现的这个目标是否可能?