Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
947 views
in Technique[技术] by (71.8m points)

visual studio 2010 - VS2010: Link in a single library statically

Situation:

I'm building a library with VS2010, and it has a dependency on LibraryA. I am only using one of many features that LibraryA offers, so I want to link it in statically.

Everything I'm reading about this tells me to set the whole project to link statically against MFC, which is something I don't want to do. I'm just fine with my library dynamically linking against windows DLLs; I just want to statically link against LibraryA only.

Fooling around with the options windows, I don't seem to see such an option. Is it really all or nothing?

Thanks, -Ben

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Answering my own question here:

All you need to do to statically link a library in VS is:

1) Add the .lib file to the list found in properties -> linker -> input : Additional Dependencies.

2) Add the directory that the .lib file is located at to the properties -> linker -> general : Additional Library Directories.

If the .lib file is a statically linked library, then that is all you have to do.

The main reason I was confused was that a .lib file could also be a companion file alongside a dll, and not a static library itself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...