gpt4 book ai didi

c++ - 链接Howard Hinnant的日期/时区库时出错

转载 作者:行者123 更新时间:2023-12-02 09:48:03 30 4
gpt4 key购买 nike

我正在尝试安装Howard Hinnant's date/time zone library,以便可以制作一个在不同时区显示时间的程序。我在时区解析器中使用了霍华德的installation guide,但是鉴于我仍然不熟悉C++和一般编程,所以我认识到我可能做错了一些事情。
到目前为止,我已经从GitHub下载了源 Material ,并且我相信我已经在Visual Studio Code中成功编译了tz.cpp(同时链接到源 Material 中提供的头文件)。我没有选择自定义构建。
然后,我尝试运行以下示例程序(安装指南中提供):

#include "date/tz.h"
#include <iostream>

int
main()
{
using namespace date;
using namespace std::chrono;
auto t = make_zoned(current_zone(), system_clock::now());
std::cout << t << '\n';
}
在控制台的“问题”窗口下没有显示错误;但是,以下文本出现在终端上:

C:\Users\kburc\AppData\Local\Temp\ccqDCN6j.o: In function `main':
c:/Users/kburc/Vol 7/Documents/!Dell64docs/Programming/CPP/KJB3programs/CLClockv2/CLClockv2.cpp:26: undefined reference to `date::current_zone()'
C:\Users\kburc\AppData\Local\Temp\ccqDCN6j.o: In function `date::sys_info date::time_zone::get_info<std::chrono::duration<long long, std::ratio<1ll, 1000000000ll> > >(std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long long, std::ratio<1ll, 1000000000ll> > >) const':
c:/Users/kburc/Vol 7/Documents/!Dell64docs/Programming/CPP/KJB3programs/CLClockv2/date/tz.h:896: undefined reference to `date::time_zone::get_info_impl(std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long long, std::ratio<1ll, 1ll> > >) const'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe' -g 'c:\Users\kburc\Vol 7\Documents\!Dell64docs\Programming\CPP\KJB3programs\CLClockv2\CLClockv2.cpp' -o 'c:\Users\kburc\Vol 7\Documents\!Dell64docs\Programming\CPP\KJB3programs\CLClockv2\CLClockv2.exe'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.
[格式的道歉]
任何有关我可能做错或做不到的事情的指针将不胜感激。如有必要,乐意提供更多信息。谢谢!
编辑:这是我的 launch.json文件:
  "version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
这是我的 tasks.json文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}

最佳答案

该程序已正确编译,但未链接:

In function `main':
undefined reference to `date::current_zone()'

In function `date::sys_info date::time_zone::get_info<...>(...) const':
undefined reference to `date::time_zone::get_info_impl(...) const'

error: ld returned 1 exit status
因此,该问题与运行该程序无关,因为该程序尚不存在。
命令行是:
g++.exe -g CLClockv2.cpp -o CLClockv2.exe
其中不包含任何链接标志( -l),这意味着GCC在找不到所需符号时不会链接该库并产生您在上面看到的错误。通常,您还需要搜索路径标记( -L)。

我建议您在尝试手动配置IDE(如VS Code)之前先从命令行学习编译。另一个选项是Visual Studio,它预先配置了MSVC。

关于c++ - 链接Howard Hinnant的日期/时区库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63456633/

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