14

I'm trying to compile a program on MacOSX that I originally wrote on a Windows OS. The program is a large C++ program with the OpenGL API among other things, totaling very many directories and files.

The compilation process at first had a problem with OpenGL for the Mac so I downloaded all the command line utilities of OpenGL for it to work. But as you might imagine, each C file within the OpenGL download had many preprocessors, each of which I in turn had to downloaded the dependencies for.

However, I have remaining one critical step: I receive a fatal error saying that windows.h file is not found. This seems something inherent to the Windows system (the windows.h file is nowhere to be found in my huge list of directories for the program), and the Mac does not seem to have an equivalent for windows.h (http://cboard.cprogramming.com/c-programming/96087-windows-h-mac.html).

Am I out of luck trying to compile this program for the Mac or can something be salvaged?

1
  • I would suggest to install vmware fusion and windows inside it to compile your code with windows.h included. You can somehow include windows.h in mac but you will never be able to run the code as windhows.h as it specific to windows and contains OS specific calls and declarations linking to windows specific dlls and definitions.
    – Aunn Raza
    Commented Oct 28, 2014 at 3:17

5 Answers 5

9

One thing you can do is create a dummy file called windows.h to satisfy the #include directive, then track down the missing typedefs, #defines, etc. one-by-one by looking at the compiler error log.

Windows.h is monolithic and includes about a hundred other Windows headers, but your program is not going to need all of those definitions. This assumes you are not using the Windows API directly, and only using simple things like DWORD. If your software is built using a framework like GLUT or GLFW that is entirely possible, but if you directly interface with WGL, you are going to have a lot of work ahead of you.

9
  • I'm interfacing with beGUI, would that be a problem?
    – warship
    Commented Oct 28, 2014 at 2:58
  • 1
    @white_rabbit: There appears to be a little bit of Win32-specific code in the beGUI framework in FrameWindow_win32.cpp/h. I am not familiar enough with it to tell you if you have to re-write that to make it work on OS X, but there appears to be an example that uses GLUT instead of the Win32 API (begui\src\begui_glut_example) - that example should be portable. Commented Oct 28, 2014 at 3:15
  • It appears that the dummy file approach causes problems: OpenGL seems to use the win32 api: ../bcore/src/GL/wglew.h:114:15: error: unknown type name 'WINAPI'
    – warship
    Commented Oct 28, 2014 at 3:21
  • Do you think perhaps using GLFW (instead of beGUI) would help? Or is the fact that OpenGL requires the Win32 API cause for only keeping this Windows-compatible?
    – warship
    Commented Oct 28, 2014 at 3:25
  • OpenGL doesn't require Win32 at all. Each platform has its own API that handles windowing for OpenGL, the Windows API is called WGL. OS X uses three different APIs: AGL/CGL/NSOpenGL (it's a confusing mess). Now, from the error you posted it appears that beGUI depends on WGL. GLFW wouldn't have this problem, but it's not a GUI framework. Are you using beGUI to do anything GUI related, or just to create an OpenGL window? Commented Oct 28, 2014 at 3:28
4

windows.h is provided by the Windows SDK, and implemented by the Windows OS itself.

You need to rewrite the program to not use Windows APIs.
Good luck.

8
  • Do you think the approach above of making a dummy file would work if I'm using a cross-platform interface such as beGUI?
    – warship
    Commented Oct 28, 2014 at 3:12
  • @white_rabbit: Only if you aren't using any actual functions from windows.h.
    – SLaks
    Commented Oct 28, 2014 at 3:13
  • Okay, so looks like OpenGL is using the win32 API: ../bcore/src/GL/wglew.h:114:15: error: unknown type name 'WINAPI' This is a significant problem, is it not?
    – warship
    Commented Oct 28, 2014 at 3:22
  • I am considering rewriting from beGUI to GLFW? Would you advise this to help this issue?
    – warship
    Commented Oct 28, 2014 at 3:24
  • @white_rabbit: OpenGL does not use the Windows API. But you mentioned you downloaded a number of tools and files for OpenGL. Why did you do that? You don't have to do that. Most likely your problems are with this thing you did.
    – datenwolf
    Commented Oct 28, 2014 at 10:11
2

You cannot get Windows.h for mac, it is Windows OS specific.
There are many alternatives to functions used in Windows.h on the other hand.

0

You can use x86_64-w64-mingw32 to cross compile win32 programs on MacOS. It includes windows.h.

3
  • 1
    Would these programs run under MacOS, or would you need to copy the executables over to a Windows machine and run them there? Commented Oct 14, 2023 at 3:41
  • @JeremyFriesner Won't run under MacOS. Would have to copy it to a Windows machine.
    – umar14
    Commented Oct 14, 2023 at 5:51
  • This is misleading; OP wants to compile on their Mac, for Mac. MinGW compiles for Windows and Windows only (which is the very point of MinGW). So even if MinGW can somehow be used to build the program on Mac, it'll only run on Windows and will therefore not achieve what OP needs. Commented Oct 14, 2023 at 21:53
0

mac has a file like windows.h called MacWindows.h

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Jun 25 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.