编译应用程序时出现奇怪错误
Strange error while compiling app
我使用的是Fedora 18(带有Gnome),我已经安装了gcc和gcc-c++,当我使用gcc -o slowka.o slowka.cpp
命令时,我看到了以下错误:
slowka.cpp:(.text+0x1b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
slowka.cpp:(.text+0x8d): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
slowka.cpp:(.text+0xa0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccp7fTFJ.o: In function `__static_initialization_and_destruction_0(int, int)':
slowka.cpp:(.text+0xdb): undefined reference to `std::ios_base::Init::Init()'
slowka.cpp:(.text+0xea): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccp7fTFJ.o: In function `bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)':
slowka.cpp:(.text._ZSteqIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_EPKS3_[_ZSteqIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_EPKS3_]+0x1f): undefined reference to `std::string::compare(char const*) const'
/tmp/ccp7fTFJ.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
我不知道是什么原因。我的代码:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main()
{
printf("Witaj w aplikacji dodającej słówka ! Czy chcesz włączyć aplikację w tryb permanentny (t/N) ?n");
string x;
scanf("%s", &x);
if(x != "t" && x != "T")
{
printf("Wybrano tryb "jednego słówka" !n");
return 0;
}
return 0;
}
通常,您会使用C++编译器来链接C++程序:
g++ -o slowka.o slowka.cpp
但是,如果您想要一个对象文件,您需要指定-c
:
g++ -c -o slowka.o slowka.cpp
或者:
gcc -c -o slowka.o slowka.cpp
(输出名称将由编译器自动推断,因此-o slowka.o
是可选的。)
相关文章:
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- Visual Studio中的wxwidgets应用程序给出错误"LNK2019 unresolved external symbol"
- 调用 java 的回调() 时应用程序崩溃.由于 detatchThread 而获得运行时错误
- 设置我的应用程序 API 感知并防止系统使其模糊和错误定位
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- QT C++防止关闭应用程序时出现运行时错误
- JNI 在应用程序中检测到错误:在为 innerclass 调用 NewObject 时使用了无效的 jobject
- 如何使用CLion和MSVC编译器工具链编译wxWidgets Hello World应用程序而没有错误?
- 运行 libpng 应用程序时出现运行时错误
- .exe应用程序在windows10中创建新模块时抛出错误,但在windows7中工作正常
- 由于选项卡顺序的原因,鼠标光标总是得到错误的hwnd-MFC应用程序
- C++ 错误的分配应用程序失败
- Android (ART) 崩溃并显示错误 JNI 在应用程序中检测到错误:jstring 是无效的本地引用
- 使用提升过程编译简单的应用程序会生成错误
- Qt 应用程序中与Qt版本相关的运行时错误
- Windows 8上的.exe文件中的MSVCR90.dll错误 - 应用程序无法正确启动(0xc000007b)
- VS2012错误:应用程序无法正确启动(0xc000007b)
- Visual Studio 2012 错误:应用程序无法正确启动 (0xc0000007b)
- QObject::connect()错误.应用程序崩溃.无构建错误