いいえ; ヘッダーのみが含まれます。
ソースを個別にコンパイルし、それを使用するコードにリンクします。
例(おもちゃのコード):
stack.h
extern int pop(void);
extern void push(int value);
stack.c
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
enum { MAX_STACK = 20 };
static int stack[MAX_STACK];
static int stkptr = 0;
static void err_exit(const char *str)
{
fprintf(stderr, "%s\n", str);
exit(1);
}
int pop(void)
{
if (stkptr > 0)
return stack[--stkptr];
else
err_exit("Pop on empty stack");
}
int push(int value)
{
if (stkptr < MAX_STACK)
stack[stkptr++] = value;
else
err_exit("Stack overflow");
}
test.c
#include <stdio.h>
#include "stack.h"
int main(void)
{
for (int i = 0; i < 10; i++)
push(i * 10);
for (int i = 0; i < 10; i++)
printf("Popped %d\n", pop());
return(0);
}
コンパイル
c99 -c stack.c
c99 -c test.c
c99 -o test_stack test.o stack.o
または:
c99 -o test_stack test.c stack.c
したがって、ソースファイルをコンパイルして(オプションでオブジェクトファイルを生成し)、それらをリンクします。多くの場合、stack.o
ファイルは(標準Cライブラリ以外の)ライブラリに配置され、そのライブラリにリンクします。もちろん、これは標準Cライブラリ関数でも起こります。Cコンパイラは、Cライブラリ(通常は-lc
)をリンクコマンドに自動的に追加します。