Mac上编译C++报错
2016-03-09 09:48
435 查看
今天在使用Mac编译C++文件时,提示以下错误。
通过在stackoverflow翻阅找到相应的解决办法。 发生这种状况的原因是gcc默认文件时c文件,在编译时不会链接c++标准库。我们可以通过以下方式进行指定引入c++标准库
或者使用
参考链接:stackoverflow
Undefined symbols for architecture x86_64: "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from: void std::__1::vector<E, std::__1::allocator<E> >::__push_back_slow_path<E const>(E const&) in main-8b5a99.o "std::terminate()", referenced from: ___clang_call_terminate in main-8b5a99.o "operator delete(void*)", referenced from: std::__1::__vector_base<E, std::__1::allocator<E> >::~__vector_base() in main-8b5a99.o std::__1::__split_buffer<E, std::__1::allocator<E>&>::~__split_buffer() in main-8b5a99.o "operator new(unsigned long)", referenced from: std::__1::__split_buffer<E, std::__1::allocator<E>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<E>&) in main-8b5a99.o "___cxa_begin_catch", referenced from: ___clang_call_terminate in main-8b5a99.o "___cxa_call_unexpected", referenced from: _main in main-8b5a99.o "___gxx_personality_v0", referenced from: _main in main-8b5a99.o ___cxx_global_array_dtor in main-8b5a99.o void std::__1::vector<E, std::__1::allocator<E> >::__push_back_slow_path<E const>(E const&) in main-8b5a99.o Dwarf Exception Unwind Info (__eh_frame) in main-8b5a99.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
通过在stackoverflow翻阅找到相应的解决办法。 发生这种状况的原因是gcc默认文件时c文件,在编译时不会链接c++标准库。我们可以通过以下方式进行指定引入c++标准库
gcc main.c -o macin -lstdc++
或者使用
g++ main.c -o main
参考链接:stackoverflow
相关文章推荐
- C/C++ 中的0长数组(柔性数组)
- C++中函数覆盖和使用虚函数有什么区别
- 如何使用Xcode7软件添加NTL库并运行C++程序。
- C语言struct中冒号用法
- caffe c++
- [转]值得推荐的C/C++框架和库
- C++ cin,getchar,get,getline的区别
- C语言——内存管理
- 怎样计算C++继承、虚继承、虚函数类的大小
- LeetCode 206. Reverse Linked List
- C++继承
- LeetCode 234. Palindrome Linked List
- C语言实现通讯录
- C语言注释与C++注释的相互转换
- C++ 公有继承简析
- c/C++
- C++第一次上机实验
- C++的字面值和字面值类型
- ubuntu配置vim为windows下C++编程风格
- 深入学习C++.2016_3_8