2017-08-03 94 views
0

我试图在Visual Studio中创建一个简单的C++项目2015年错误解析外部符号

Peakdetector.h

#ifndef PEAKDETECTOR_H 
#define PEAKDETECTOR_H 
//------------------------------------------------------- 
#ifdef DLL_BUILD_SETUP 
    #ifdef Q_OS_LINUX 
     #define DLLSPEC __attribute__((visibility("default"))) 
    #else 
     #define DLLSPEC __declspec(dllexport) 
    #endif 
#else 
    #ifdef Q_OS_LINUX 
     #define DLLSPEC 
    #else 
     #define DLLSPEC __declspec(dllimport) 
    #endif 
#endif 
    namespace vpg { 
    #ifndef VPG_BUILD_FROM_SOURCE 
    class DLLSPEC PeakDetector 
    #else 
    class PeakDetector 
    #endif 
     private: 
      int __seek(int d) const; 
      double __getDuration(int start, int stop); 
    } 

    inline int PeakDetector::__seek(int d) const 
    { 
    return ((m_intervalslength + (d % m_intervalslength)) % m_intervalslength); 
    } 

#endif 

PeakDetector.cpp

#include "stdafx.h" 
#include "peakdetector.h" 

    namespace vpg { 
    void PeakDetector::__updateInterval(double _duration) 
    { 
     //other stuff 

    } 
} 

当我尝试运行此应用程序我得到错误

LNK2019函数“private:void”中引用的无法解析的外部符号“__declspec(dllimport)private:int __cdecl vpg :: PeakDetector :: __ seek(int)const”(__imp _?_ seek @ PeakDetector @ vpg @@ AEBAHH @ Z) __cdecl VPG :: PeakDetector :: __ updateInterval(双)”(?__ updateInterval @ PeakDetector @ VPG @@ AEAAXN @ Z)MyCustomProject

我是新来这一点,想不通为什么我有这个error.I已只是复制粘贴这个代码从一个例子。请让我知道如果我缺少任何代码。另外我没有任何.lib文件。

+2

C++区分大小写。 –

+0

@NeilButterworth非常感谢你。就像我说的,我对此很新。我应该在这里改变什么?它是'class peakDetector {'?? – Rohit

+0

@Rohit类名“class PeakDetector” – Naidu

回答

2

您必须在Visual Studio中添加DLL_BUILD_SETUP定义。

为了做到这一点,哟必须去

Project Settings -> C/C++ -> Preprocessor -> Preprocessor definitions 

和定义添加到列表中。

在编译导出符号的库(本例中为类)和使用该库的项目中的__declspec(dllimport)时,必须使用规范__declspec(dllexport)

我从源代码中看到,您提供的附加定义VPG_BUILD_FROM_SOURCE禁用导出以便使用静态/内联链接,您可以尝试添加该定义。

+0

Thankyou工作 – Rohit

+0

我没有在帖子中发现任何拼写错误,但考虑到我在评论中读到的内容:是否有人更新了原始问题并删除了错别字? –

+0

@JuanRamirez如果你看编辑线,你可以看到帖子的历史。 [编辑16分钟前](https:// stackoverflow。COM /职位/ 45493544 /修订版)。原帖是camelCase,但更新为PascalCase。 – Thebluefish

相关问题