架构x86_64的未定义符号:Xcode 5问题 [英] Undefined symbols for architecture x86_64: Xcode 5 Issues

查看:238
本文介绍了架构x86_64的未定义符号:Xcode 5问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习在Xcode中编写C ++,我在Joe Pitt-Francis和Jonathan Whiteley的书中做这个例子。 C ++中的科学计算指南

I am learning to code C++ in Xcode, i am doing this example from the book by Joe Pitt-Francis and Jonathan Whiteley. "Guide to Scientific Computing in C++"

代码如下,

Book.ccp

#include "Book.hpp"
#include <iostream>


int main (int argc, char* argv[])
{
Book good_read;

good_read.author = "Lewis Carroll";
good_read.title = "Alice ";
good_read.publisher = "MA";
good_read.price = 199;
good_read.format = "hardback";
good_read.SetYearOfPublication(1787);

std::cout << "Year of publication of " << good_read.title << " is " << good_read.GetYearOfPublication() << "\n";

Book another_book(good_read);

Book an_extra_book ("the magic");

return 0;

}

Book.hpp

#ifndef book_Header_h
#define book_Header_h

#include <string>
class Book
{
public:
Book ();
Book (const Book& otherBook);
Book (std::string bookTitle);
std::string author, title, publisher, format;
int price;
void SetYearOfPublication (int year);
int GetYearOfPublication() const;
private:
int mYearOfPublication;
};
#endif

当我补充时,我得到了跟随错误。

When I complie, I got the follow error.

Undefined symbols for architecture x86_64:
"Book::SetYearOfPublication(int)", referenced from:
 _main in Book.o
 "Book::Book(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>    >)", referenced from:
  _main in Book.o
 "Book::Book(Book const&)", referenced from:
  _main in Book.o
  "Book::Book()", referenced from:
  _main in Book.o
  "Book::GetYearOfPublication() const", referenced from:
  _main in Book.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

在几个论坛上,它说,问题是Xcode不是编译所有的文件,但我不知道如何解决它,任何建议是非常欢迎。

In several forums it says that the issue is that Xcode is not compiling all the files, but I have no idea on how to solve it, any suggestion is more than welcome.

推荐答案

您在中声明函数 Book :: SetYearOfPublication() > Book.hpp ,但是你永远不要定义它。你必须在一个实现文件中这样做:

You declare function Book::SetYearOfPublication() in Book.hpp, but you never define it. You have to do something like this in an implementation file:

void Book::SetYearOfPublication (int year) {
  // TODO: add code for setting the publication year
}

这篇关于架构x86_64的未定义符号:Xcode 5问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆