体系结构x86_64:C++项目的未定义符号
Undefined symbols for architecture x86_64: C++ Project
我正在编写一个c++项目,希望在该项目中转换为汇编代码。尽管我研究了这个特定的错误,但给出的答案似乎都不能解决我的问题。这是代码:
//
// main.cpp
// TicTacToe
//
//
//
#include <iostream>
void printboard(char board[][3]);
void update(char board[][3],char,int,int);
bool isValid(char board[][3],char,int,int);
int menu();
void game1(char board[][3]);
void game2(char board[][3]);
void game3(char board[][3]);
void game4(char board[][3]);
void def();
bool state(char board[][3],int,int);
using namespace std;
int main(int argc, const char * argv[]) {
//game board, initialize with 0's
char board[3][3] = {{'0','0','0'},{'0','0','0'},{'0','0','0'}};
int choice = menu();
switch(choice)
{
case 1: game1(board);break;
case 2: game2(board);break;
case 3: game3(board);break;
case 4: game4(board);break;
default: def();break;
}
return 0;
}
int menu()
{
int temp;
cout<<"Welcome to Tic-Tac-Toe. Please enter a mode in which to play.n";
cout<<"Enter 1 to choose to play against another opponent.n";
cout<<"Enter 2 to play against easy AI.n";
cout<<"Press 3 to play against medium AI.n";
cout<<"Press 4 to play against hard AI.n";
cin>>temp;
return temp;
}
void update(char board[][3],char choice,int i,int j)
{
toupper(choice);
if(choice == 'O'){
board[i][j] = 'O';
}else{
board[i][j] = 'X';
}
}
void printboard(char board[][3])
{
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cout<<board[i][j]<<"|";
}
cout<<endl;
cout<<"______"<<endl;
}
}
void def()
{
cout<<"Invalid choice. Enter numbers 1-4.n";
}
bool isValid(int board[3][3],char choice,int row,int col)
{
toupper(choice);
if(row >= 3 || col >=3)
return false;
if(choice != 'O' || choice != 'X')
return false;
if(board[row][col] == 'O' || board[row][col] == 'X')
return false;
return true;
}
bool state(char board[][3],int choice1,int choice2)
{
//check for win state, these are absolutes
if((board[0][2] == choice1 && board[1][1] == choice1 && board[0][2] == choice1))
{
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[0][2] == choice2 && board[1][1] == choice2 && board[0][2] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
if(board[0][0] == choice1 && board[1][1] == choice1 && board[2][2] == choice1){
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[0][0] == choice2 && board[1][1] == choice2 && board[2][2] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
if(board[0][0] == choice1 && board[1][0] == choice1 && board[2][0] == choice1){
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[0][0] == choice2 && board[1][0] == choice2 && board[2][0] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
if(board[0][0] == choice1 && board[0][1] == choice1 && board[0][2] == choice1){
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[0][0] == choice2 && board[0][1] == choice2 && board[0][2] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
if(board[0][2] == choice1 && board[1][2] == choice1 && board[2][2] == choice1){
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[0][2] == choice2 && board[1][2] == choice2 && board[2][2] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
if(board[1][0] == choice1 && board[1][1] == choice1 && board[1][2] == choice1){
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[1][0] == choice2 && board[1][1] == choice2 && board[1][2] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
if(board[2][0] == choice1 && board[2][1] == choice1 && board[2][2] == choice1){
cout<<"Player 1 wins!!!n";
return false;
}
else if(board[2][0] == choice2 && board[2][1] == choice2 && board[2][2] == choice2){
cout<<"Player 2 wins!!!n";
return false;
}
return true;
}
void game1(char board[][3])
{
char choice1;
char choice2;
int row;
int col;
bool gamestate;
bool valid;
cout<<"Player 1, would you like to be X or O?n";
cin>>choice1;
cout<<"Player 2, would you like to be X or O?n";
cin>>choice2;
do{
do{
//Get players intput and check if the input is valid
cout<<"Player 1, enter row/col to place your move.n";
cin>>row>>col;
valid = isValid(board,choice1,row,col);
cout<<"Player 2, enter row/col to place your move.n";
cin>>row>>col;
valid = isValid(board,choice2,row,col);
}while(valid);
//check the state of the game
gamestate = state(board,choice1,choice2);
}while(gamestate);
}
void game2(char board[][3])
{
cout<<"In game 2"<<endl;
}
void game3(char board[][3])
{
cout<<"In game 3"<<endl;
}
void game4(char board[][3])
{
cout<<"In game 4"<<endl;
}
这是Xcode输出的错误。它指出问题出在函数IsValid上。尽管我似乎在传递数组,并且原型定义正确。我不知道这里发生了什么。
Ld /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug/TicTacToe normal x86_64
cd /Users/justinfulkerson/dev/CSC11/FulkersonJustinCSC11/Project/TicTacToe
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug -F/Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug -filelist /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Intermediates/TicTacToe.build/Debug/TicTacToe.build/Objects-normal/x86_64/TicTacToe.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Intermediates/TicTacToe.build/Debug/TicTacToe.build/Objects-normal/x86_64/TicTacToe_dependency_info.dat -o /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug/TicTacToe
Undefined symbols for architecture x86_64:
"isValid(char (*) [3], char, int, int)", referenced from:
game1(char (*) [3]) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
问题出在这里。由于我的构建系统,我不得不修复两个编译器警告[这是额外的错误]。无论如何,这里有一个显示问题/修复的差异:
--- gameasm.txt 2015-11-07 13:53:39.299520352 -0800
+++ gameasm.cpp 2015-11-07 14:30:50.049802299 -0800
@@ -52,7 +52,7 @@
void update(char board[][3],char choice,int i,int j)
{
- toupper(choice);
+ choice = toupper(choice);
if(choice == 'O'){
board[i][j] = 'O';
}else{
@@ -76,9 +76,9 @@
cout<<"Invalid choice. Enter numbers 1-4.n";
}
-bool isValid(int board[3][3],char choice,int row,int col)
+bool isValid(char board[3][3],char choice,int row,int col)
{
- toupper(choice);
+ choice = toupper(choice);
if(row >= 3 || col >=3)
return false;
if(choice != 'O' || choice != 'X')
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- 我不断收到对项目"xxx"的错误未定义引用
- 我可以在将项目编译为静态库(未定义的引用)时在代码中使用 QImage 吗?
- 编译Qt项目给出了对运算符delete(void*,unsigned int)的未定义引用
- 无法生成项目,出现错误 - 未定义的体系结构符号 x86_64:"_JNI_CreateJavaVM"
- Google测试 - 使用2个不同的项目时未定义的恢复
- 旧项目编译的未定义引用
- Qt项目中对glew方法的未定义引用
- C++ 项目中未定义的引用
- OpenGL 项目返回时带有未定义的引用
- 尝试在项目中包含 boost::thead 时对 "__gx_personality_sj0" 和其他内容的未定义引用
- XCode无法编译Poco项目,未定义符号
- _WIN64未在 x64 项目中定义
- 3 文件项目中未定义引用中的 C++ 命名空间
- 将项目转换为 qt5 并将未定义的引用转换为 'vtable for qt5 和 cmake
- libmediainfo:qt5 项目未定义的符号错误
- 对我的C++ OpenFrameworks项目中wpa_ctrl函数的未定义引用.需要帮助集成此 c 库
- 在Eclipse中构建C/C++项目时出错:未定义的引用函数