2010-04-12 43 views
0

我使用Microsoft Visual Studio 2008爲C++編譯了NTL inifite精度整數算術庫。我在this site上使用Visual Studio接口而不是從命令提示符。其實我寧願從命令提示符下執行它,但我不知道如何執行。爲Windows編譯和使用NTL C++庫

無論如何,我已經編譯了庫,現在我想從命令提示符下使用庫編譯程序。我試圖編譯程序,已經在Linux系統中,在那裏我有以下

c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include mpqs.cpp main.cpp -o main -L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl -L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm 

沒關係了GMP的東西編譯上測試,我沒有在Windows所安裝。這純粹是可選的事情,將使NTL運行更快。無論如何,這在Linux上正常工作。現在在Windows上我寫了下面的

cl /EHsc /I D:\Downloads\WinNTL-5_5_2\include mpqs.cpp main.cpp /link /LIBPATH:"D:\Documents\Visual Studio 2008\Projects\ntl\Debug" 

但是這會導致以下錯誤:

mpqs.cpp 
mpqs.cpp(38) : error C2039: 'find_smooth_vals' : is not a member of 'QS' 
     d:\desktop\qs\mpqs.h(12) : see declaration of 'QS' 
mpqs.cpp(41) : error C2065: 'M' : undeclared identifier 
mpqs.cpp(41) : error C2065: 'n' : undeclared identifier 
mpqs.cpp(42) : error C2065: 'sieve_table' : undeclared identifier 
mpqs.cpp(42) : error C2228: left of '.size' must have class/struct/union 
     type is ''unknown-type'' 
mpqs.cpp(43) : error C2065: 'sieve_table' : undeclared identifier 
mpqs.cpp(44) : error C2065: 'qx_table' : undeclared identifier 
mpqs.cpp(44) : error C3861: 'test_smoothness': identifier not found 
mpqs.cpp(45) : error C2065: 'smooth_indices' : undeclared identifier 
mpqs.cpp(45) : error C2228: left of '.push_back' must have class/struct/union 
     type is ''unknown-type'' 
main.cpp 
Generating Code... 

它是那樣的話,我的mpqs.h文件不包含在編譯過程?另外我不明白爲什麼它抱怨.push_back()的矢量類型?

非常感謝幫助!

+0

NTL嚴重過時,請使用[MPIR](http://mpir.org/)代替 – bobobobo 2011-10-11 23:57:52

回答

0

mpqs.h肯定會包含在輸出中,要求您參考它。

看來MPQS.h似乎沒有包含在NTL庫中......你寫了嗎?如果是的話,你可以發佈代碼嗎?

此外,你不應該在你的構建中包含庫文件?

編輯:沒有函數find_smooth_values,那麼爲什麼你應該期望MSVC找到它?我不確定爲什麼在GCC下編譯但顯然不存在。我猜測其他錯誤是由於這一個造成的。錯誤告訴你的東西。你應該聽他們。

push_back失敗,因爲它不知道你嘗試push_back的類型是什麼。這又可能是由於find_smooth_values不存在而導致的。嘗試將函數原型添加到QS類中。這可以很好地解決你所有的問題。

至於圖書館,它將不會得到使用該庫,直到編譯成功。所以不要爲此擔心。進入並修復MSVC報告的錯誤!

+0

是的,我寫了mpqs.h,它與mpqs.cpp和main.cpp位於同一目錄文件夾中這是一個使用類mpqs的可運行文件)。我嘗試在我的build命令的末尾添加「ntl.lib」,但它給了我相同的錯誤。我不確定我是否可以在評論中發佈代碼,但我將其粘貼到此處:http://pastebin.com/mLN5K40E – 2010-04-12 11:38:34

+0

感謝Goz! 2010-04-13 11:45:58