簡體   English   中英

使用vscode,為什么同時包含“iosteam”和“stdio.h”時無法編譯?

[英]Using vscode, why can't I compile when both “iosteam” and “stdio.h” are included?

當我同時聲明時,vscode無法編譯文件並且有錯誤日志:

    > Executing task: C:\mingw64\bin\gcc.exe -g d:\CODES\C++\try\main.cpp -o d:\CODES\C++\try\main.exe <

C:\Users\16337\AppData\Local\Temp\ccqDR0fO.o: In function `__tcf_0':
C:/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
C:\Users\16337\AppData\Local\Temp\ccqDR0fO.o: In function `__static_initialization_and_destruction_0':
C:/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status

我的代碼很簡單:

#include <iostream>
#include <stdio.h>


int main()
{
    printf("print something");
    return 0;
}

Dev-C++ 可以正確編譯該代碼。

如果我刪除#include <iostream> ,它可以正確編譯。

<iostream>是一個標准的 C++ header,所以你需要一個 C++ 編譯器和 Z3175B426046787BEECE27 來使用7it4444 gcc足夠聰明,可以將.cpp文件編譯為 C++,但是它不會將標准庫鏈接到您的程序中,因此是未定義的引用。

您需要使用g++ ,默認情況下它將鏈接標准 C++ 庫,就像 Dev-C++ 一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM