2014-12-07 72 views
3

我是一名業餘的VC++開發人員。在VS2010中,VC++錯誤LNK 2019與CoolProp 5.0.0

我想用VS2010終極x64的筆記本整機運行在我的學術VC++項目使用CoolProphttp://www.coolprop.org/)作爲靜態庫中贏得32應用程序。

所以我已經下載,

http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/

http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.2/static_library/ 2.CoolProp.h 1.CoolProp.lib和無論是在系統文件夾放置。

接下來,我在VS2010中創建了一個示例win32控制檯應用程序,作爲空sln。 在Properties-> C/C++ - > General中添加了CoolProp.h作爲附加包含目錄 在Properties-> Linker-> Input-> Additional Dependencies中添加了CoolProp.lib作爲其他依賴項

然後,我從http://www.coolprop.org/coolprop/HighLevelAPI.html#high-level-api

#include "CoolProp.h" 
#include <iostream> 
using namespace CoolProp; 
int main() 
{ 
// First type (slowest, due to most string processing, exposed in DLL) 
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]") << std::endl; //  Default backend is HEOS 
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]") << std::endl; 
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane[0.5]&Ethane[0.5]") << std::endl; 

std::vector<double> z(2,0.5); 
// Second type (C++ only, a bit faster) 
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane&Ethane", z) << std::endl; 
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane&Ethane", z) << std::endl; 
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane&Ethane", z) << std::endl; 

return EXIT_SUCCESS; 
} 

複製這一計劃,並試圖建立。

生成(但完全編譯)失敗,原因是

main.obj:錯誤LNK2019:無法解析的外部符號 「雙__cdecl PropsSI(焦炭,焦炭,雙,焦炭,雙,字符*)」(道具@@ YANDDNDNPAD @ Z)在函數中引用_main

有人可以幫我解決這個問題嗎? 我已經閱讀下面的計算器職位,但想不出解決請幫忙

回答

3

這是爲我工作,(VS 2010)如下:
- 通過右鍵單擊解決方案資源管理器中的頭文件文件夾 - > Add - > Exis,將'CoolPropLib.h'文件添加到您的項目中ting Item - >選擇'CoolPropLib.h'。
- 打開文件'CoolPropLib.h'和註釋行22如下(//#include「PlatformDetermination.h」)。
- 添加這兩條線(23,24):

#define CONVENTION __stdcall 
#define EXTERNC 

一個內建__stcall不與__cdecel內置
次使用的庫:
http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/Windows/32bit__stdcall_calling_convention/CoolProp.lib/download
- 你需要的dll (for __stdcall)
http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/Windows/32bit__stdcall_calling_convention/CoolProp.dll/download

-create folder in your project folder in your windows explorer(not in VS)and put 'CoolProp.lib'在裏面。

-in屬性 - >連接器 - >常規 - >附加庫目錄,添加$(PROJECTDIR)\ LIB
-the代碼我測試的是:

#include "stdafx.h" 
#include <iostream> 
#include <vector> 
#include "CoolPropLib.h" 
using namespace std; 


int _tmain(int argc, _TCHAR* argv[]) 
{ 

    // First type (slowest, due to most string processing, exposed in DLL) 
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]") << std::endl; //  Default backend is HEOS 
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]") << std::endl; 
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane[0.5]&Ethane[0.5]") << std::endl; 

    return 0; 
} 

- 如果你有問題,我可以上傳項目給你。


編輯1:

  • 我的意思是 'CoolPropLib.h' 而不是 'CoolProp.h',我糾正;在你的問題中,你將它命名爲'CoolProp.h'。
  • 正如你在評論中提到的;您可以在屬性 - > c/C++ - >高級中將調用約定更改爲_stdcall。
+0

它爲我工作。我包含了CoolPropLib.h,並在Properties-> c/C++ - > Advanced中將調用約定更改爲_stdcall。非常感謝你 – Selva 2014-12-07 11:17:31

+0

@SelvaKumar:不客氣。我修改了答案。 – houssam 2014-12-07 11:30:30

+0

正如我在我的回覆中提到的那樣,使用DLL並不是最佳選擇,因爲您可以使用的功能有限。按照我的描述,最好自己構建靜態庫。 – ibell 2014-12-07 15:27:44

3

我是CoolProp的主要開發人員之一。謝謝@houssam的回覆。進入DLL(共享庫)路徑的問題是您無法訪問許多有用的低級函數,而如果您與靜態庫鏈接,則仍然可以訪問所有低級代碼

更好的計劃是自己構建靜態庫,因爲要求用於構建靜態庫的編譯器與用於編譯項目的編譯器完全相同。爲了做到這一點,你可以在這裏遵循的方向:http://www.coolprop.dreamhosters.com:8010/sphinx/coolprop/wrappers/StaticLibrary/index.html#static-library,基本上你需要做的

# Check out the sources for CoolProp 
git clone https://github.com/CoolProp/CoolProp --recursive 
# Move into the folder you just created 
cd CoolProp 
# Make a build folder 
mkdir build && cd build 
# Build the makefile using CMake 
cmake .. -DCOOLPROP_STATIC_LIBRARY=ON -G "Visual Studio 10 2010" 
# Make the static library 
cmake --build . 

然後,您需要在靜態鏈接庫由@houssam描述。您的代碼不需要其他更改。

未來,[email protected]郵件列表或https://github.com/CoolProp/CoolProp/issues是提問的好地方。

+0

謝謝伊恩貝爾:) – Selva 2014-12-07 15:55:15

+0

謝謝貝爾。 – houssam 2014-12-07 17:42:41