Linux and Mac build issue

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
posted on 2008-07-17 14:31  SunWentao  阅读(196)  评论(0编辑  收藏  举报