跳轉到內容

SPM/編譯 gnumex mex 檔案

來自華夏公益教科書,開放的書籍,用於開放的世界
< SPM

如果提供的 shortpath.dlluigetpath.dll 不起作用,可能是因為它們是針對舊版本的 Matlab 編譯的。但原始碼包含在內,因此您可以使用當前版本的 Matlab 重新編譯,首先設定 mex,在 Matlab 提示符下鍵入

   >> mex -setup

Matlab 會說

   Please choose your compiler for building external interface (MEX) files: 

   Would you like mex to locate installed compilers [y]/n? 

所以選擇'y',Matlab 然後列出可用的編譯器

   Select a compiler: 
   [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2007a\sys\lcc 
   [2] Microsoft Visual C++ .NET 2003 in C:\Program Files\Microsoft Visual Studio .NET 2003
   [0] None
   Compiler: 

注意:我安裝了 Visual Studio 2003,這就是為什麼我有 2 個選項。如果你安裝了 Borland,你也將在上面看到它。

與 MinGW 和 Cygwin (gcc) 一起使用的編譯器未列出,因為它沒有像 Matlab、Visual Studio 等那樣在 Windows 中註冊。這就是使用 Gnumex 來設定 gcc 選項的原因。選擇 [1] 使用與 Matlab 一起提供的編譯器。

現在將目錄更改為 c:\gnumex\src 並編譯 .c 檔案

   mex shortpath.c -output shortpath.dll
   mex uigetpath.c -output uigetpath.dll

編譯 uigetpath.c 時,您可能會遇到這樣的錯誤

c:\docume~1\beau\locals~1\temp\mex_c58982ee-6281-4e1f-e2ac-723987a01052\uigetpath.obj .text: undefined reference to '_SHGetMalloc@4' 
c:\docume~1\beau\locals~1\temp\mex_c58982ee-6281-4e1f-e2ac-723987a01052\uigetpath.obj .text: undefined reference to '_SHBrowseForFolder@4' 
c:\docume~1\beau\locals~1\temp\mex_c58982ee-6281-4e1f-e2ac-723987a01052\uigetpath.obj .text: undefined reference to '_SHGetPathFromIDList@8' 

  C:\PROGRA~1\MATLAB\R2007A\BIN\MEX.PL: Error: Link of 'uigetpath.dll' failed. 

??? Error using ==> mex at 206
Unable to complete successfully.

但幸運的是,uigetpath.dll 對於 Gnumex 的功能並不重要。我相信它只在按下“瀏覽”按鈕時使用,向用戶展示可瀏覽的資料夾樹。為了避免使用它,只需在 Gnumex 的文字框中鍵入路徑。當我使用 Visual Studio 編譯器時,此錯誤不會出現,很可能是因為它的 mexopts.bat 檔案已設定為正確連結到 Microsoft 庫以用於列出的 _SH 函式。

現在您有了有效的 shortpath.dll(以及可能還有 uigetpath.dll),將它/它們複製到根 Gnumex 資料夾 (c:\gnumex)。

華夏公益教科書