简体   繁体   English

在C ++ Visual Studio中链接静态库

[英]link static library in c++ visual studio

can someone please help me to understand the process. 有人可以帮我理解这个过程吗?

in c++ visual studio 2010 在C ++ Visual Studio 2010中

i have a visual studio solution (lets call it mysol) 我有一个Visual Studio解决方案(我们称其为mysol)

i have a project built as a static library (let's call it staticprj) staticprj needs to use a library from outside (lets call it ext.lib) 我有一个构建为静态库的项目(将其称为staticprj)staticprj需要从外部使用一个库(将其称为ext.lib)

in the body of the source code of staticprj i include outside library header file with # include extlib.h and make calls to some of its functions (let call them extfunctions()) i also include the the path to the header files location of the ext.lib. 在staticprj源代码的主体中,我使用#include extlib.h包含外部库头文件,并对其某些函数进行调用(将其称为extfunctions()),我还包括指向头文件位置的路径。 ext.lib。

the staticprj compiles okay without errors staticprj可以编译,没有错误

the mysol also has another project which is a dynamic library (dynprj) and which depends on the staticprj. mysol还有另一个项目是动态库(dynprj),它依赖于staticprj。

also in the source files of the dynprj uses functions from outside library. dynprj的源文件中也使用外部库中的函数。

i have included #include extlib.h in the source code of dynprj. 我已在dynprj的源代码中包含#include extlib.h。 i have included the path of the header files i have attached extlib.h directly to the dynprj i have also added ext.lib to the linker input (along with the path where the ext.lib resides). 我已经包含了头文件的路径,我已经将extlib.h直接附加到dynprj,我还已经将ext.lib添加到链接器输入中(以及ext.lib所在的路径)。

i still get a lnk2001 error stating that extfunctions() where not found. 我仍然收到lnk2001错误,指出未找到extfunctions()。

the whole structure (the mysol solution) compiles okay if i do not use ext.lib at all. 如果我根本不使用ext.lib,则整个结构(mysol解决方案)可以编译。

my question is how does the linking process works and what can i do to correct this linking error. 我的问题是链接过程如何工作,我该怎么做才能纠正此链接错误。

(note that without the presence of ext.lib my linking of the staticprj and dynprj is fine. my compilation works okay and my code works. i only get the linking error when i try to link another ext.lib to staticprj and dynprj and use functions from ext.lib) (请注意,在没有ext.lib的情况下,我对staticprj和dynprj的链接很好。我的编译正常,代码也行。我仅在尝试将另一个ext.lib链接到staticprj和dynprj并使用时才出现链接错误ext.lib中的函数)

thanks in advance. 提前致谢。

I'm not quite sure it will work, but try putting the .dll inside your "mysol" debug folder. 我不太确定它是否可以工作,但是请尝试将.dll放入“ mysol”调试文件夹中。 I had a similar problem couple of weeks ago when I had library compiled as .dll. 几周前,当我将库编译为.dll时,我遇到了类似的问题。 I just placed that .dll within my debug folder and worked lovely. 我只是将该.dll放在我的调试文件夹中,并且工作得非常好。

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

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