简体   繁体   中英

How to compile a project with clases in Clang?

Seen this post: How do you compile a C++ program with multiple class files from OS X Terminal? I see that to compile with gcc a project with a class (with.h and.cpp) is easy as:

g++ [list of all source files] -o [executableName]

And it actually works for me, but when i try to use Clang :

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

I get:

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

NOTE: i know how to use Makefile 's, but i would like to have a quick way to compile in Clang like in 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. Meanwhile you want getting yet another output file "main". Thus, clang complains it can't generate multiple output files, -o Person.pch and -o main.

Pre-compiled headers should be compiled separately.

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

The first step is not required, if skipped, no pre-compiled headers are used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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