Relative path with #pragma comment(lib)

假如想象 提交于 2019-12-03 03:36:38

No, not if this needs to be relative from a .cpp file. Which is pretty unusual, you cannot normally guarantee that a .lib got deployed in a directory that's relative from a client source code that uses the library. Although you can certainly give install instructions that stipulate this.

The normal way is to just specify "foo.lib" and have the linker configured to search the proper directory for the .lib file with the Additional Library Directories setting. Which allows the .lib to be deployed anywhere but the library user will have to update the setting when he sets up his project. This is otherwise a very normal configuration task. And not terribly different from specifying the library in the Additional Dependencies setting.

Keep in mind that the #pragma is typically most useful to help the client programmer to use the proper version of a static link library. You normally have to provide 4 builds of a static .lib, debug vs release and /MT vs /MD. Possibly multiplied by the number of VS versions you are willing to support. This can get hairy in a hurry. The _DLL, _DEBUG and _MSC_VER predefined macros help you to generate the correct #pragma.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!