Linked Questions
16 questions linked to/from How to identify platform/compiler from preprocessor macros?
1 vote
2 answers
500 views
Compile part of code rely on OS in Qt [duplicate]
I need to figure out the operating system my program is running on during runtime. I'm using Qt 4.8.1, MinGW. My program shall run a command-line QProcess on Windows or Linux. Now I need a kind of ...
324 votes
20 answers
233k views
How do I check OS with a preprocessor directive?
I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-...
227 votes
7 answers
274k views
C++ compiling on Windows and Linux: ifdef switch [duplicate]
I want to run some c++ code on Linux and Windows. There are some pieces of code that I want to include only for one operating system and not the other. Is there a standard #ifdef that once can use? ...
124 votes
8 answers
115k views
Detecting CPU architecture compile-time
What is the most reliable way to find out CPU architecture when compiling C or C++ code? As far as I can tell, different compilers have their own set of non-standard preprocessor definitions (_M_X86 ...
39 votes
9 answers
67k views
Are there any macros to determine if my code is being compiled to Windows? [duplicate]
I would like to detect whether the OS I'm compiling on is Windows. Is there a simple macro I can check to verify that?
17 votes
3 answers
23k views
MinGW not defining WIN32, error in preprocessor directives
I am using mingw32-make to compile a project to Windows, which depends on a project called libevent2. I keep receiving this error - util.h:69:25: fatal error: sys/socket.h: No such file or directory ...
4 votes
1 answer
4k views
One header for multiple source files?
How might I write a single header file that defines an interface and use a separate source files to write platform-specific code? For example: video.h video_windows.c video_linux.c video_osx.c
4 votes
1 answer
7k views
RAW Sockets in C++ Windows
I want to use a RAW Socket in Visual C++. I saw a function on Linux which is int out = socket(AF_INET, SOCK_RAW, htons(ETH_P_ALL)); Using this code in linux we can do that, but how to use RAW SOCKET ...
1 vote
2 answers
3k views
Platform Independence with C++. Detection and Compilation
So i'd like to build my application to be Platform Independent such that it can run on Windows, OSX, Linux etc. For example one of the main "parts" that is different across the platforms is a Window. ...
4 votes
2 answers
2k views
Start and kill processes in C++ cross platform
I'm looking for a way for basic management of processes in a cross platform way in C++, but I can't use external libraries (like boost::process). The scenario is this - i'm calling a child process ...
1 vote
3 answers
675 views
What is #define mostly used for in c++?
I have just been using the #define to change my values ex: #include <iostream> #include <string> #define Changed_num 100 using namespace std; int main () { ...
2 votes
1 answer
2k views
Cross Platform usage of printf_s and scanf_s functions - C (linux/win32) [duplicate]
I'm currently trying to get some C code that I originally wrote for linux (gcc) to build on a win32 box. The MSVC compiler is giving me warnings for all my printf and scanf usage suggesting I should ...
2 votes
1 answer
600 views
Preprocessor Macro not working on Windows in Fortran Code
Dear All I have a small Fortran program containing preprocessor macro. Below is a minimal example. On mac os x, it works well but when I compile it on windows 7 (64-bit) it always prints unknown ...
0 votes
3 answers
471 views
How exactly cross platform libraries works for different machines
Recently, I was learning about networking in C++ and I found boost.asio which is a cross platform library, and then I got a thought about how this library is a cross platform since Windows provides ...
0 votes
1 answer
267 views
Cross compiling error on Visual Studio
Here is a snapshot of a function that I am porting to my Windows machine from here using Visual Studio. bool MinidumpFileWriter::Open(const char *path) { assert(file_ == -1); #if __linux__ file_ =...