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

时间: 2024-08-25 11:56:34

Mac上编译C++报错的相关文章

mac上安装pil报错: ERROR: Could not find a version that satisfies the requirement pil (from versions: none):

mac上安装pil报错: ERROR: Could not find a version that satisfies the requirement pil (from versions: none): 原文地址:https://www.cnblogs.com/Zhao159461/p/12629635.html

在Mac上使用Gistore报错

安装过程无误,也单独安装了bindfs: ? ? brew list ? ? bindfs docker openssl python sqlite ? ? boot2docker gdbm pkg-config readline ? 在执行备份时,报错: $ sudo gistore commit backup.git/ 04-14 12:01:53 CRITICAL Exception caught abort:Traceback (most recent call last): File

编译nagios-plugins报错./stdio.h:456:1:

在AWS的EC2上编译nagios-plugins报错: ./stdio.h:456:1: error: 'gets' undeclared here (not in a function) make[4]: *** [localcharset.o] Error 1 make[4]: Leaving directory `/root/nagios-plugins-1.4.16/gl' make[3]: *** [all-recursive] Error 1 make[3]: Leaving di

Mac上编译并运行Android5.0源码

下载.配置环境.build和运行参考的都是Android Source提供的文档,包括:Initializing a Build Environment,Downloading the Source和Building the System. 我是在OSX 10.10.3上编译的AOSP,记录一下中途碰到的各种问题. 下载 AOSP需要FQ,而且经常会断,还好是断点续传,坚持个两三天怎么也能下下来. case sensitive system 我在Mac上对file system只会用Disk U

Xcode6编译SDWebImage报错原因分析(SDWebImageDownloaderOperation.m错误)

之前写了一片关于编译SDWebImage报错解决方法的文章: http://blog.csdn.net/cuibo1123/article/details/39434015 结果很多人问这个问题的原因,那就在这里给大家说一说好了,分析思路一并送上(不过我还是建议大家自己动手去分析). 首先,如果新建工程,按照SDWebImage的方式声明输出口并引用: @interface ZCTest () @property (assign, nonatomic, getter = isExecuting)

源码编译php-5 报错整理

阿里云上 源码编译 php 报错的集中整理 [[email protected] php-5.5.31]#   ./configure --prefix=/module/application/php-5.5/--enable-pcntl --enable-fpm --enable-posix --enable-mysqlnd --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --

安装编译qemu-kvm报错Make sure to have the zlib libs and headers installed.

[[email protected] qemu-kvm.git]# ./configure Error: zlib check failed Make sure to have the zlib libs and headers installed. 解决上面报错需要安装zlib相关的软件 [[email protected] qemu-kvm.git]# yum install zlib* 安装完上面软件后继续出现下面报错 [[email protected] qemu-kvm.git]# .

尝试在Mac上编译DNX

自从XRE改名为DNX至今,从来没有在Mac OS X上成功编译过DNX.一直很纳闷,难道DNX的开发人员不用Mac?今天突然明白了,DNX的开发人员真的不用Mac.而且DNX用的2个持续集成服务AppVeyor与Travis,一个是Windows环境,一个是Linux环境,就是没有Mac OS X环境. 看来不能指望DNX的开发人员短期内解决这个问题了,只能自己动手. 编译的错误信息如下(编译命令./build.sh): Restore complete, 725ms elapsed info

PHP编译安装报错: mcrypt.h not found. Please reinstall libmcrypt.

PHP编译安装报错: mcrypt.h not found. Please reinstall libmcrypt. 转载2016-04-25 12:40:44 标签:linuxitphp 解决方法: 1.为系统安装perl-Geo-IP,默认yum源中没有这个包,特意安装epel第三方yum源[[email protected] ~] rpm -Uvh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rp