Visual Studio 2010 - 独立函数中的链接器错误
我的解决方案中有两个项目;一个构建静态库,另一个使用它并测试它。
在我的测试应用程序中使用此函数时,我遇到了这些链接器错误(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
timeGetTime 函数 需要 Winmm .lib 库,因此您必须在其他依赖项中指定它。
配置属性->链接器->输入->附加依赖项。
timeGetTime function requires Winmm.lib library, so you have to specify it among additional dependencies.
Configuration Properties -> Linker -> Input -> Additional Dependencies.