Linux and Mac build issues 孫文濤 2008-07-16
(1) Windows上面的lib和dll對應Linux下面的lib**.a 和lib**.so,而產生這個*.a和*.so的檔案,即目標檔案為*.o 和*.os
so 為Shared Object的簡寫。
今天我在做跨平台的build時碰到的問題就是用SCons的SharedLibrary的builder,可是在前面的編譯階段卻產生的是*.o的檔案,而真正需要的是*.os的檔案。
在Mac上面StaticLibrary是*.a結尾,SharedLibrary 則是lib**.dylib結尾的。
(2) 今天對link和build的過程有了更新的認識:
compiler將*.cpp檔案build為Object file, *.obj on Windows, *.o or *.os on POSIX platform;
link的工具會將這些object file link為一個lib或dll等。
今天早上很早就碰到了link unresolved symbol的問題,在一個project中應該是不會存在這樣問題的,最後發現原來我用SCons的Glob的操作後,沒有將所有子folder下面的東西都include進來所致。./win,./unix等下面的cpp沒有產生*.obj檔案。
(3) Typical preprocessor definitions:
以後可以參考這個去定義預先處理宏
#if defined(OSWin_)
#ifdef OM_BUILD_DLL
// dll export.
#define OM_Export _declspec(dllexport)
#else
// dll import, the normal way to use the library.
#define OM_Export _declspec(dllimport)
#endif
#elif defined(OSMac_) || defined(OSLinux_)
#define OM_Export
#endif