zoukankan      html  css  js  c++  java
  • Mac上编译C++报错

    今天在使用Mac编译C++文件时,提示以下错误。

     1 Undefined symbols for architecture x86_64:
     2   "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
     3       void std::__1::vector<E, std::__1::allocator<E> >::__push_back_slow_path<E const>(E const&) in main-8b5a99.o
     4   "std::terminate()", referenced from:
     5       ___clang_call_terminate in main-8b5a99.o
     6   "operator delete(void*)", referenced from:
     7       std::__1::__vector_base<E, std::__1::allocator<E> >::~__vector_base() in main-8b5a99.o
     8       std::__1::__split_buffer<E, std::__1::allocator<E>&>::~__split_buffer() in main-8b5a99.o
     9   "operator new(unsigned long)", referenced from:
    10       std::__1::__split_buffer<E, std::__1::allocator<E>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<E>&) in main-8b5a99.o
    11   "___cxa_begin_catch", referenced from:
    12       ___clang_call_terminate in main-8b5a99.o
    13   "___cxa_call_unexpected", referenced from:
    14       _main in main-8b5a99.o
    15   "___gxx_personality_v0", referenced from:
    16       _main in main-8b5a99.o
    17       ___cxx_global_array_dtor in main-8b5a99.o
    18       void std::__1::vector<E, std::__1::allocator<E> >::__push_back_slow_path<E const>(E const&) in main-8b5a99.o
    19       Dwarf Exception Unwind Info (__eh_frame) in main-8b5a99.o
    20 ld: symbol(s) not found for architecture x86_64
    21 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

  • 相关阅读:
    关于MySQL错误 2005
    Eclipse如何导入第三方jar包
    Codeforces Round #377 (Div. 2) D. Exams
    18110 Koishi's travel, Satori's travel
    用Java做的类似皇家守卫战的游戏
    Notepad++如何编译、运行Java
    Codeforces Round #341 (Div. 2)--C. Wet Shark and Flowers
    hdu 2120 Ice_cream's world I
    FZU 1851 组合数
    HUST 1599 Multiple
  • 原文地址:https://www.cnblogs.com/WingPig/p/5256920.html
Copyright © 2011-2022 走看看