在终端(MACOS)中编译Hello World.cpp
Compiling hello world.cpp in terminal (macOS)
我正在尝试在终端编译C Helloworld。
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
i CD到包含代码的目录。我设法使用命令g -o hello c_helloworld.cpp编译。但是当我使用命令gcc -o hello c_helloworld.cpp时,我会收到以下错误。
架构的未定义符号x86_64:" std :: __ 1 :: locale :: use_facet(std :: __ 1 :: locale :: locale :: id&amp;(const", 从: STD :: __ 1 :: CTYPE CONST&amp;std :: __ 1 :: use_facet>(std :: __ 1 :: locale const&amp;( 在c_hellowlld-a3d3b8.o中 引用以下参考: std :: __ 1 :: basic_ios> :: wide(char(c_helloworld-a3d3b8.o" std :: __ 1 :: basic_string, std :: __ 1 ::分配器> :: __ init(未签名长,char(",引用 从: std :: __ 1 :: basic_string,std :: __ 1 ::分配器> :: basic_string(basic_string(unsigned long,char( c_helloworld-a3d3b8.o" :: 〜basic_string((",从: std :: __ 1 :: ostreambuf_iterator> std :: __ 1 :: __ ________d_and_output>(std :: __ 1 :: ostreambuf_iterator>,char const*,char const*,char const*,char const*,char const*,char const*,std :: __ 1 :: ios_base&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp; C_Helloworld-a3d3b8.o" std :: __ 1 :: basic_ostream> :: put(char(",从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: endl (std :: __ 1 :: basic_ostream>&amp;(在c_helloworld-a3d3b8.o中 std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: endl (STD :: __ 1 :: BASIC_OSTREAM>&amp;(在c_helloworld-a3d3b8.o中 :: Sentry :: Sentry(STD :: __ 1 :: BASIC_OSTREAM>&amp;(",从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: __ put_character_sequence (std :: __ 1 :: basic_ostream>&amp; char const*,unsigned long(在c_helloworld-a3d3b8.o中 " std :: __ 1 :: basic_ostream :: Sentry :: 〜Sentry((",从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: __ put_character_sequence (std :: __ 1 :: basic_ostream>&amp; char const*,unsigned long(在c_helloworld-a3d3b8.o中 引用以下参考: _ Main在C_HELELELD-A3D3B8.O中 STD :: __ 1 :: CTYPE CONST&amp;std :: __ 1 :: use_facet>(std :: __ 1 :: locale const&amp;( 在c_helloworld-a3d3b8.o中 从: std :: __ 1 :: basic_ios> :: widen(char(c_helloworld-a3d3b8.o" 从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: __ put_character_sequence (std :: __ 1 :: basic_ostream>&amp; char const*,unsigned long(在c_helloworld-a3d3b8.o中 " std :: __ 1 :: ios_base :: clear(unsigned int(",从: std :: __ 1 :: ios_base :: setState(unsigned int(c_helloworld-a3d3b8.o" std :: terminate((",从: ____clang_call_call_terminate in C_helloworld-a3d3b8.o" ___cxa_begin_catch",从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: __ put_character_sequence (std :: __ 1 :: basic_ostream>&amp; char const*,unsigned long(在c_helloworld-a3d3b8.o中 ____clang_call_call_terminate in C_helloworld-a3d3b8.o" ___cxa_call_unexped",从: std :: __ 1 :: ostreambuf_iterator> :: ostreambuf_iterator(std :: __ 1 :: basic_ostream>&amp;(在c_helloworld-a3d3b8.o
中 " ____cxa_end_catch",从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: __ put_character_sequence (std :: __ 1 :: basic_ostream>&amp; char const*,unsigned long(在c_helloworld-a3d3b8.o中 " ____gxx_personality_v0",从: std :: __ 1 :: basic_ostream>&amp;std :: __ 1 :: __ put_character_sequence (std :: __ 1 :: basic_ostream>&amp; char const*,unsigned long(在c_helloworld-a3d3b8.o中 std :: __ 1 :: ostreambuf_iterator> std :: __ 1 :: __ ________d_and_output>(std :: __ 1 :: ostreambuf_iterator>,char const*,char const*,char const*,char const*,char const*,char const*,std :: __ 1 :: ios_base&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp&amp; c_helloworld-a3d3b8.o std :: __ 1 :: ostreambuf_iterator> :: ostreambuf_iterator(std :: __ 1 :: basic_ostream>&amp;(in C_helloworld-a3d3b8.o std :: __ 1 :: basic_ios> :: widen(char(c_helloworld-a3d3b8.o C_Helloworld-A3D3B8.O LD中的矮人异常易位信息(__eh_frame( clang:错误:链接器命令因出口代码1失败(使用-V查看 调用(
GCC用于编译C程序(默认情况下(,G 适用于C 。因此,这是期望的。
默认情况下,GCC链接到标准C库。如果要编译C 程序,则可以通过添加以下选项链接到标准C 库:
gcc -o hello c_helloworld.cpp -lstdc++
ps。我建议您在提出问题之前搜索网站,已经有一个答案。
用GCC
使用G 更容易编译.CPP文件。通过在目录中运行./outputfile
来执行编译代码。因此,基本上会运行
g++ file.cpp -o file && ./file
在命令行中
编辑:我的错误.. gcc
也可以在此处使用,但是只使用G
- 无法编译wxWidgets Hello World
- 如何使用CLion和MSVC编译器工具链编译wxWidgets Hello World应用程序而没有错误?
- 为什么 const char* const & = 可以编译"hello"?
- macos GCC 工具链编译简单 hello 世界的问题
- 为什么一个简单的"Hello World"风格的程序不能用Turbo C++编译?
- Visual Studio 中的 Hello World C++ 应用程序 - 关于预编译标头不同的问题
- CPP-Netlib Hello World 示例不会在 Linux 上编译
- 在终端(MACOS)中编译Hello World.cpp
- 使用 Visual Studio Code 在 Linux 中创建和编译"hello world"应用程序
- 用Mac OS X Sierra上的OpenCV C 编译Hello World
- WxWidgets Hello World 编译失败:"wchar_t must be available"
- 编译QT Hello World程序时未定义的参考错误
- 从OpenVDB编译Hello World示例
- 用于在 Visual Studio 2005 中编译 Win32 "hello world"的命令行
- 无法在我的 OSX 中编译"hello world" cpp
- V8 "Hello World"示例 - 在 Ubuntu 13.10 上编译 - 大量未定义的引用错误 "icu_46"
- "Operation not permitted" 在 El Capitan 上运行 hello world 二进制编译 w/ clang++
- 用 Mingw 编译的 C++ 文件不打印 Hello World
- 默认"Hello World"示例上的黑莓 10 编译错误
- 提升::测试:编译和运行"hello world"程序