VinayKumarL-2425 avatar image
0 Votes"
VinayKumarL-2425 asked MinxinYu-MSFT commented

VS2019 linker fails to detect the object file of static library with CFG enabled

We have a static library xyz.lib. It has abc.obj in it.
These object files are built with CFG flag enabled.

But creation of DLL from this static library fails with lot unresolved symbols.

LINK /nologo /NODEFAULTLIB /OPT:NOREF /NXCOMPAT /DynamicBase /STACK:2097152 /def:"xyz.def" /out:xyz.dll pqr.obj /implib:"xyz.lib" /dll xyz.lib

The same works fine. If I recreate/rearrange the xyz.lib with some dummy operations on static library(xyz.lib) as follows:

LIB xyz.lib /EXTRACT:abc.obj /OUT:abc.obj
LIB /out:xyz.lib xyz.lib abc.obj

Any specific reason for this behavior? Any workaround to resolve this problem?

NOTE: This behavior is not seen with Visual Studio 2015

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you provide a minimal reproducible example? Does this problem exist in VS2022?

0 Votes 0 ·

It is the same steps as mentioned above.
1. Create few object files by compiling with CFG flag enabled.
2. Create a static library out of those object files.
3. Try creating an application(by invoking some functions from those object files) by linking that static library.
4. Linking error is observed.
5. Reorder the object files of the same library as mentioned in the previous comment.
6. It links successfully and binary is created.

0 Votes 0 ·

I'm sorry I can't reproduce your problem with Visual Studio 2022. If the problem still occurs in Visual Studio 2022, you can report it to Developer Community

0 Votes 0 ·

0 Answers