道歉,我理解与此非常相似的问题已被相对经常询问,虽然没有一个解决方案似乎对我有用.当试图运行任何合理复杂的c ++代码时,我得到上述错误.完整的错误消息是:
/main: relocation error: ./main: symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference
Run Code Online (Sandbox Code Playgroud)
运行另一个项目,我得到一个非常类似的错误:
./main: relocation error: ./main: symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference
Run Code Online (Sandbox Code Playgroud)
我实际上没有任何编译问题,因为这些项目编译都很好.这只是在我尝试运行可执行文件时发生的.我认为这是我的gcc安装的错误,所以今天我重新安装它,虽然这根本没有帮助.我真的不知道如何解决这个问题,有人可以提供帮助吗?
这是我用来编译其中一个项目的Makefile,我觉得这可能是错误:
CC= g++
CFLAGS= -Wall -g -std=c++11 -lX11 -lpthread
OBJS = main.o Board_Tile.o Sliding_Solver.o
main: $(OBJS)
$(CC) -o $@ $(OBJS)
%.o : %.cc
$(CC) $(CFLAGS) -c $^
Run Code Online (Sandbox Code Playgroud)
我的gcc版本是5.3.0,我正在运行Ubuntu 14.0.4.
bool linear_search(const string A[], int n, string colour, int &count)
{
for (int i = 0; i < n; i++);
{
if (colour == A[i])
{
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
编译错误上面的代码结果'i' was not declared in this scope的if声明if (colour == A[i]).
这与我编写的许多其他for循环非常类似,我不明白为什么它没有在范围中声明.是不是在前一行宣布了?我该如何解决?