繁体   English   中英

如何用 Clang 中的类编译项目?

[英]How to compile a project with clases in Clang?

看到这篇文章: 如何从 OS X 终端编译带有多个 class 文件的 C++ 程序? 我看到用gcc编译一个带有 class (with.h and.cpp)的项目很容易:

g++ [所有源文件列表] -o [executableName]

它实际上对我有用,但是当我尝试使用Clang时:

clang++-11 main.cpp Person.hpp Person.cpp -o main

我得到:

clang: error: cannot specify -o when generating multiple output files

注意:我知道如何使用Makefile的,但我想有一种快速的方法来编译Clang就像gcc一样。

If you run clang++-11 main.cpp Person.hpp Person.cpp -o main with the header file, clang notices this and compiles the pre-compiled header "Person.pch", the default -o Person.pch is implied. 同时,您还想获得另一个 output 文件“main”。 因此,clang 抱怨它无法生成多个 output 文件,-o Person.pch 和 -o main。

预编译的头文件应该单独编译。

clang++-11 Person.hpp
clang++-11 main.cpp Person.cpp -o main

第一步不是必需的,如果跳过,则不使用预编译的头文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM