0

我的源文件以:

#include "foo.h"

我可以使用头文件中的所有全局变量、类型和结构。在我的头文件中,我从几个包含开始:

#include<file.h>

然后转到全局变量:

#define GLOBAL

然后结构:

#typedef struct boo;

然后键入。然后我去函数声明。IE:

size_t foo(int*r, size_t nitems);

我做错了什么,我收到链接器错误>

4

3 回答 3

1

The header file provides the function declaration to your source code. As you've found that's enough to get your code to compile but not to get it to link.

To get it to link you have to provide the linker with a file containing the actual compiled function - the function declaration is effectively a promise to the compiler that you will do this.

Exactly how you do it depends on what tools you're using and what form the compiled function is in.

于 2011-07-15T15:56:15.250 回答
1

问题可能在于您的链接方式。

于 2011-07-15T15:25:17.517 回答
0

#define对于简单的替换标识符,其工作方式与复制/粘贴完全相同。

做完之后

#define GLOBAL 5

以下代码

int GLOBAL;
GLOBAL = 13;
putchar(GLOBAL);

变成

int 5;
5 = 13;
putchar(5);

这显然不能编译。

于 2011-07-15T16:02:36.027 回答