2016-02-25 52 views
-4

我的問題很奇怪。 在visual c++我想用fuzzylite library創建一個DLL。 當我創建我的類,它的形式(myclass.hmyclass.cpp)使用庫項目編譯罰款。 和fuzzylite頭被包含在myclass.hfuzzylite的Visual C++奇怪的行爲

,但如果我在myclass.cpp或增加(#include 「fl/Headers.h」)頂部添加(#include 「stdafx.h」)到stdafx.h我得到100 errors。 有什麼想法?

更新1:

//FuzzyCalc.h 
#pragma once 
#define __DLL_EXPORTS 
#ifdef __DLL_EXPORTS 
#define __DLL_API __declspec(dllexport) 
#else 
#define __DLL_API __declspec(dllimport) 
#endif 
class __DLL_API FuzzyCalc 
    { 
      public: 
      FuzzyCalc(); 
      ~FuzzyCalc(); 
      double getOutputValue(double val1, double val2); 
    }; 


//FuzzyCalc.cpp 
#include "fl/Headers.h" 
#include "FuzzyCalc.h" 
FuzzyCalc::FuzzyCalc() 
    { 
    } 
FuzzyCalc::~FuzzyCalc() 
    { 
    } 
double FuzzyCalc::getOutputValue(double val1, double val2) 
    { 
     return 0.0; 
    } 

直到此時每一件事情是正常的程序編譯和構建成功的,但如果我補充一點:

#include "stdafx.h" 
#include "fl/Headers.h" 
#include "FuzzyCalc.h" 
FuzzyCalc::FuzzyCalc() 
    { 
    } 
FuzzyCalc::~FuzzyCalc() 
    { 
    } 
double FuzzyCalc::getOutputValue(double val1, double val2) 
    { 
    return 0.0; 
    } 

我得到一些錯誤,如thease:

Error C2146 syntax error: missing ')' before identifier 'a' fuzzyind  fuzzylite\fl\Operation.h 41 
Error C2365 'T': redefinition; previous definition was 'template parameter' fuzzyind \fuzzylite\fl\Operation.h 41 
Error C2061 syntax error: identifier 'a' fuzzyind \fuzzylite\fl\Operation.h 41 
Error C2059 syntax error: ')' fuzzyind \fuzzylite\fl\Operation.h 41 
Error C2334 unexpected token(s) preceding ':'; skipping apparent function body fuzzyind \fuzzylite\fl\Operation.h 41 
Error C2988 unrecognizable template declaration/definition fuzzyind \fuzzylite\fl\term\Term.h 37 
Error C2143 syntax error: missing ';' before 'namespace' fuzzyind \fuzzylite\fl\term\Term.h 37 
Error C1004 unexpected end-of-file found fuzzyind fuzzyind\dllmain.cpp 19 

只是添加一行,每事情出錯了。

+0

建立一個樣品是主要的,你需要的標題。然後逐行添加所需的功能,直到停止編譯。如果這不會使問題變得明顯,請編輯您的問題以添加您的代碼。這就是我們所說的MCVE,但您已經知道,因爲您已閱讀網站幫助以及有關如何編寫好問題的部分。 – user4581301

回答

0

我解決了問題。 的問題是因爲在文件stdafx.h中添加了windows.h。該文件中有 存在與fuzzylite庫衝突的宏定義,例如min和max。 通過添加的#define NOMINMAX在此之前,包括解決問題的正確的方法是:

// stdafx.h : include file for standard system include files, 
// or project specific include files that are used frequently, but 
// are changed infrequently 

#pragma once 

#include "targetver.h" 

#define WIN32_LEAN_AND_MEAN    // Exclude rarely-used stuff from  
#define NOMINMAX 
#include <windows.h> 
#include "fl/Headers.h" 

希望這可以幫助別人。