[英]C++ compiler command c++ does not generate output
我在nano
文本編輯器(UNIX 命令行)中編寫了一個 C++ 文件,我正在嘗試使用以下命令執行它: c++ main.cpp
。 當我運行它時,沒有顯示錯誤消息,但是,也沒有成功消息; 根本沒有出現......我也嘗試了clang
,它給了我更多的細節,點擊這里查看錯誤信息。 我的代碼:
#include <iostream>
using namespace std;
int main() {
cout << "Hello" << endl;
return 0;
}
叮當輸出:
/usr/bin/ld: /tmp/main-ad7332.o: in function `main':
main.cpp:(.text+0x11): undefined reference to `std::cout'
/usr/bin/ld: main.cpp:(.text+0x24): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: main.cpp:(.text+0x2d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: main.cpp:(.text+0x36): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: /tmp/main-ad7332.o: in function `__cxx_global_var_init':
main.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: main.cpp:(.text.startup+0x19): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
沒有任何輸出是預期的結果。 運行c++
只編譯提供的源文件。 要運行您的程序,您必須顯式運行生成的可執行文件,默認情況下為a.out
。
關於您從clang
收到的錯誤消息,請確保您使用的是clang++
並記住包含聲明std::cout
的iostream
標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.