gpt4 book ai didi

c++ - 为什么我不能使用 Visual Studio 2013 调用 CTime::GetAsDBTIMESTAMP?

转载 作者:行者123 更新时间:2023-11-28 02:46:02 25 4
gpt4 key购买 nike

我在 Visual Studio 2012 中创建了一个新的 Visual C++ Win32 项目 - 只是一个带有预编译 header 的控制台应用程序。我为 atltime.h 添加了一个 include 并向 _tmain 添加了三行代码:

// timeapp2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "atltime.h"

int _tmain(int argc, _TCHAR* argv[])
{
CTime c = CTime::GetCurrentTime();
DBTIMESTAMP t;
c.GetAsDBTIMESTAMP(t);
return 0;
}

我编译它。它编译得很好。

我在 Visual Studio 2013 中尝试同样的操作。我收到以下错误:

Error   1   error LNK2019: unresolved external symbol "public: bool __thiscall ATL::CTime::GetAsDBTIMESTAMP(struct tagDBTIMESTAMP &)const " (?GetAsDBTIMESTAMP@CTime@ATL@@QBE_NAAUtagDBTIMESTAMP@@@Z) referenced in function _wmain c:\tmp\timeapp\timeapp2\timeapp2.obj    timeapp2

Error 2 error LNK1120: 1 unresolved externals c:\tmp\timeapp\Debug\timeapp2.exe 1 1 timeapp2

这是从 MSDN 订阅者下载中获取的 Visual Studio Premium 2013 Update 2 的全新安装。我在两台不同的机器上尝试过同样的事情,一台运行 Windows 8.1 x64,另一台运行 Windows Server 2012 R2。两者都无法使用 Visual Studio 2013 进行编译。

我做错了什么?

最佳答案

您缺少 ATL 库。

(以下是针对 VS2008 的,对我的旧环境感到抱歉 - 但我希望您可以在类似的位置找到这些选项):

创建项目时,选择“添加通用ATL header ”

或者在 Project Configuratrion/General 下,启用“使用 ATL”(静态或动态,动态提供较小的可执行文件,但您需要 list 中的相应 ATL 运行时并安装在目标上)


[编辑]
您可以尝试将相应的 ATL 库手动添加到链接器(atl{s}{d}.lib,使用 's' 表示静态,'d' 表示调试版本)。还没有在 VS2013 下完成 ATL,所以这些只是“有根据的猜测”。


如果只是这一次调用,您也可以只使用GetSystemTime,然后填充DBTIMESTAMP 结构。

(无耻的插件:或者,如果您来自 CTime,它只是 _time64_t see here 的包装器,用于转换时间_t --> SYSTEMTIME)

关于c++ - 为什么我不能使用 Visual Studio 2013 调用 CTime::GetAsDBTIMESTAMP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24410459/

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