ヘッダーを使用してコードを整理しただけですが、これを行ったのと同じように、リンク時にエラーになるという警告が表示されました。
次のようなコード(ヘッダー内にある関数の使用)がありますtest.c
:
#include "test1.h"
/* Some code */
main()
{
Testing();
}
そして私のtest1.h
ヘッダーは次のようなものです:
void Testing();
void print(int, int, int, const char*);
そしてtest1.c
void Testing()
{
print(0xF9, 27, 5, "\xC9\\xBB");
}
void print(int colour, int x, int y, const char *string)
{
volatile char *video=(volatile char*)0xB8000 + y*160 + x*2;
while(*string != 0)
{
*video=*string;
string++;
video++;
*video=colour;
video++;
}
}
コードをコンパイルしようとすると、次のようになりました。
ubuntu@eeepc:~/Development/Test$ gcc -o test.o -c test.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
test.c: 関数 'main' 内:
test.c:11: 警告: 暗黙的関数 'Testing' の宣言<br> ubuntu@eeepc:~/Development/Test$
当時は単なる警告ですが、リンクしようとすると...
ubuntu@eeepc:~/Development/Test$ ld -T linker.ld -o kernel.bin loader.o test.o
test.o: In function Testing'main':
test.c:(.text+0xfc): undefined reference to
私は何をする必要がありますか?