I am working on a project using c++/windows forms (visual studio 2010), we have 4 projects:
We have:
Warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
This warning appeared for the 3 static libraries projects in the same object files (.NETFramework,Version=v4.0.AssemblyAttributes.obj).
We want to eliminate it, but after some search, most topics speak about the precompiled headers to be a reason while we don not use it.
Any new ideas about why this warning exist and how to eliminate it?
Disclaimer: This solution is indeed terrible, and this code should not be added to production build! It is only useful to "hide" the warning.
A better solution would be to remove the file in question from the compilation, as it is anyway useless.
I had a the problem with this warning originating from several dependencies, and I found that it was caused by some translation unit being empty, i.e. empty source files.
These files actually had a content but it was deactivated for visual studio so I just added at the beginning:
__declspec( dllexport ) void getRidOfLNK4221(){}
And now my project compiles without any warning :)
Hope it helps, even if this is a late answer!
I had a c++ static library with an empty module in it, linking which in non-optimized mode gave me that LNK4221 warning. (in Visual Studio) I went to Librarian->All Options, and added "/ignore:4221" to Additional Options. So, the warning has disappeared.
You get this warning because you use only template classes in cpp file. To get rid of it, insert one simple function with no template.
See this: https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4221
In summary, the file exports nothing, so linker does not link, as it thinks it's a waste of effort
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With