简体   繁体   English

.lib链接其他.lib

[英].lib linking other .libs

Currently my visual studio is basically generating Engine.dll and Game.exe 目前,我的视觉工作室基本上是在生成Engine.dll和Game.exe

Engine.dll links to some other basic libraries like: d3dx9d.lib ComCtl32.lib WinMM.lib WSock32.lib etc. Engine.dll链接到其他一些基本库,例如:d3dx9d.lib ComCtl32.lib WinMM.lib WSock32.lib等。

I also wanted to try to create an Engine.lib, but I get some really nice warnings now: Symbol x has been defined already. 我也想尝试创建Engine.lib,但是现在我得到一些非常好的警告:符号x已经被定义。 These libraries define the same symbols. 这些库定义相同的符号。

So I read somewhere that I must force my user (Game.exe) to link to the libs instead. 因此,我读到某个地方,我必须强制我的用户(Game.exe)链接到这些库。 But this is just really inconvenient I think, especially if I have many games and I decide to add another library to my engine. 但这确实给我带来了不便,特别是如果我有很多游戏并且决定将另一个库添加到引擎中时。 It's just maintenance for something so simple. 仅仅是维护,就这么简单。

Should I stick to the .dll, or is there some way to fix this beauty up? 我应该坚持使用.dll,还是有某种方法可以修复此问题?

Thanks a lot, 非常感谢,

Antoon 安东

You need to make up your mind whether the want the DLL or the static link library. 您需要下定决心是否需要DLL或静态链接库。 Advantage of a DLL is that the build times can be quicker if you make local changes. DLL的优点是,如果您进行本地更改,则构建时间会更快。 Advantage of a .lib is that you'll end up with only one deployable file. .lib的优点是,最终只能得到一个可部署文件。

Getting it linked (either the static .lib or the dll's import .lib) is otherwise automatic. 否则将其自动链接(静态.lib或dll的import .lib)。 You want to make sure that the library is built first, can't link the .exe without it. 您要确保首先构建该库,否则就无法链接.exe。 Right-click the exe project in the Solution Explorer window, Project Dependencies, tick the library project. 右键单击“解决方案资源管理器”窗口中的exe项目,在“项目依赖项”中,选中库项目。 That automatically adds the .lib to the exe project's additional dependencies. 这会自动将.lib添加到exe项目的其他依赖项中。

Using #pragma comment(lib, "engine.lib") in the engine's header file is another way. 在引擎的头文件中使用#pragma comment(lib,“ engine.lib”)是另一种方法。 Repeat for other dependencies like the OS import libraries. 对其他依赖项(如OS导入库)重复上述步骤。 Getting the library path right is a // todo item. 确保正确的库路径是// //待办事项。

Did you create a different namespace to avoid naming clashes? 您是否创建了其他名称空间以避免命名冲突?

EDIT -- seems like there is some confusion as to what you're asking, because you are asking a couple of questions. 编辑-似乎对您要问的内容有些困惑,因为您要问几个问题。

To me, it sounds like you want to take a stab at implementing your own Engine class. 对我来说,听起来您想刺痛实现自己的Engine类。 However, you've got naming issues. 但是,您遇到了命名问题。 I am treating this as more of an architectural question now. 我现在将其更多地视为体系结构问题。 If you write your Game to an interface, then the problem goes away. 如果您将游戏编写到界面上,那么问题就消失了。 For example, if your Engine is using different algorithms, then if you had written an EngineInterface that the current Engine and YourEngine implemented, then you could easily use Strategy to flip between the different implementations on the fly. 例如,如果您的引擎使用不同的算法,那么如果您编写了当前引擎和YourEngine实现的EngineInterface,则可以轻松地使用Strategy在运行中的不同实现之间进行切换。 This is nice because you'll be able to see the differences in-game if you wire the preferences into the app. 很好,因为如果您将首选项连接到应用程序中,便可以看到游戏中的差异。

If the symbols are not supposed to be the same, use diferent names or control how they are exposed. 如果符号不相同,请使用不同的名称或控制其显示方式。 Another option is the usage of namespaces to avoid naming conflicts. 另一个选择是使用名称空间来避免命名冲突。

If the symbols are supposed to be the same thing, you need to define those only once in one of the libs. 如果这些符号应该是同一对象,则只需在一个库中定义一次即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM