一种解决方案,用于在两个项目中构建DLL的文件相同 [英] Same file used to build DLL in two projects under one solution

查看:92
本文介绍了一种解决方案,用于在两个项目中构建DLL的文件相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定的类,希望在同一解决方案下的两个DLL项目之间共享.

当前,我将文件复制到两个项目文件夹中,并同时包含#pragma和#ifndef保护.

我想知道是否有更好的解决方案.
两种代码的唯一区别是,它们对

I''ve got this one particular class that I wish to share between two DLL projects under the same solution.

Currently, I copied the file into the two project folders and included both a #pragma once and #ifndef guard.

I was wondering if there is a better solution for it.
The only difference in the both codes is that they both use different #define for the

_declspec(dllexport)

使用不同的#define.

只是为了让您大致了解两者的外观:

.

Just to give you a rough idea what both looks like:

#pragma once
#ifndef ITEM_H

class CItem
{
public:
DLL1_API CItem(void);
DLL1_API ~CItem(void);

DLL1_API int getValue(void) const;
DLL1_API void setValue(int value);

/*
Remaining methods with the similar signatures.
*/
}





#pragma once
#ifndef ITEM_H
class CItem
{
public:
DLL2_API CItem(void);
DLL2_API ~CItem(void);
DLL2_API int getValue(void) const;
DLL2_API void setValue(int value);
/*
Remaining methods with the similar signatures.
*/
}



DLL1_API和DLL2_API当前都设置为



Both DLL1_API and DLL2_API are current set to

_declspec(dllexport)

推荐答案

使用单个源文件,您可以将其添加到每个项目中.然后为每个项目创建一个唯一的标头,您可以将其包含在dll源中,该源将包含您可以在其中使用的任何唯一定义.因此,您可以使用在相应标头中唯一定义的DLL_API来代替DLL1_APIDLL2_API.
Use a single source file which you can add to each project. Then create a unique header for each project that you can include into the dll source which will contain any unique defines that you may use in it. So instead of using DLL1_API or DLL2_API, you would use DLL_API which is uniquely defined in the appropriate header.


这篇关于一种解决方案,用于在两个项目中构建DLL的文件相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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