Can I use winnt.h in Linux?
Why would you want Windows functionality on Linux ? That would be like going to an up-market restaurant and asking if you can order from McDonalds.
4 Answers 4
Seems like a strange question; you should probably clarify which function(s) you actually need from winnt.h so that you can learn the Linux equivalent. winnt.h isn’t really a general purpose «library», it’s just an interface to built in Windows-specific functions.
With that as a major caveat, you may get some degree of what you want by attempting to run your app with the help of Wine. See http://www.winehq.org/ If you’re just trying to run an existing app, that’s may be a reasonable solution. If you’re trying to make a Linux version of your app, though, that won’t help you very much.
No, well you could but it’s not going to do any good — the.h file just declares functions that are defined in libs that are only on windows
winnt.h contains lots of macros that depend on a Windows environment and a lot of function declarations that only exist in Windows-specific libraries. So, it’s not really useful (or possible) to use winnt.h on Linux.
That said, you can use Winelib, which includes most of the functionality exposed by those Windows-specific headers, and you can get those features by linking your program with Winelib. In general, this is probably not a good idea, because Winelib is relatively unstable (the functionality of a given API function may be absent, incomplete, buggy, or incompatible compared to the native Windows version). It is a much better idea to look for a Linux-native alternative to what you need.
What parts of winnt.h do you want to use? Of course, if you need some nice macroses or type definitions from it, you can freely copy it to your own header file (of course, with dependencies). But if you include all winnt.h file to your program in linux environment, you will get tons of error messages. One of the reasons for it is pronounced by Martin Beckett in his reply.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Include windows h in linux
I am making a program in Linux that is designed to run in Windows. I had only started programming on Linux earlier this day. I am using the default g++ compiler. When I try to compile my program, I get an error:
free_roam.cpp:7:21: fatal error: Windows.h: No such file or directory compilation terminated.
Can I simply download Windows.h? Is there is a package I didn’t install? Is there no possible way for me to get Windows.h?
If you’re wondering, I cannot simply use another header, as very much of my code uses that header, and (as far as I know) there is no alternative.
You can use MinGW on Linux and cross compile to get a windows executable file. MinGW comes with a windows.h header file so that will work.
If you are compiling for Linux you can’t use windows.h.
If you are compiling for Linux you can’t use windows.h. |
It is kinda weird to have to point this out.
Cross-compiling from linux, especially if you’re using a debian based distribution like Ubuntu, is a piece of cake! You just need to install minGW first.
sudo apt-get install mingw32
Then write code like you normally would, using standard libraries only (iostream, vector, string, cstdio/lib, etc.) Compiling on linux is the same as it always is:
g++ -s -o output main.cpp
and then to produce a Windows executable.
i586-mingw32msvc-g++ -s -o output.exe main.cpp
Don’t worry about trying to remember the minGW compiler’s long name. Typing i5, then hitting tab, and then typing g++ will fill it out for you. Remember that only the standard libraries are portable. If you try to build something using unistd.h, or if you wanted to functionality only available from windows.h, you’re out of luck.
Note that executables produced by minGW will be fairly large (about half a megabyte if you use the -s flag). This is because all of the libraries that might be dynamically linked when built with g++ or in visual studio, are built into the executable. This means that the .exe minGW builds will run on all Windows systems without other dependencies, where executables built by visual studio typically don’t work correctly without installing a run time on the client’s system.
If you try to build something using unistd.h, or if you wanted to functionality only available from windows.h, you’re out of luck. |
Not really, you can use the WinAPI just fine when you compile with MinGW. It just prevents you from creating a native Linux build.
Wow. I’m. really surprised I didn’t know that. Just tried it now, and I can definitely include windows.h and compile with minGW in linux. Test window application works exactly as expected.
EDIT: Programs built this way spawn a console window when they launch. I don’t know if it can be suppressed, but a program as trivial as
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmd, int show)< MessageBox(NULL, "test message","Test",MB_OK); return 0; >
will spawn an empty console every time it’s run.
EDIT EDIT:
i586-mingw32msvc-g++ -mwindows main.cpp
porting win32 code (windows.h) to linux [closed]
It’s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
I’m working on a c++ project where I have bunch of Visual Studio generated project files that I want to port to linux. I essentially am using windows.h header file in multiple files on Windows. Now, I’m unsure as there explicitly exists no linux.h file (incase it does, please guide me where to look at). On linux I’m using Eclipse CDT for development. I’ve two ideas in mind of how possibly it would work on linux but I want your input to know what the right direction is: (1) To remove the windows API calls with Linux API calls in the C++ files. But this would mean, I’ve to find equivalent function in linux which I am not sure where to look at. eg. Filetime in Win32 is equivalent to something in linux (haven’t found this thing yet). (2) I copy the basic syntax of these functions (as written in windows.h) and just create a header file (lets say i name it linux.h) and include this header file in project on linux. So, apparently you might have figured out that I’m confused of how to move things ahead. I just want to work this thing out. Please suggest me ideas/views other than following: (1) No, I don’t want to use Boost. (2) I don’t want to rewrite the files in Visual Studio.