gpt4 book ai didi

c++ - 在项目之间共享源文件

转载 作者:行者123 更新时间:2023-11-30 01:51:56 24 4
gpt4 key购买 nike

我有一个项目 A,其中包含带有类定义和实现的源文件 MyClass.hMyClass.cppMyClass 正在使用 CString

现在我决定创建新项目B,它是用于测试MyClass 目的的简单控制台应用程序。在解决方案资源管理器中,我从 A 项目位置向我的项目添加了 MyClass header 和 cpp 文件。直到这一刻我才知道我必须使用MFC才能使用CString。我尝试构建项目并收到错误,据我所知要求使用 MFC。

#error :  Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

为了了解发生了什么,我决定删除 MyClass 并在同样使用 CString 的项目 B 中创建简单的 MyCLass2。在构建 B 之后,我得到了类似

的错误
Error   22  error C2061: syntax error : identifier 'CString'    

包含在 MyClassMyClass2 中的是相同的。

为什么在 MyClass 案例中我被要求添加 MFC 库?我想在这种情况下编译器知道什么是 CString。它怎么知道的?

当系统不理解什么是 CString 时,我期望得到与使用 MyClass2 编译相同的结果。

最佳答案

If using in an ATL application:

CString, CStringA, and CStringW are exported from the MFC DLL (MFC90.DLL), never from user DLLs. This is done to prevent CStringT from being multiply defined.

来源:http://msdn.microsoft.com/en-us/library/5bzxfsea.aspx

如果您想在不链接到 MFC 的情况下使用,那么您可以使用以下类:CAtlString、CAtlStringA 和 CAtlStringW。

关于c++ - 在项目之间共享源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25445458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com