在Visual Studio 2010上将静态库链接到我的项目 [英] Linking a static library to my project on Visual Studio 2010

查看:118
本文介绍了在Visual Studio 2010上将静态库链接到我的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将oscpack(http://code.google.com/p/oscpack/)用作我的项目的静态库,但当我尝试将其添加到示例时,会出现链接错误,例如:

I want to use oscpack (http://code.google.com/p/oscpack/) as a static library for my project but when I try to add it to an example, I get linking errors, for example:


1> oscpackd.lib(UdpSocket.obj):error LNK2019:unresolved external symbol _ imp _socket @ 12在函数public:__thiscall中引用的函数UdpSocket :: Implementation :: Implementation(void)(?? 0Implementation @ UdpSocket @@ QAE @ XZ)

1>oscpackd.lib(UdpSocket.obj) : error LNK2019: unresolved external symbol _imp_socket@12 referenced in function "public: __thiscall UdpSocket::Implementation::Implementation(void)" (??0Implementation@UdpSocket@@QAE@XZ)

1> oscpackd。 lib(UdpSocket.obj):错误LNK2019:未解析的外部符号_ imp _closesocket @ 4在函数public:__thiscall UdpSocket :: Implementation ::〜Implementation(void)中引用(?? 1Implementation @ UdpSocket @@ QAE @ XZ)

1>oscpackd.lib(UdpSocket.obj) : error LNK2019: unresolved external symbol _imp_closesocket@4 referenced in function "public: __thiscall UdpSocket::Implementation::~Implementation(void)" (??1Implementation@UdpSocket@@QAE@XZ)

...

我的项目,因此您可以更好地了解我的文件夹结构:

I have uploaded my projects so you can get a better idea on how is my folder structure:

http://d.pr/IABh

基本上,我创建了一个用于构建oscpack.lib的解决方案,在项目中我添加了相应的.h和.cpp文件中。
然后在示例解决方案上,我添加了我的main.cpp然后我包括(属性> C / C ++>其他包括目录)的oscpack库的文件夹,然后在链接器选项卡上我添加了文件夹位置

Basically, I created a solution for building the oscpack.lib, in the project I added the corresponding .h and .cpp files. Then on the example solution, I added my main.cpp and then I included (properties>C/C++>Additional Include Directories) the folder of the oscpack library, then on the Linker tab I added the folder location of the libs and the name of the libs.

推荐答案

感谢您的帮助

VS项目模板负责告诉链接器链接最常见的Windows库。像kernel32.lib,你不能写没有它的Windows程序。但不是winsock,并不是每个程序都想创建一个套接字。必须明确添加。

The VS project templates take care of telling the linker to link the most common Windows libraries. Like kernel32.lib, you cannot write a Windows program without it. But not winsock, not every program is going to want to create a socket. That has to be added explicitly.

您可以从MSDN文章中找到这些依赖关系,比如closesocket()。它在文章的底部。 标头位会告诉您需要包含哪些内容,您就是这样。 位告诉您需要告诉链接器链接。不是自动的,你必须自己照顾。

You can find these kind of dependencies from the MSDN article about, say, closesocket(). It is at the bottom of the article. The Header bit tells you what you need to #include, you got that right. The Library bit tells you what you need to tell the linker to link. Not automatic, you have to take care of it yourself.

这篇关于在Visual Studio 2010上将静态库链接到我的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆