Platformaga asoslangan turli fayllarni qo'shishi mumkinmi?

Qo'shadigan nom fayllari faqat MacOS-da emas, balki Linux mashinalarida mavjud ko'rinadi. Kodni kompilyatsiya qilish va ishga tushirish uchun VM dan foydalanishim mumkin bo'lsa-da, bu MacOS-da buni amalga oshirish uchun yaxshi bo'lar edi.

To be more specific, I am using #include , which compiles on Linux, and I would like to use this compatibility header for MacOS, which I would include with #include "endian.h". My code compiles and executes as expected with the former include on Linux machines, and with the latter include on MacOS machines.

Platformada spetsifikatsiyani o'z ichiga oladi (ehtimol, #if -sayt sintaksisidan foydalaning)? Yoki bu yomon amaliyotmi?

1
#if va #endif qatorlari orasida #include qatoriga ega bo'lishingiz mumkin. Agar bu sizning savolingizga javob bermasa, siz aniqroq bilasizmi?
qo'shib qo'ydi muallif M.M, manba
@hitecherik holat, platformaga xos makro bo'lishi mumkin
qo'shib qo'ydi muallif M.M, manba
@AlejandroVisiedo - bu yaxshi "bog'liq" link, lekin javoblar (va izohlar) havolali bog'lanishlar va boshqalar. Bu ishonchli javob sifatida bu kishiga tayangan holda uni yopishga arziydi.
qo'shib qo'ydi muallif David C. Rankin, manba
Siz yuborgan havolada bu haqda qanday ma'lumot borligini ko'rsatadigan ma'lumot mavjud.
qo'shib qo'ydi muallif Retired Ninja, manba
@hitecherik Siz Buyruq Line Tool ni o'rnatdingizmi?
qo'shib qo'ydi muallif GRC, manba
qo'shib qo'ydi muallif GRC, manba
qo'shib qo'ydi muallif GRC, manba
qo'shib qo'ydi muallif GRC, manba
@hitecherik bu erda aniq muammo: stackoverflow.com/questions/20813028/…
qo'shib qo'ydi muallif GRC, manba
@hitecherik bu erda aniq muammo: stackoverflow.com/questions/20813028/…
qo'shib qo'ydi muallif GRC, manba
@hitecherik bu erda aniq muammo: stackoverflow.com/questions/20813028/…
qo'shib qo'ydi muallif GRC, manba
Bu savol @AlejandroVisionedo bilan bog'liq savolga qaraganda ko'proq o'ziga xosdir - men platformaga xos bo'lgan narsalar haqida so'rayman, boshqa savol esa platformaga xos makrolar haqida so'rayapti.
qo'shib qo'ydi muallif hitecherik, manba
@ M.M Iltimos, savolni o'qib chiqing - men buni to'liq tushunaman, bu holda #if va #endif foydalanish mumkin; if/ bo'lsa, qanday shart mavjudligiga ishonchim komil emas.
qo'shib qo'ydi muallif hitecherik, manba
@GRC Menda Komanda qatorlari vositalari o'rnatilgan - bu mening holatimda farq qilmaydi.
qo'shib qo'ydi muallif hitecherik, manba

6 javoblar

Clang va GCC qo'llab-quvvatlaydigan __ has_include preprocessor holati, siz test platformasidan o'rniga foydalanishingiz mumkin:

#if __has_include()
#include 
#else
#include "endian.h"
#endif

One thing to watch for, though, is that as is not a standard header, it could be possible that it's present on another platform with different definitions that don't really help you.

Bu bir necha kun avval yozgan bu boshqa javob bilan bog'liq.

4
qo'shib qo'ydi

Clang va GCC qo'llab-quvvatlaydigan __ has_include preprocessor holati, siz test platformasidan o'rniga foydalanishingiz mumkin:

#if __has_include()
#include 
#else
#include "endian.h"
#endif

One thing to watch for, though, is that as is not a standard header, it could be possible that it's present on another platform with different definitions that don't really help you.

Bu bir necha kun avval yozgan bu boshqa javob bilan bog'liq.

4
qo'shib qo'ydi

Clang va GCC qo'llab-quvvatlaydigan __ has_include preprocessor holati, siz test platformasidan o'rniga foydalanishingiz mumkin:

#if __has_include()
#include 
#else
#include "endian.h"
#endif

One thing to watch for, though, is that as is not a standard header, it could be possible that it's present on another platform with different definitions that don't really help you.

Bu bir necha kun avval yozgan bu boshqa javob bilan bog'liq.

4
qo'shib qo'ydi

Üstbilgida platformaga xos tarkiblarni (ehtimol, agar # asosli sintaksisdan foydalansangiz) ishlatish uchun usul bormi?

Ha:

#ifdef __MACH__
...//Mac headers
#elif __unix__
...//these will work for Linux/Unix/BSD even for Mac in most cases
#elif _WIN32
...//windows 32 bit
#elif _WIN64
...//windows 64 bit
#endif

Yoki bu yomon amaliyotmi?

Men bunday o'ylamayman

To'g'ri eslab qolsam, boshqa yechim GCC uchun Unix uchun barcha ehtiroslarga o'xshash barcha narsalarni beradi Macdagi Buyruqni kiritish vositasi ni o'rnatish. Mana, mening javobim yaxshilanadi, men nimani unutganimni bilar edim: (Yaxshi, faqatgina Mac uchun bir necha marta rivojlanish uchun foydalanardim: S

  • install the command line tools from the Xcode Preferences->Downloads window, or
  • execute xcode-select --install from the Terminal command-line.

va mana bu erda:

endian.h not found on mac osx

2
qo'shib qo'ydi

Üstbilgida platformaga xos tarkiblarni (ehtimol, agar # asosli sintaksisdan foydalansangiz) ishlatish uchun usul bormi?

Ha:

#ifdef __MACH__
...//Mac headers
#elif __unix__
...//these will work for Linux/Unix/BSD even for Mac in most cases
#elif _WIN32
...//windows 32 bit
#elif _WIN64
...//windows 64 bit
#endif

Yoki bu yomon amaliyotmi?

Men bunday o'ylamayman

To'g'ri eslab qolsam, boshqa yechim GCC uchun Unix uchun barcha ehtiroslarga o'xshash barcha narsalarni beradi Macdagi Buyruqni kiritish vositasi ni o'rnatish. Mana, mening javobim yaxshilanadi, men nimani unutganimni bilar edim: (Yaxshi, faqatgina Mac uchun bir necha marta rivojlanish uchun foydalanardim: S

  • install the command line tools from the Xcode Preferences->Downloads window, or
  • execute xcode-select --install from the Terminal command-line.

va mana bu erda:

endian.h not found on mac osx

2
qo'shib qo'ydi

Üstbilgida platformaga xos tarkiblarni (ehtimol, agar # asosli sintaksisdan foydalansangiz) ishlatish uchun usul bormi?

Ha:

#ifdef __MACH__
...//Mac headers
#elif __unix__
...//these will work for Linux/Unix/BSD even for Mac in most cases
#elif _WIN32
...//windows 32 bit
#elif _WIN64
...//windows 64 bit
#endif

Yoki bu yomon amaliyotmi?

Men bunday o'ylamayman

To'g'ri eslab qolsam, boshqa yechim GCC uchun Unix uchun barcha ehtiroslarga o'xshash barcha narsalarni beradi Macdagi Buyruqni kiritish vositasi ni o'rnatish. Mana, mening javobim yaxshilanadi, men nimani unutganimni bilar edim: (Yaxshi, faqatgina Mac uchun bir necha marta rivojlanish uchun foydalanardim: S

  • install the command line tools from the Xcode Preferences->Downloads window, or
  • execute xcode-select --install from the Terminal command-line.

va mana bu erda:

endian.h not found on mac osx

2
qo'shib qo'ydi