Compiling a simple hello world program generates warnings when compiling with clang
. I understand that using clang-cl
will get rid of the warnings.
On Clang's website, it states: "clang-cl is an alternative command-line interface to Clang, designed for compatibility with the Visual C++ compiler, cl.exe."
I do not want to use Microsoft Visual C++'s tool chain. I want to use Clang as the compiler and LLD as the linker.
- What is meant by "compatibility with the Visual C++ compiler"?
- How do I know which linker is used by default? Clang's documentation says that LLD is used by default, but, if so, then why is there a warning? And why is
clang-cl
the recommended solution for this warning?
clang
I compiled:
clang main.cpp
and got warnings:
main-a354e7.o : warning LNK4217: locally defined symbol _CxxThrowException imported in function "class std::num_put<char,class std::ostreambuf_iterator<char,struct std::char_traits<char> > > const & __cdecl std::use_facet<class std::num_put<char,class std::ostreambuf_iterator<char,struct std::char_traits<char> > > >(class std::locale const &)" (??$use_facet@V?$num_put@DV?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@@std@@YAAEBV?$num_put@DV?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@@0@AEBVlocale@0@@Z)
main-a354e7.o : warning LNK4217: locally defined symbol __std_terminate imported in function "int `public: __cdecl std::locale::~locale(void)'::`1'::dtor$6" (?dtor$6@?0???1locale@std@@QEAA@XZ@4HA)
It still generated an a.exe
file. However, this same command generates no file when run in a Debian terminal (WSL Windows Subsystem for Linux) and has errors.
clang && lld [lld-link]
I tried compiling to object code and then passing this to LLD. It resulted in an error:
clang -c main.cpp -o main.o
lld-link main.o
lld-link: error: could not open libcpmt.lib: no such file or directory
- What is this library? Where did it come from? Why is it not found?
main.cpp
#include <iostream>
using namespace std;
int add1(int x);
int main()
{
int a;
a = 1;
cout << a << endl; //prints a and goes to new line
a = add1(a);
return 0; //must return 0 to tell the OS the
//program executed successfully
}
int add1( int x )
{
x = x + 1;
return x;
}