- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当我尝试编译时,我总是遇到这个错误,但不知道为什么
Ld /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug/BATTLESHIP normal x86_64
cd /Users/Itunes/Desktop/Programs/CMPSC122/BATTLESHIP
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/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.8.sdk -L/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug -F/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug -filelist /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/BATTLESHIP.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -o /Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Products/Debug/BATTLESHIP
duplicate symbol __ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEERK5Point in:
/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/main.o
/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/Board.o
duplicate symbol __ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEERK5Point in:
/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/main.o
/Users/Itunes/Library/Developer/Xcode/DerivedData/BATTLESHIP-gefqfgwzntvzlvfyyxoqzmmanjlb/Build/Intermediates/BATTLESHIP.build/Debug/BATTLESHIP.build/Objects-normal/x86_64/Ship.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的头文件和 .cpp 文件是
Board.h
// Board.h - Board class declaration
#pragma once
#include "Point.h"
using namespace std;
#define HIT 'X'
#define SHIP 'S'
#define MISS 'O'
#define WATER '~'
class Board
{
public:
// Constructor
Board();
// Function which prints an image of the board showing hits ( X ) and misses ( O )
void PrintBoard();
// Resets the board for both players before new games begin
void ResetBoard();
// Marks both boards after each guess
void MarkBoard(bool hit, Point guessCoordinate);
// Returns TRUE if the user has guessed the given coordinate
bool CheckGuess( Point guessCoordinate );
private:
// Board used for determining whether the user has guessed a certain position yet or not
bool playerBoard[BOARD_WIDTH][BOARD_LENGTH] = {false};
// Board used soley for output
// KEY: 0 = not yet guessed, 1 = hit, 2 = miss
// intialize all spaces to 0 to show that no guesses have been made yet
int outputBoard[10][10] = { 0 };
};
板.cpp
// Board.cpp - Board class function implementation
#include "Board.h"
Board::Board()
{
}
// Prints the output board to console
void Board::PrintBoard()
{
// Print column numbers
cout << " \t" << " " << 1;
for( int number = 2; number < 11; number++)
cout << " " << number;
cout << endl;
// Print board itself
// i = row number, j = column number
for( int i = 0; i < 10; i++)
{
// int i can double as a row and column counter for checking if a space has been hit
/*cout << " \t";
// Print row lines
for( int k = 1; k < 11; k++)
cout << " __";*/
cout << endl;
// Print row number
cout << i+1 << " ";
cout << "\t";
// Print columns
for( int j = 0; j < 10; j++)
{
cout << "|";
// INSERT CODE THAT PLACES X OR O IF GUESS IS HIT OR SHIP
if( outputBoard[i][j] == 0 )
cout << WATER;
if( outputBoard[i][j] == 1 )
cout << HIT;
if( outputBoard[i][j] == 2 )
cout << MISS;
}
cout << "|";
cout << endl;
}
cout << endl;
}
void Board::MarkBoard(bool hit, Point guessCoordinate)
{
// First mark the board to show the player has guessed this coordinate
playerBoard[guessCoordinate.X][guessCoordinate.Y] = true;
if( hit == true )
{
// Show that the player hit a ship
outputBoard[guessCoordinate.X][guessCoordinate.Y] = 1;
}
else
{
// Show that the player missed the ship
outputBoard[guessCoordinate.X][guessCoordinate.Y] = 2;
}
}
bool Board::CheckGuess(Point guessCordinate)
{
bool previouslyGuessed = false;
// If the given point has already been guessed, make the function return true
if( playerBoard[guessCordinate.X][guessCordinate.Y] )
{
previouslyGuessed = true;
}
else
{
previouslyGuessed = false;
}
return previouslyGuessed;
}
Ship.h
#pragma once
#include <string>
#include "Point.h"
using namespace std;
#define SHIP_TYPES 5
#define MAX_LENGTH 5
enum DIRECTION {HORIZONTAL,VERTICAL};
class Ship
{
public:
// Constructor
Ship();
// Function to initially set all ship to the correct values
void LoadShips( Ship ship[SHIP_TYPES] );
// Function which gives ships their location points and placement orientation
void FillShipData( DIRECTION direction, Point coordinate );
bool isSunk();
bool isHit( Point guess, Ship ship[SHIP_TYPES] );
string GetName()
{ return Name; }
private:
// Ship name
string Name;
// How many spaces the ship occupies
int Length;
// Determines whether a ship lies vertically or horizontally on the board
DIRECTION Direction;
// Holds the coordinates that the ship occupies
Point spaceOccupied[MAX_LENGTH];
};
发货.cpp
#include "Ship.h"
Ship::Ship()
{
}
void Ship::LoadShips(Ship ship[SHIP_TYPES])
{
//Sets the default data for the ships
//we plan to include in the game
//IMPORTANT!! > MUST MATCH SHIP_TYPES -Default=5 (0-4)
ship[0].Name = "Cruiser"; ship[0].Length = 2;
ship[1].Name = "Frigate"; ship[1].Length = 3;
ship[2].Name = "Submarine"; ship[2].Length = 3;
ship[3].Name = "Escort"; ship[3].Length = 4;
ship[4].Name = "Battleship"; ship[4].Length = 5;
}
void Ship::FillShipData( DIRECTION direction, Point coordinate )
{
Direction = direction;
int x,y;
// If the ship will be laid horizontally, give it the initial point plus the x-coordinates to its right
if( Direction == HORIZONTAL )
{
while( coordinate.X+Length >= BOARD_WIDTH || coordinate.X < 0 || coordinate.Y < 0 || coordinate.Y >= BOARD_LENGTH )
{
cout << "Your ship will not be entirely on the board when placed this way. Please choose a new row number and column number separated by a space (ex: x y): ";
cin >> x >> y;
coordinate.X = x;
coordinate.Y = y;
}
for( int i = 0; i < Length; i++ )
{
spaceOccupied[i] = coordinate;
coordinate.X++;
}
}
// If the ship will be laid vertically, give it the initial point plus the y-coordinates below it
else
{
// Be sure the give point will contain and the ship
while( coordinate.Y+Length >= BOARD_LENGTH || coordinate.X < 0 || coordinate.Y < 0 || coordinate.X >= BOARD_WIDTH )
{
cout << "Your ship will not be entirely on the board when placed this way. Please choose a new row number and column number separated by a space (ex: x y): ";
cin >> x >> y;
coordinate.X = x;
coordinate.Y = y;
}
for( int i = 0; i < Length; i++ )
{
spaceOccupied[i] = coordinate;
coordinate.Y++;
}
}
}
// use throwaway to call, one user's guess and the other user's ships
//
bool Ship::isHit( Point guess, Ship ship[SHIP_TYPES] )
{
bool hit = false;
// For loop to examine each ship
for( int i = 0; i < SHIP_TYPES && hit==false; i++ )
{
// For loop to go through each point the ship occupies
for( int j = 0; j < ship[i].Length && hit==false; j++ )
{
// If the player's guess matches a point the ship is located on, it has been hit
if( ship[i].spaceOccupied[j] == guess )
{
hit = true;
// Inform player they landed a hit
cout << "Ship: " << ship[i].Name << " has been hit!\n";
}
}
}
// If the player has missed all ships, inform them
if( hit == false )
cout << "Missed.\n";
return hit;
}
最后是 Point.h
#pragma once
#include <iostream>
using namespace std;
#define BOARD_LENGTH 10
#define BOARD_WIDTH 10
struct Point
{
// A location on the grid defined
// by X(horizontal) Y(vertical) coordinates
int X;
int Y;
bool operator == (const Point& compareTo) const
{
return ( (X == compareTo.X) && (Y == compareTo.Y) );
}
};
ostream& operator <<(ostream& out, const Point& myPoint)
{
out << "(" << myPoint.X << "," << myPoint.Y << ")";
return out;
}
我的主要函数只包含没有函数声明的 Board.h 和 Ship.h。任何帮助将不胜感激!
最佳答案
愚蠢的人,但请确保您没有在某处错误地#imported .m 文件
关于c++ - Xcode 错误 : "2 duplicate symbols for architecture x86_64",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20184582/
我们的开发环境是这样配置的,当我们运行代码的调试版本时,它会在崩溃或 ^C 时进入 gdb。随着最近的一些更改,这种情况不再发生(退出程序而不是进入 gdb),我怀疑符号大小的增加导致了这个问题。 有
刚刚浏览了一个教程,想到了我看到的地方 first_name: 还有一个地方 :first_name 这样对吗?有什么区别? 最佳答案 哈希语法在 Ruby 1.9.2 中发生了变化,以更接近 jso
这里是一个相当抽象的问题,因为我不知道从哪里开始我自己的调查。 我有一个用 CMake 构建的 C 包,它生成 librpdb.so;我为同一个库设置了一个 Ruby Gem,它生成 rpdb.bun
我尝试使用 Symbol 创建对象键并用 Symbol.for 找到对应的值,但它不起作用: const sym = Symbol("x"); let obj = { [sym]: "val" }
这可能是一个愚蠢的问题,但我很高兴知道为什么我们使用带有一些标志的短形式的单符号和带有完整标志的双符号? 例子: 1) -h & --help 2) -f & --force 谁能解释一下原因? 最
我们希望能够在删除物理构建区域时删除符号服务器内容,symstore del 命令对事务 ID 起作用。这是未知的。 How to extract the transaction ID based o
我在一个我不太理解的小程序上遇到这个问题(我对节点红色有点陌生),代码是 var profile = msg.user.profile; var cart = profile.cart = pr
我正在尝试创建一种工资单以在控制台中打印,但我从代码中收到以下错误。很多时候它实际上只是一个错误,但我认为我没有足够的 java 知识来自己修复它。 import java.io.*; import
在 C# 项目中,我在 UnhandledException 中创建了小型转储。在我的 Dev 机器中,项目源和 bin 位于路径 K:\projects\*MYPROJECT* 下,如果我设法让它在
我正在尝试针对另一个使用 libcurl 共享库的共享库 (libtheirstuff.so) 交叉编译我自己的共享库 (libmystuff.so),但出现以下错误: libmystuff.so:
我试图遍历一个数组来检查它是否包含任何通过指定函数的项目。我通过向 Array 对象添加一个 .any() 原型(prototype)来做到这一点: Array.prototype.any = (co
除了这个 undefined symbol 错误外,一切正常: bash-3.2$ make g++ -Wall -g solvePlanningProblem.o Position.o AStarN
我 rsync 目录“Promotion”包含两台具有不同目录结构的机器之间的绝对符号链接(symbolic link)。因此绝对符号链接(symbolic link)在两台机器上都不起作用。为了使它
我有以下 JSX - What is your e-mail address? setStateForProperties(e)}
根据 SVG 的 symbol文档,我可以添加 refX/refY属性给它。 如果我理解正确,我可以使用这些属性来定义符号坐标系中的引用点,因此当我使用 引用它时元素,它将相对于该引用点(而不是默认
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
我是一名优秀的程序员,十分优秀!