Roman P
Roman P

Reputation: 5

Is it possible to compile c program on Mac which is compilable on Windows?

I wrote a c program on windows. It can compile properly on this OS. It uses windows.h library. Can I compile it by GCC compilers on Mac? Or I must to change the code? I heard c is portable; therefore it should can run on Mac. Yes?

Upvotes: 0

Views: 1398

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 224002

You must either change the code or install something on your system to provide a substitute for <windows.h>, because it is not a standard header on macOS with Apple’s developer tools.

Assuming you do not install some substitute, if any exist, then you must remove #include <windows.h>. Whether you must change any other code, and how much, depends on what facilities you have used from <windows.h> and cannot be answered without knowing more about your code.

C is portable. The C standard defines a core subset of the language called strictly conforming. Strictly conforming code is portable to all C implementations. Most C programs include code outside that subset. It is portable to some extent, but there are many qualifications to that, many implementation dependencies, and many subtleties. Commonly, any complicated program requires changes in order to run on a new platform unless it was carefully designed for portability.

Upvotes: 1

Related Questions