gcc跨平台编译
在OSX下編譯報找不到malloc.h,經過查詢是頭文件位置不兼容,于是搜索資料,看如何通過宏來兼容不同平臺。
在OSX下可以通過 gcc -arch i386 -dM -E - < /dev/null | sort 查看gcc定義的預編譯宏。
可以添加如下代碼進行兼容
#ifdef _WIN32//define something for Windows (32-bit and 64-bit, this part is common)#ifdef _WIN64//define something for Windows (64-bit only)#else//define something for Windows (32-bit only)#endif #elif __APPLE__#include "TargetConditionals.h"#if TARGET_IPHONE_SIMULATOR// iOS Simulator#elif TARGET_OS_IPHONE// iOS device#elif TARGET_OS_MAC// Other kinds of Mac OS#else# error "Unknown Apple platform"#endif #elif __ANDROID__// android #elif __linux__// linux #elif __unix__ // all unices not caught above// Unix #elif defined(_POSIX_VERSION)// POSIX #else # error "Unknown compiler" #endif譬如malloc.h是這樣的:
#ifdef __APPLE__ #include <sys/malloc.h> #else #include <malloc.h> #endif總結
- 上一篇: Android答题app
- 下一篇: mysql order by 嵌套查询_