2017-08-03 92 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

相關問題