![](/img/trans.png)
[英]How can I get C++ code that compiles via terminal to compile using the Qt IDE?
[英]C++ program compiles and runs in codeblocks, but can't compile it in terminal
我創建了一個包含多個源文件和頭文件的C ++項目。 該程序在代碼塊中編譯和運行良好,但我無法在終端中編譯它。
所有文件都在同一個文件夾中。
這是我輸入的命令:
clang++ -std=c++11 main.cpp file1.cpp file1.h
表明:
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
還有一大堆錯誤:
error: use of undeclared identifier 'std'
在頭文件中。
您應該避免編譯頭文件( .h
)。
試試:
clang++ -std=c++11 main.cpp file1.cpp
頭文件是預處理器將包含在需要它的cpp文件中的東西(那些使用#include
預處理器指令的編譯單元 )。
您不應該編譯頭文件,只能編譯源文件。 在需要引用頭文件的源文件中,將#include "file1.h"
放在頂部。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.