2012-02-02 125 views
5

我的解決方案中有兩個項目;一個構建靜態庫,另一個使用它並對其進行測試。Visual Studio 2010 - 獨立功能中的鏈接器錯誤

在我的測試應用程序中使用此函數時,我得到了這些鏈接器錯誤(2019)...但我可以沒有問題地鏈接其他聲明的東西(soley類)。

的測試應用程序依賴於靜態庫,它有參考它,以及因此它應該鏈接(我只能得到連接錯誤以及)

這是爲什麼?我錯過了什麼嗎?我想不出任何可能出錯的事情。

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

你會得到什麼錯誤? – 2012-02-02 19:49:54

+0

'錯誤LNK2001:無法解析的外部符號__imp__timeGetTime @'我猜 – LihO 2012-02-02 19:54:59

回答

16

timeGetTime function需要WINMM.LIB庫,讓你有額外的依賴關係中指定。

配置屬性 - >鏈接器 - >輸入 - >其他依賴項。

+0

啊哈!釘牢它,謝謝! – KaiserJohaan 2012-02-02 19:56:06

+0

不客氣;) – LihO 2012-02-02 19:58:03