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

时间:2012-02-02 19:48:03

标签: c++ visual-studio-2010 visual-c++ linker static-libraries

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

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

test-app依赖于静态lib,它也引用了它,所以它应该链接(我只得到那个链接器错误)

这是为什么?我错过了什么吗?我想不出任何可能出错的事情。

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
}

1 个答案:

答案 0 :(得分:17)

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

配置属性 - &gt;链接器 - &gt;输入 - &gt;附加依赖。