In clang, I can just use clang file.o -o file.exe and it links the object file to a executable.
But there's a reason I must link file.o using just -cc1 and that's because I have embedded it in a C++ application. How can I link it using C++?
When you give a .o file to clang with -cc1 option, clang thinks its a source file and produces errors for it.
You just can't do that.
clang -cc1...invokes the compiler only. It does not do linking. If you input an object file it treats it as a source file because the compiler can only consume source files and output object files.Look at this - verbose output of compiling and linking a simple program with clang:
You see that:
compiles
main.cpp, as C++, to the object file/tmp/main-e80981.o. Then the linker does the linking:Perhaps it helps that the clang source file you pointed to appears to be the main source file for the frontend
clangcommand, notclang -cc1, and that the main source file for the compiler appears to be this one. If that is right - and I have only taken a quick glance at the source - then you might hope to proceed to by embedding a call toclang, notclang -cc1.