为什么我在我的C 代码中获得链接命令失败错误
Why do I get linker command fail error in my c++ code?
我在我的代码中求解链接错误时遇到了困难。我不明白为什么我会得到这个。我试图重写它,制作相同的参数,但没有任何改变。有什么想法吗?
main.cpp
int first_max(const string &name, Champship& e)
{
ChampshipEnor t(name);
bool l = false;
int _max = -1;
while(!t.end()){
if(!t.current().isHigh == true){
}else if (l){
if(t.current().point > _max){
_max = t.current().point;
e = t.current();
}
}else{
l = true;
_max = t.current().point;
e = t.current();
}
}
return _max;
}
int main(){
string filename;
cout<<"Enter the name of the input file, please:"; cin>>filename;
//First task
cout<<"First taskn";
try{
Champship e;
if(first_max(filename, e)){
cout<<e.racer<<" has scored the most point ("<<e.point<<") in "<<e.year<<endl;
}else{
cout<<"There is no racer matching our search criteria.n";
}
}catch(ChampshipEnor::FileError err)
{
cerr<<"Can't find the input file:"<<filename<<endl;
}
return 0;
}
冠军
//#pragma once
//#include <fstream>
//#include <sstream>
//#include <string>
struct Champship {
std::string racer;
int year;
int point;
bool isHigh = false;
};
class ChampshipEnor{
private:
std::ifstream _f;
Champship _cur;
bool _end;
public:
enum FileError{MissingInputFile};
ChampshipEnor(const std::string &str) throw (FileError);
void first() {next();}
void next();
Champship current() const { return _cur;}
bool end() const { return _end;}
};
冠军
#include "champship.h"
ChampshipEnor::ChampshipEnor(const std::string &str) throw (FileError)
{
_f.open(str);
if(_f.fail())throw MissingInputFile;
}
void ChampshipEnor::next()
{
std::string line;
getline(_f , line);
if( !(_end = _f.fail()) ){
istringstream is(line);
is >> _cur.racer >> _cur.year;
_cur.point = 0;
std::string category;
int pos;
for( is >> category >> pos ; !is.fail(); is >> category >> pos ){
if(category == "magasugras"){
_cur.isHigh = true;
}
switch(pos) {
case 1 :
_cur.point += 12;
break;
case 2 :
_cur.point += 10;
break;
case 3 :
_cur.point += 8;
break;
case 4 :
_cur.point += 6;
break;
case 5 :
_cur.point += 4;
break;
case 6 :
_cur.point += 2;
break;
}
}
//if (_cur.high == true && _cur.point > _max) _max = _cur.point;
}
}
链接器错误,构建代码时得到的:
g -o"/卷/1TB HDD/coding/op/masodikbead/main"/oblumes/1tb hdd/coding/op/masodikbead/main.o"
架构X86_64的未定义符号: "冠军::冠军(STD :: __ 1 :: BASIC_STRING,STD :: __ 1 :: Artocator> const&amp;(",从: first_max(std :: __ 1 :: basic_string,std :: __ 1 ::分配器> const&amp; ,,冠军&amp; amp;(LD:符号(s(架构x86_64找不到符号clang:错误:Linker命令因出口代码1失败(使用-V查看调用(以状态1(0分钟,0秒(终止过程0错误(S(,1个警告(S((0分钟,0秒(
检查存在:/卷/1TB HDD/CODING/OP/MASODIKBEAD/MAIN
您必须构建类似的代码:
g++ "path to your main.cpp" "path to your champship.cpp" -o a.out
请参阅此问题。
您也可以参考本文。
请记住,您必须在编译过程中包括所有.cpp
文件(如果您使用的话(。在您的情况下,您使用的是ChampshipEnor
对象,在您的主函数中,并且类在champship.cpp
中定义。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 链接器命令失败,macOS 上的退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 如何从命令行链接C++库
- Xcode:链接器命令失败,退出代码为 1(使用 -v 查看调用)[C++]
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 链接从命令行转换为Make的库
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- Android Studio 链接器命令在包含 Boost 库时失败
- Cmake 3.8.0在makefiles中生成错误的链接命令
- 为什么我在我的C 代码中获得链接命令失败错误
- Xcode C :链接命令失败,出口代码1未找到-lboost_regex
- VS 2008:链接命令包括我没有要求且不存在的库
- CMake:运行链接命令时出错:%1不是有效的Win32应用程序
- 如何在VS 2012中查看c++链接命令
- CMake(Android工具链)-运行链接命令时出错:没有这样的文件或目录
- 如何使用CMake在链接命令行结束时添加标志?