最近在試用smartmontools,感覺還行,於是乎想找來源碼改改試試,這下可好,掉坑里了。嗚嗚嗚。。。
smartmontools的源碼在這里可以看到:https://www.smartmontools.org/browser,svn下載地址http://svn.code.sf.net/p/smartmontools/code/。因為工作環境必須使用Windows(改天試試Linux),smartmontools必須使用MingW gcc at MSYS, 於是想把MingW的環境安裝一下。
兩個安裝參考文檔,不知道哪個更合適、簡單:1. http://www.cccp-project.net/wiki/index.php?title=Installing_MSYS-MinGW 2. http://www.mingw.org/wiki/MSYS
唉,摸着石頭過河吧。
1. 安裝MSYS失敗
C:\msys\1.0\postinstall>PATH ..\bin;C:\MinGW\bin;C:\Program Files\SlickEdit Pro
20.0.1\win\;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C
:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program F
iles\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Pr
ogram Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL
Server\120\Tools\Binn\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\fio\
;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\usr
\bin;C:\Program Files\smartmontools\bin
C:\msys\1.0\postinstall>..\bin\sh.exe pi.sh
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x71110000, BaseAddress 0x71110000, RegionSize 0x3000, State 0x1000
C:\msys\1.0\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
C:\msys\1.0\postinstall>pause
請按任意鍵繼續. . .
WHY.........?
查詢方案。。
http://www.myexception.cn/mobile/631529.html
http://download.csdn.net/detail/bihaichentian/2634858
貌似這個有用?http://blog.csdn.net/yangyangyang20092010/article/details/46350519
把之前安裝的MinGW,MSYS刪除,重新安裝試試。還是不行。
好吧,換個Windows環境,我到虛擬機下試試。這次直接按這個步驟來http://blog.csdn.net/yangyangyang20092010/article/details/46350519 。
下載MinGW和MSYS,安裝到c:/MinGW/mingw-64下面,msys整個文件夾也拷貝到這里。另外,需要安裝一下autoconf, automake, perl。
好了,下面可以試試編譯了。
2. 打開c:/MinGW/mingw-**/msys/msys.bat, 進入到smartmontools文件夾目錄,
先運行autogen.sh
然后(參考smartmontools源碼里面的 INSTALL 文件)
mkdir vctmp && cd vctmp ../configure [... any MinGW option set from above ...] make config-vc10
Configure 結束得到:
然后 make config-vc10:
好了,現在Windows需要的三個文件創建好了(config.h,smart*.rc,svnversion.h ),進入os_win32文件夾,用visual studio打開solution文件(*.sln)。分別編譯工程,或者編譯整個solution。
到此,環境搭建問題解決了。
關於如何調試,改天試試再來寫。目前來講,代碼可以編輯編譯和運行了,來個fake圖:
3. 調試
main函數帶參數在Visual Studio下的調試方法 http://blog.csdn.net/qq1987924/article/details/22781331
正所謂
路漫漫其修遠兮,吾將上下而爬坑。