Clang, Microsoft linker and standard library

I have successfully created Clang with Microsoft C ++, and I'm trying to build it to compile a welcome global test case; he gets to the creation of the object file, linking the remaining stumbling block with the standard library:

hello-202520.o : error LNK2019: unresolved external symbol _printf referenced in function _main
LINK : error LNK2001: unresolved external symbol _mainCRTStartup

There are comments from previous years that Clang still does not make the Windows connection at all, but I get the impression that they are out of date, and indeed it seems that now they can create Windows-format object files:

clang -c hello.c
ren hello.o hello.obj
link hello.obj

... not barf, so the file format seems to be correct, but still receives unresolved external character errors. We will probably assume that the Microsoft compiler tags its output object files with the standard library with which they should be linked, while Clang does not, and an eye splash with a hexadecimal dump of the corresponding object files seems to confirm this and gives a hint on linker to use:

link /defaultlib:libcmt /defaultlib:oldnames hello.obj

At this stage, I had high hopes, but, alas, he still gives the same unresolved external symbol errors.

What am I still missing?

+3
source share
1 answer

, Clang 32- , 64- MSC, _ C x64, -m64 clang .

+7

Source: https://habr.com/ru/post/1541020/


All Articles