.lib 链接其他 .lib
目前我的视觉工作室基本上生成 Engine.dll 和 Game.exe
Engine.dll 链接到其他一些基本库,例如: d3dx9d.lib ComCtl32.lib WinMM库 WSock32.lib 。
我还想尝试创建一个 Engine.lib,但现在我收到一些非常好的警告:符号 x 已被定义 这些库定义了相同的符号。
所以我在某处读到我必须强制我的用户(Game.exe)链接到库。但我认为这真的很不方便,特别是如果我有很多游戏并且我决定向我的引擎添加另一个库。只是维护这么简单的东西。
我应该坚持使用 .dll,还是有某种方法可以修复这个问题?
非常感谢,
安东
Currently my visual studio is basically generating Engine.dll and Game.exe
Engine.dll links to some other basic libraries like:
d3dx9d.lib
ComCtl32.lib
WinMM.lib
WSock32.lib
etc.
I also wanted to try to create an Engine.lib, but I get some really nice warnings now: Symbol x has been defined already. These libraries define the same symbols.
So I read somewhere that I must force my user (Game.exe) to link to the libs instead. 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?
Thanks a lot,
Antoon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要决定是否需要 DLL 还是静态链接库。 DLL 的优点是,如果进行本地更改,构建时间会更快。 .lib 的优点是您最终只会得到一个可部署文件。
否则,链接它(静态 .lib 或 dll 的导入 .lib)是自动的。您要确保首先构建该库,没有它就无法链接 .exe。右键单击“解决方案资源管理器”窗口中的 exe 项目,“项目依赖项”,勾选库项目。这会自动将 .lib 添加到 exe 项目的附加依赖项中。
在引擎的头文件中使用#pragma comment(lib, "engine.lib") 是另一种方法。对其他依赖项(例如操作系统导入库)重复此操作。 // 获取正确的库路径是一个待办事项。
You need to make up your mind whether the want the DLL or the static link library. Advantage of a DLL is that the build times can be quicker if you make local changes. Advantage of a .lib is that you'll end up with only one deployable file.
Getting it linked (either the static .lib or the dll's import .lib) is otherwise automatic. You want to make sure that the library is built first, can't link the .exe without it. Right-click the exe project in the Solution Explorer window, Project Dependencies, tick the library project. That automatically adds the .lib to the exe project's additional dependencies.
Using #pragma comment(lib, "engine.lib") in the engine's header file is another way. Repeat for other dependencies like the OS import libraries. Getting the library path right is a // todo item.
您是否创建了不同的命名空间以避免命名冲突?
编辑 - 似乎您所问的内容有些混乱,因为您问了几个问题。
对我来说,听起来您想尝试实现您自己的 Engine 类。但是,您遇到命名问题。我现在更多地将其视为一个架构问题。如果您将游戏写入接口,那么问题就会消失。例如,如果您的引擎使用不同的算法,那么如果您编写了当前引擎和您的引擎实现的 EngineInterface,那么您可以轻松地使用策略在不同的实现之间动态切换。这很好,因为如果您将首选项连接到应用程序中,您将能够看到游戏中的差异。
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. 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. 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.