【问题标题】:Visual Studio 2010 - linker errors in stand-alone functionsVisual Studio 2010 - 独立函数中的链接器错误
【发布时间】:2012-02-25 11:55:30
【问题描述】:

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

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

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

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

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
}

【问题讨论】:

  • error LNK2001: unresolved external symbol __imp__timeGetTime@ 我猜

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-10-17
    • 2011-11-05
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多