Library importing: #pragma comment VS Visual studio project input
- using #pragma comment(lib, "../../xxx.lib")
- using Visual studio project option
What is the advantage and disadvantage between two method? I'm finding way which is better convenient to manage for many projects.
And what method does Microsoft recommend?
The advantage of #pragma comment is that the user of your library cannot forget to add the setting. Or add the wrong one, it is not uncommon to get lost at the difference between the debug and release build and the /MD vs /MT build. One disadvantage is that troubleshooting linker problems can be difficult in some cases.
There's a third way that's hard to beat for convenience in a solution. Right-click the project that requires the library and click Project Dependencies. Tick the library project. This ensures that the library project is always built before the project and the .lib is automatically added.