Skip to main content
コードを修正しました。
ソース リンク
StackDestroyer
  • 3,607
  • 7
  • 58
  • 108
ソース リンク

C++のコンパイルがうまくいきません

C++ のコンパイルでエラーが出てはまっています。

環境はmacOSです。

コンピュータ将棋のアルゴリズムというサイトでソースコードが紹介されていたのでそれを動かそうとしています。
http://homepage1.nifty.com/Ike/ComShogi/02.html
のchapter02フォルダのKomaMoves.cppをコンパイルしようとしています。

まず出たエラーが下記です。

コマンドは% g++ -o komaMoves KomaMoves.cpp

KomaMoves.cpp:206:67: error: source file is not valid UTF-8
  ...<8B><E0>","<94>n","<97><B4>",
     ^
KomaMoves.cpp:206:68: error: source file is not valid UTF-8
  ...<E0>","<94>n","<97><B4>",
     ^
KomaMoves.cpp:206:72: error: source file is not valid UTF-8
  ...<94>n","<97><B4>",
     ^
KomaMoves.cpp:206:77: error: source file is not valid UTF-8
  ...<97><B4>",

日本語が書かれている箇所があったのでそこに原因があると思いそこをとりあえず削除して実行できるか確認したところ、続いて下記のエラーが出ました。

% g++ -o komaMoves KomaMoves.cpp
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

どうすればコンパイルできるかご教示いただけるとありがたいです。

ソースコード KomaMoves.cpp

#include "kyokumen.h"

// 方向を示す定数。
int Direct[12]={
    17,1,-15,16,-16,15,-1,-17,14,-18,18,-14
};

// 成ることが出来る駒か?
int CanPromote[]={
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

// その方向に動けるか?その方向に飛んで動くものは入れてはいけない。
int CanMove[12][64]={
    {
    // Direct[0]=17,
    // |/
    //   ̄
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,1,1,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=1,
    // ↓
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-15,
    // \|
    //  ̄
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,1,1,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=16,
    // ←
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-16,
    // →
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=15,
    //  __
    // |\
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-1,
    // ↑
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-17
    // __
    // /|
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=14,先手の桂馬
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-18,先手の桂馬
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-14,後手の桂馬
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=18,後手の桂馬
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    }
};

// その方向に飛んで動くことが出来るか?
// 飛車角香車と龍と馬しかそういう駒はない
int CanJump[12][64]={
    // Direct[0]=17,
    // \|
    //  ̄
    {
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=1,
    // ↓
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-15,
    // \|
    //  ̄
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=16,
    // ←
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-16,
    // →
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=15,
    //  __
    // |\
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-1,
    // ↑
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-17
    // __
    // /|
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=14,先手の桂馬飛び
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-18,先手の桂馬飛び
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=-14,後手の桂馬飛び
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    },{
    // Direct[0]=18,後手の桂馬飛び
//  空空空空空空空空空空空空空空空空空歩香桂銀金角飛王と杏圭全金馬龍
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//  空歩香桂銀金角飛王と杏圭全金馬龍壁空空空空空空空空空空空空空空空
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    }
};

// 駒を盤面に表示するための文字列
char *komaStr[]={
"   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ",
"   "," 歩"," 香"," 桂"," 銀"," 金"," 角"," 飛"," 王"," と"," 杏"," 圭"," 全"," 金"," 馬"," 龍",
"   ","v歩","v香","v桂","v銀","v金","v角","v飛","v王","vと","v杏","v圭","v全","v金","v馬","v龍",
" 壁","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ","   ",
};

// 駒の種類を表示するための文字列
char *komaStr2[]={
"  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ",
"  ","歩","香","桂","銀","金","角","飛","王","と","杏","圭","全","金","馬","龍",
"  ","歩","香","桂","銀","金","角","飛","王","と","杏","圭","全","金","馬","龍",
" 壁","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ",
};