lld-link.exe Can't Recognize .obj File Type?

Hi.

Just now when I tried to compile a .cpp file using the LLVM toolset in VS2019, I got two error messages from lld-link:
"
lld-link : error : Debug\cust_std_lib_facilities.obj: unknown file type
lld-link : error : Debug\Ex10_10.obj: unknown file type
"
What’s the reason for this, and is there a way to fix it? This is the first time I’m saying this error; I’ve used LLVM before and this error never came up when I know .obj files should’ve been used then as well.

lld doesn’t care about the file extension; it examines the first few bytes of the file to figure out the filetype. That error message means that examination failed: the header doesn’t correspond to any of the input filetypes lld-link supports.

The Unix “file” utility is generally useful for figuring out what sort of file you’re working with. (On Windows, you can get it through Cygwin or gnuwin32.)

-Eli

I’m guessing you have enabled LTCG. In this case the file extension will be .obj, but it’s actually not a COFF object file, and only Microsoft understands the format of this file.

Make sure LTCG is off and that when you run dumpbin on the obj file you get some reasonable information from it.

My post assumes that you have compiled with MSVC and are linking with cl. If you are compiling with clang-cl and linking with lld-link then definitely lld-link should understand the file. In any case, run dumpbin on the object file and see if it gives you any clues as to whether it’s actually a COFF object file.