【发布时间】:2020-09-13 00:33:58
【问题描述】:
我在 Windows 10 pro 上使用 c++ builder 10.2 和 clang 编译器。谁能告诉我为什么这不能编译?
// crt_tzset.cpp
// This program uses _tzset to set the global variables
// named _daylight, _timezone, and _tzname. Since TZ is
// not being explicitly set, it uses the system time.
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
_tzset();
int daylight;
_get_daylight( &daylight );
printf( "_daylight = %d\n", daylight );
long timezone;
_get_timezone( &timezone );
printf( "_timezone = %ld\n", timezone );
size_t s;
char tzname[100];
_get_tzname( &s, tzname, sizeof(tzname), 0 );
printf( "_tzname[0] = %s\n", tzname );
exit( 0 );
}
我收到 3 个与 _get_daylight、_get_timezone 和 _get_tzname 相关的“未解决的外部”错误。
【问题讨论】:
-
Unresolved external 表示链接器错误,而不是编译错误 - 对吗?如果您查找它,您会发现 __get_daylight 包含在 Universal C 运行时中。这意味着您可能不会链接到它。现在它取决于您的项目/IDE 如何进行链接。
-
我不怀疑 Wolfgang 的话,但我在 IDE 的项目管理器中看不到这样的选项。我以前从未遇到过这种情况,也不知道这个 C 运行时库存在于哪里。希望我不必下载 Visual ******* C。
-
如果您查看
_tzset()及其同伴的文档,至少应该有两件事:要包含哪个 头文件 以使编译器知道它们,以及要链接到哪个库。 -- 你的项目经理(我不知道 c++builder)当然有一些方法可以让你定义要链接的库。您需要寻找“库”,而不是“tzset”。 -
@the busybee 我一直在寻找但只能找到#nclude
。 -
读了stackoverflow.com/questions/2766233/…之后我一点也不聪明。
标签: c++ c windows c++builder