ld:重复符号 [英] ld: duplicate symbol

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

问题描述

我正在学校项目,我从Xcode得到一些奇怪的错误。我使用TextMate的Command + R函数来编译项目。编译似乎工作正常,但链接失败与错误消息我不明白。

I'm working on a school project and I'm getting some weird errors from Xcode. I'm using TextMate's Command+R function to compile the project. Compilation seems to work okay but linking fails with an error message I don't understand.

ld输出:


ld:重复符号text_field(std :: basic_istream >&)in /path/final/build/final.build/Release/final.build/Objects-normal/ppc/generics.o和/path/final/build/final.build/Release/final.build/Objects -normal / ppc / main.o
collect2:ld返回1退出状态

ld: duplicate symbol text_field(std::basic_istream >&)in /path/final/build/final.build/Release/final.build/Objects-normal/ppc/generics.o and /path/final/build/final.build/Release/final.build/Objects-normal/ppc/main.o collect2: ld returned 1 exit status

下面是我的文件io_functions.cpp是整个项目中text_field的唯一声明。

Below is my file io_functions.cpp This is the only declaration of text_field in the entire project.

#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

#ifndef ENDF
#define ENDF '|'
#define ENDR '\n'

/**
reads one field from a given input stream
Usage: var = text_field(in)
*/
string text_field(istream &in){
	string s;
	getline(in, s, ENDF);
	return s; 
}

long long_field(istream &in){
	return atol(text_field(in).c_str()); 
}

int int_field(istream &in){
	return atoi(text_field(in).c_str()); 
}

double double_field(istream &in){
	return atof(text_field(in).c_str()); 
}

#endif

出了什么问题?由于很多原因,我不想发布我的项目的整个来源。

What is going wrong? For a number of reasons I don't want to post my project's entire source.

推荐答案

我的第一个想法是,你在链接器命令中包含它两次,但它似乎抱怨有同样的函数 main.o generics.o

My first thought was that you're including it twice on the linker command but it appears to be complaining about having the same function in main.o and generics.o.

因此,您似乎将 io_functions.cpp 文件包含在 main.cpp 和<$ c $

So it looks like you're including the io_functions.cpp file into the main.cpp and generics.cpp which is a bad idea at the best of times.

你应该有一个头文件(例如, io_functions.h ),它指定 io_functions.cpp 中包含的所有内容,并将两个。

You should have a header file (e.g., io_functions.h) that specifies everything contained in io_functions.cpp and include that header file into the other two.

这篇关于ld:重复符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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