I have a c program that includes a header . This program works fine on windows but on linux when I compile the code with:
gcc main.c -Wall -o main
I get:
main.c:2:10: fatal error windows.h: No such file or directory compilation terminated
Do you have any idea why this error happens and how to fix?
There's no "equivalent", so to speak, for windows. h in Linux, you need to fix your errors case by case, or better, rewrite your code for linux (if it's not too complicated).
h is a Windows-specific header file for the C and C++ programming languages which contains declarations for all of the functions in the Windows API, all the common macros used by Windows programmers, and all the data types used by the various functions and subsystems.
mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32 , for example.
h header file to get function declarations for Windows-only functions. This file does not normally exist on Linux, because its installations of toolchains (such as GCC) will (by default) only include the files needed to compile for Linux. You have a few options: As Ed Heal suggested, port the code to Linux.
The problem is that your code is using the windows.h header file to get function declarations for Windows-only functions. This file does not normally exist on Linux, because its installations of toolchains (such as GCC) will (by default) only include the files needed to compile for Linux.
You have a few options:
As Ed Heal suggested, port the code to Linux. That means you would remove the inclusion of windows.h, and replace all the function calls that used the Windows API with their Linux equivalents. This will make your source code only work on Linux, unless you can refactor the OS-dependent calls into platform-agnostic code. A word of warning: unless the program you're working with is trivial, this is not an easy task. There's no guarantee that every Windows API function has a Linux equivalent.
Install a Windows toolchain for your build system, which should include windows.h, and cross-compile your code. This will result in a binary that won't work on Linux, but will work on Windows.
A middle ground between those two options would be to actually do both, and use conditional compilation to allow you to selectively compile for one target or another.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With