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

Kai*_*aan 6 c++ linker static-libraries visual-studio-2010 visual-c++

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

在我的测试应用程序中使用此函数时,我有这些链接器错误(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
Run Code Online (Sandbox Code Playgroud)

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
}
Run Code Online (Sandbox Code Playgroud)

Lih*_*ihO 17

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

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