开发者

How to link to .lib produced by project in same VC++ 2010 solution

开发者 https://www.devze.com 2023-02-04 11:14 出处:网络
I have a VC++ 2010 solution with multiple project, one of which is a .lib produced by my desire to put some common code in a single place.

I have a VC++ 2010 solution with multiple project, one of which is a .lib produced by my desire to put some common code in a single place.

I'm now trying to get another of the projects, which is a normal console application, to link to this library. However, VS is complaining that it can't find the .lib even though I added it as an additional dependency.

I was kind of hoping that VS would make it easy on me since the .lib is in the same solution, albeit in a different project, but sadly, no luck.

EDIT I must be blind but I can't seem to find the 'additional paths' option Tim mentioned. I added the lib project to the project dependencies of the console project, but it still isn't working.

EDIT2 Edwin's suggestion did the trick after I actually a开发者_StackOverflow社区dded the .cpp and .h files to the .lib project. I really hate it when I miss something so obvious.


In the properties_>Common Properties->Framework & dependecies of your executable you can add projects on which your executable is dependant of. After that you only need to adjust additional include paths of C++->General to let it find your include-file.

EDIT: I have an exe-project named AppTest and a lib-project Dummy.

I added the project Dummy to Framework & dependecies of AppTest.

Then i adjusted for all configurations the include paths of AppTest to point to directory of Dummy.

Then i included dummy.h in apptest.cpp and a call to a function from dummy.lib.

Build the solution. That's all.


There are three (maybe more :-) ways of linking a library in Visual C++. You can explicitly include .lib file in the project by doing Add Existing Item and pointing to the lib file. That way you don't need to specify the path. You can add a file in Options/Linker/Input and specify path in Additional Library Directories. And finally, you can use #pragma comment( lib, "my.lib") and specify the path as before. I'm not sure, but I think the above pragma also allows to put the full path as well.


Change the "Additional paths" property(ies) in the project that is dependent on the lib.

0

精彩评论

暂无评论...
验证码 换一张
取 消