Is Static link of DLL (using *.lib) possible from code only (without add to project, something like #pragma link “…”)?

故事扮演 提交于 2021-01-29 05:54:40

问题


I am upgrading my preexisting CAD/CAM project (quite big one > 10MByte of code) and have to add some special measuring equipment. The problem is I have more than one supplier of the measuring system (although is already decided which one to use) and I want to configure them (using #define in case vendor is changed in future) with code to use only selected device type. So I have something like:

  #define use_vendor1
//#define use_vendor2
//#define use_vendor3

and some of the vendors APIs require their own DLLs so I need for example:

Project/Add to project/vendor1.lib
Project/Remove from project/unused_vendor.lib

if use_vendor1 is used ... That will be uncomfortable to add/remove each type reconfiguration of exe is required. I was wondering if there exist a way similar to this:

#ifdef use_vendor1
#pragme link "vendor1.lib"
#endif

That one does not work of coarse because DLL *.lib is not compiled code as *.obj ...

Having all the libs in the project is an option but that would require shipping exe with all the DLL's which I would rather avoid.

Another option would be dynamic DLL link but I rather avoid it as that is more coding for me in it...

I am bound to old BDS2006 Turbo C++ Explorer IDE and compiler.

Also is it possible to statically link DLL in relative path to EXE ?


回答1:


You are looking for #pragma comment:

#ifdef use_vendor1
#pragma comment(lib, "vendor1.lib")
#endif


来源:https://stackoverflow.com/questions/57586957/is-static-link-of-dll-using-lib-possible-from-code-only-without-add-to-proj

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