I have windwos source code(first.c) how can I compile it and creating executable file under linux?
I run kali linux.

I appreciate your help

Yes,but there is no one write clear linux commands about that.
I need someone to help me with commands.

Why would you want to compile a windows program on *nix? Why not just compile on Windows?

Because I like to learn.

I think I'm solved
Here is the code hello world i hello.c

#include <stdio.h>

int main(void)
  printf("Hello World\n");
  return 0;

root@kali:~/.wine/drive_c/MinGW/bin# wine gcc -o /root/Desktop/hello.exe /root/Desktop/hello.c

root@kali:~# cd Desktop/
root@kali:~/Desktop# wine hello.exe
Hello World

But when I try to compile another one I got this error anyone know how can I fix it?

root@kali:~/.wine/drive_c/MinGW/bin# wine gcc -o /root/Desktop/first.exe /root/Desktop/first.c
/root/Desktop/first.c:12:22: fatal error: ntstatus.h: No such file or directory
     #include <ntstatus.h>
    compilation terminated.


Here is header of the first.c

#ifndef WIN32_NO_STATUS
# define WIN32_NO_STATUS
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <windows.h>
#include <assert.h>
#ifdef WIN32_NO_STATUS
# undef WIN32_NO_STATUS
#include <ntstatus.h>

The compiler is complaining because it cannot find ntstatus.h.
Either you do not have it installed, or it has been put somewhere outside of the systems search path for header files.

Also you should be aware that ntstatus.h is a windows-only header file. It is not available for Linux.
You will need to have a copy of all of the windows header files and the windows versions of the corresponding libraries somewhere on your machine if you do not already have them. Once you do have them, you need to either put them on a path that is recognised by the compiler, or tell the compiler where to find the files.

Personally I've never tried cross-compiling Windows binaries on a Linux machine, so I can't really help beyond that! I know it is possible to do it, but I've never had the desire (or the need) to do so, or to find out for myself. But if anybody here at Daniweb knows anything about this kind of thing, it will probably be Rubberman or Mike!

Thanks Sir for your answer.
Well see if some one can help me to solve this problem.

Did you try the mingw32 package?

You can install it with:

$ sudo apt-get install mingw32 mingw32-binutils mingw32-runtime

or whatever the equivalent packages are for Kali Linux (you might have to manually download the .deb files for these, and install them with $ sudo dpkg --install name_of_package.deb).

This will make it easier because MinGW comes with the standard Windows headers and libraries, and you won't have to fiddle around too much with the include-paths and all that. See compilation instructions here.

Thanks mike for your answer
Yes,I already installed mingw32 package but still I get the same error when I compile it!!!

Member Avatar for iamthwee

Forget windoze port this to lunux.

Most windows c/c++ will run on linux anyway unless you are using os specific calls. Depending on what you are doing you probably don't even need windows.h or ntstatus.

Have you searched your linux machine for ntstatus.h?
Open a terminal and try the following command:
find / -type f -iname "ntstatus.h"
This will recursively search from the root of your file-system and try to find the file.

If it lists any files called ntstatus.h, then you know it is a problem with the compilers paths (and in which case, I'm not sure how to fix it offhand!).

But if it does NOT list any files, you'll probably need to download and install the Windows SDK on your Kali Linux machine (because ntstatus.h is part of the Windows SDK).

BTW: If memory serves, when you download the SDK from Microsoft, it is usually a self-extracting archive in .exe format. So I'm not sure whether you'd be best served installing it via Wine, onto Wines virtual C:, or by extracting/installing it on a Windows machine and copying all of the include and library files to your Kali box via a USB thumb-drive.... IDK!

Either way, the first thing you need to do is determine whether or not you have ntstatus.h. I suspect that you do not!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.