问题描述
我遇到了一个奇怪的问题,我最近一个工作的Visual Studio 2008项目。
我试图编译一个新的静态库使用函数从另一个静态库。 (让我们说Lib1是我的静态库项目,Lib2是Lib1依赖的lib文件)。
我可以构建lib1没有问题;它包括lib2的头文件并调用它的函数,并且没有问题。
问题是当我构建一个单独的测试项目有Lib1作为依赖;它不会构建,我得到链接器错误。未解决的外部是我试图在Lib1内调用来自Lib2的函数。
当我在测试项目中包含Lib2时,这一切都是固定的。 p>
这一切对我来说都是有意义的;我可以测试Lib2没有被内置到Lib1 ..
我的问题是:有办法吗?我理想地希望能够将Lib1部署为独立的lib,而不需要Lib2。 (Lib2实际上只是一个从Windows平台SDK的Lib,所以它不是一个很大的交易...)
这是不允许的,因为它会允许人们
这个问题的专业方法是什么?
谢谢!
- R
我看到两种可能性
- 记录依赖关系
- 在.h文件中使用#pragma,请求链接.lib。如果VS可以找到它,它就像在链接线上包含它一样。
#pragma comment(lib,libname.lib)
I ran into a strange problem with a Visual Studio 2008 project I was working with recently.
I am trying to compile a new static library that uses functions from another static library. (Let's say Lib1 is my static library project, and Lib2 is the lib file that Lib1 depends on).
I am able to build lib1 without issue; It includes the header files for lib2 and calls its functions, and there are no problems.
The problem is when I build a separate test project that has Lib1 as a dependency; it won't build and I get linker errors. The unresolved externals are the functions I am trying to call within Lib1 that are from Lib2.
This is all fixed when I include Lib2 in my test project as well.
This all makes sense to me of course; I can test that Lib2 is not being built into Lib1..
My question is: is there a way to do this? I would ideally like to be able to deploy Lib1 as a standalone lib without requiring Lib2. (Lib2 is actually just a Lib from the Windows Platform SDK, so it's not really a big deal...)
Is this not allowed because it would allow people to "hide" third party libraries in their own, or something?
What would be a professional approach to this problem?
Thanks!
--R
I would not advise using a librarian to take Windows' library contents into your own library -- it's likely that that's against the license.
I see two possibilities
- Documenting the dependency
- Using a #pragma in your .h file that requests the .lib to be linked against. If VS can find it, it's the same as including it on your link line.
http://msdn.microsoft.com/en-us/library/7f0aews7(VS.80).aspx
#pragma comment(lib, "libname.lib")
这篇关于C ++ - 你能建立一个静态库到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!