I am trying to build a lib for macOS and Linux. The reason I am writing is to know how to detect macOS 11+ and Linux in a header file.
I have the structure on cmake, and it's building, but the os.h
header is not building.
How can I detect with #ifdef
s whether my code is on macOS Big Sur+ vs Red Hat? I am working on both sides.
I tried to use #ifdef
s without success. This lib made with cmake is a proprietary code. I read a lot here about the subject without success.
Can you help me?
My os.h
:
#ifndef OS_H
#define OS_H
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <map>
#include <string>
#include <sstream>
#include <vector>
#include <cstring>
#include <vector>
#include <fstream>
#include <ctype.h>
// os detection version
#ifdef Q_OS_LINUX
std::cout << "Linux version";
#elif defined(Q_OS_CYGWIN)
std::cout << "Cygwin version";
#else
#error "We don't support that version yet..."
#endif
#ifdef _WIN32 // Includes both 32 bit and 64 bit
#ifdef _WIN64
printf("Windows 64 bit\n");
#else
printf("Windows 32 bit\n");
#endif
#elif __linux__
printf("Linux\n");
#elif __unix__
printf("Other unix OS\n");
#else
printf("Unidentified OS\n");
#endif
#if __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR
printf("iPhone stimulator\n");
#elif TARGET_OS_IPHONE
printf("iPhone\n");
#elif TARGET_OS_MAC
printf("MacOS\n");
#else
printf("Other Apple OS\n");
#endif
#else
printf("Not an Apple OS\n");
#endif
#if __linux__
// linux optimized code (will fail in other platforms)
#else
// general code for all platforms
#endif
// general code
using namespace std;
#endif // OS_H
I cannot get this straight. My issue is somewhere. It's my first time with os flags. I am not used to this.