[英]Fail compile when include String
Here is a simple C++ program and I believe it should work. 这是一个简单的C ++程序,我相信它应该可以工作。 My code is reference from here.
我的代码是从这里参考。 Convert command line argument to string
将命令行参数转换为字符串
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <iostream>
//using namespace std;
int main(int argc, char *argv[]){
std::string boss;
//printf("PROGRAM NAME: %s\n", argv[0]);
if (argc > 1){
//printf("%s\n",&argv[1][0]);
printf("%s\n",argv[1]);
boss = argv[1];
}
}
When Compile it come out the problem: 编译时出现问题:
/tmp/cctYLBpB.o: In function main': testarg.cpp:(.text+0x1c): undefined reference to
std::basic_string, std::allocator >::basic_string()' testarg.cpp:(.text+0x58): undefined reference to std::string::operator=(char const*)' testarg.cpp:(.text+0x64): undefined reference to
std::basic_string, std::allocator >::~basic_string()' testarg.cpp:(.text+0x78): undefined reference to std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' testarg.cpp:(.text+0x7c): undefined reference to
__cxa_end_cleanup' /tmp/cctYLBpB.o: In function __static_initialization_and_destruction_0(int, int)': testarg.cpp:(.text+0xc0): undefined reference to
std::ios_base::Init::Init()' testarg.cpp:(.text+0xe4): undefined reference to std::ios_base::Init::~Init()' /tmp/cctYLBpB.o:(.ARM.extab+0x0): undefined reference to
__gxx_personality_v0' collect2: error: ld returned 1 exit status /tmp/cctYLBpB.o:在
main': testarg.cpp:(.text+0x1c): undefined reference to
函数中main': testarg.cpp:(.text+0x1c): undefined reference to
std :: basic_string,std :: allocator> :: basic_string()的main': testarg.cpp:(.text+0x1c): undefined reference to
testarg.cpp :(。text + 0x58):未定义引用std::string::operator=(char const*)' testarg.cpp:(.text+0x64): undefined reference to
std :: basic_string,std :: allocator> ::〜basic_string() 'testarg.cpp :(。text + 0x78):对std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' testarg.cpp:(.text+0x7c): undefined reference to
__cxa_end_cleanup的std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' testarg.cpp:(.text+0x7c): undefined reference to
'/tmp/cctYLBpB.o:在函数__static_initialization_and_destruction_0(int, int)': testarg.cpp:(.text+0xc0): undefined reference to
std :: ios_base :: Init的__static_initialization_and_destruction_0(int, int)': testarg.cpp:(.text+0xc0): undefined reference to
:init()'testarg.cpp :(。text + 0xe4):未定义引用std::ios_base::Init::~Init()' /tmp/cctYLBpB.o:(.ARM.extab+0x0): undefined reference to
〜Init()'/tmp/cctYLBpB.o:(.ARM.extab+ std::ios_base::Init::~Init()' /tmp/cctYLBpB.o:(.ARM.extab+0x0): undefined reference to
__gxx_personality_v0'collect2:错误:ld返回1退出状态
Did you guys expert had seen any problem on it ? 你们专家看过任何问题吗? I have no idea ...
我不知道 ...
When you use gcc
to build your program, the standard C++ libraries are not used by the linker. 当您使用
gcc
构建程序时,链接器不会使用标准的C ++库。 Use g++
instead. 请改用
g++
。 Add -Wall
for good measure. 添加
-Wall
以备-Wall
。 You will get useful warning messages that will help you find problems at compile time rather than find them at run time. 您将获得有用的警告消息,这些消息将帮助您在编译时发现问题,而不是在运行时发现问题。
g++ filename.cpp -Wall -o testc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.