Mac OS X 上的 GCC 7 找不到C++标准库
GCC 7 on Mac OS X doesn't find C++ standard library
我一直在尝试编译以下简单的程序:
#include <iostream>
using namespace std;
int main() {
std::cout << "Test compilation" << std::endl;
return 0;
}
我在Mac OS X 10.11.6上使用GGC 7(通过自制软件安装(。
不幸的是,它没有构建这个简单的测试程序(源文件是test.cpp(:
$ make test.out
gcc-7 -O0 -g -std=c++1z -pedantic -Wall -Wextra -Wno-unused-variable -Wno-sign-compare -Wno-missing-braces -Wmissing-field-initializers
-Werror=implicit test.cpp.cpp -o test.cpp.out
Undefined symbols for architecture x86_64:
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in ccJgvOlx.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccJgvOlx.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccJgvOlx.o
"std::cout", referenced from:
_main in ccJgvOlx.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>>&)", referenced from:
_main in ccJgvOlx.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>>&, char const*)", referenced from:
_main in ccJgvOlx.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [test.out] Error 1
我的 GCC 配置如下:
$ gcc-7 -v
Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/7.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/7.2.0/lto-wrapper
Target: x86_64-apple-darwin15.6.0
Configured with: ../configure --build=x86_64-apple-darwin15.6.0 --prefix=/usr/local/Cellar/gcc/7.2.0 --libdir=/usr/local/Cellar/gcc/7.2.0/lib/gcc/7 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-7 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC 7.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls
Thread model: posix
gcc version 7.2.0 (Homebrew GCC 7.2.0)
我需要更改什么才能编译和运行这个简单的测试程序?
我不是你尝试用 C 编译器编译C++程序所做的事情。
根据我的经验,如果您使用g++
,应该不会有这样的问题:
g++-7 -O0 -g -std=c++1z -pedantic -Wall test.cpp.cpp -o test.cpp.out
我建议您将规则从
test.out: test.cpp
${CC} ${CPPFLAGS} ...
自
test.out: test.cpp
${CXX} ${CPPFLAGS} ...
在您的制作文件中解决此问题。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 找不到QtResource文件中的文件
- VC++本机单元测试,找不到调试符号
- RegGetValue在当前用户下找不到名称
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- c++找不到具有相同哈希的无序集合元素
- 找不到以下加速库:boost_fiber
- 找不到 FLTK(缺少:FLTK_INCLUDE_DIR)
- 设置 Visual Studio for MPI: 找不到标识符错误
- "assimp/config.h"找不到,但它在文件夹中
- 链接器找不到在虚拟类 c++ 中访问的静态字段的符号
- C++系统找不到指定的文件错误
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- vcpkg 添加新库,但找不到
- Qt 5.11.2 (Clang 8.0 (Apple), 64 位), 找不到 QJSEngine 文件
- 找不到Linux Visual Studio代码C++文件