Visual Studio 2010 - 独立函数中的链接器错误

发布于 2025-01-01 21:59:39 字数 808 浏览 1 评论 0原文

我的解决方案中有两个项目;一个构建静态库,另一个使用它并测试它。

在我的测试应用程序中使用此函数时,我遇到了这些链接器错误(2019)...但我可以毫无问题地链接其他声明的内容(唯一的类)。

测试应用程序依赖于静态库,并且它也引用了它,因此它应该链接(我也只收到链接器错误)

这是为什么?我错过了什么吗?我想不出还有什么可能出问题的。

便携式时间.h

#ifndef _PORTABLE_TIME_H
#define _PORTABLE_TIME_H

#if defined _WIN32 || _WIN64
#include <WinSock2.h>
#else
#include <time.h>
#endif

#include <stdint.h>

uint64_t GetTimeSinceEpoch();

#endif

便携式时间.cpp

#include "PortableTime.h"

uint64_t GetTimeSinceEpoch()
{
    #if defined _WIN32 || _WIN64
        return (uint64_t)timeGetTime();
    #else
        struct timeval tv;
        gettimeofday(&tv, 0); 
        return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
    #endif
}

I have two projects in my solution; one which builds a static lib, another which uses it and tests it.

I've got these linkers errors (2019) when using this function in my test app... yet I can link other declared stuff (soley classes) without problem.

The test-app is dependent on the static lib, and it has reference to it as well so it should link (I only get that linker error as well)

Why is this? Am I missing something? I can't think of anything else that couldve gone wrong.

PortableTime.h

#ifndef _PORTABLE_TIME_H
#define _PORTABLE_TIME_H

#if defined _WIN32 || _WIN64
#include <WinSock2.h>
#else
#include <time.h>
#endif

#include <stdint.h>

uint64_t GetTimeSinceEpoch();

#endif

PortableTime.cpp

#include "PortableTime.h"

uint64_t GetTimeSinceEpoch()
{
    #if defined _WIN32 || _WIN64
        return (uint64_t)timeGetTime();
    #else
        struct timeval tv;
        gettimeofday(&tv, 0); 
        return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
    #endif
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2025-01-08 21:59:39

timeGetTime 函数 需要 Winmm .lib 库,因此您必须在其他依赖项中指定它。

配置属性->链接器->输入->附加依赖项。

timeGetTime function requires Winmm.lib library, so you have to specify it among additional dependencies.

Configuration Properties -> Linker -> Input -> Additional Dependencies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文