添加__declspec(dllexport)会中断我的静态库的链接 [英] Adding __declspec(dllexport) breaks linkage of my static library

查看:99
本文介绍了添加__declspec(dllexport)会中断我的静态库的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个C ++项目的VS 2010解决方案。一个生成一个应用程序(.exe)。另一个产生静态库(.lib)。该应用程序使用静态库。解决方案构建,应用程序按预期执行。该课程声明如下。



class MyClass

{

public:

static void MyFunc(void);

};



如果类声明更改如下:



class __ declspec(dllexport) MyClass

{

public:

static void MyFunc(void);

};



应用程序(.exe)构建失败,并显示以下错误消息。



.obj:错误LNK2019:未解析的外部符号__declspec(dllimport)public:static



为什么?



我尝试了什么:



在网上搜索并没有找到解释

I have a VS 2010 solution with two C++ projects. One produces an application (.exe). The other produces a static library (.lib). The application uses the static library. The solution builds and the application executes as expected. The class is declared as follows.

class MyClass
{
public:
static void MyFunc(void);
};

if the class declaration is changed as follows:

class __declspec(dllexport) MyClass
{
public:
static void MyFunc(void);
};

The application (.exe) build fails with the following error message.

.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static

Why ?

What I have tried:

searched the web and did not find an explanation

推荐答案

您正在创建静态库,而不是dll,因此不要使用 __declspec(dllexport) )。您只需确保为静态库设置项目构建,并确保您的应用程序包含使用此项目生成的.lib文件。
You are creating a static library, not a dll, so you do not use __declspec(dllexport). You just need to ensure that your project build is set for a static library, and that your application includes the .lib file that this project produces.


这篇关于添加__declspec(dllexport)会中断我的静态库的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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