Mac OSX Lion で非常に単純な name.c ファイルをコンパイルする際に問題が発生します。
今、私は cs50.net でハーバード CS50 コースをたどり始めました。私はプログラミングの初心者ではありませんが、このコースがどのように教えられているか興味がありました。
これは name.c のソースです。
#include <stdio.h>
#include <cs50.h>
int
main(void)
{
printf("State your name:\n");
string name = GetString();
printf("O hai, %s!\n", name);
return 0;
}
ご覧のとおり、 https ://manual.cs50.net/CS50_Library というライブラリが必要です。
これをコンパイルすると、次のようになります。
Undefined symbols for architecture x86_64:
"_GetString", referenced from:
_main in name-vAxcar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [name] Error 1
ソース ファイル内で同じ GetString() cs50.c 関数を使用すると、完全に機能します。
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
typedef char *string;
string GetString(void);
int
main(void)
{
printf("State your name:\n");
string name = GetString();
printf("O hai, %s!\n", name);
}
string
GetString(void)
{
// CODE
}
なぜこれが起こるのですか?上記のリンクにあるように、ライブラリをインストールしました。確認したところ、cs50.h と libcs50.a の両方がそれぞれ /usr/local/include と /usr/local/lib にあります。
よろしくお願いいたします。