簡體   English   中英

支持linux / types.h OSX

[英]Supporting linux/types.h OSX

我試圖使用OSX交叉編譯應用程序。 但是,當我編譯時,我得到以下內容......

fatal error: 'linux/types.h' file not found

當我改為sys / types.h時,我得到...

 error: unknown type name '__s32'
 unknown type name '__u8'
 unknown type name '__u16'
 etc

有人可以幫我解決這個問題嗎?

顯然,特定於Linux的頭文件不會出現在MacOS / X下,而不是基於Linux的。

解決問題的最簡單方法是通過您的程序並替換所有實例

#include "linux/types.h"

有了這個:

#include "my_linux_types.h"

...並編寫一個名為my_linux_types.h的新頭文件並將其添加到您的項目中; 它看起來像這樣:

#ifndef my_linux_types_h
#define my_linux_types_h

#ifdef __linux__
# include "linux/types.h"
#else
# include <stdint.h>
typedef int32_t __s32;
typedef uint8_t __u8;
typedef uint16_t __u16;
[... and so on for whatever other types your program uses ...]
#endif

#endif

這些頭文件是內核使用的頭文件。 可能問題在於跨平台的這種頭文件的實現和定義(在我們的例子中是Linux vs Mac OS)POSIX定義不適用於內核,而是適用於它暴露給用戶空間的系統調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM