<p>More out of interest than anything else, but can you compile a DirectX app under linux?</p>

<p>Obviously there's no official SDK, but I was thinking it might be possible with wine.</p>

<p>Presumably wine has an implementation of the DirectX interface in order to run games? Is it possible to link against that? (edit: This is called winelib)</p>

<p>Failing that, maybe a mingw cross compiler with the app running under wine.</p>

<p>Half answered my own question here, but wondered if anyone had heard of anything like this being done?</p>

[{'answer_id': 47978, 'author': 'Nicholas', 'author_id': 2658, 'author_profile': 'https://Stackoverflow.com/users/2658', 'pm_score': 0, 'selected': False, 'text': '<p>There is currently no way to compile DirectX code to directly target Linux. You would build your application like you normally would, then run it using a compatibility layer like Wine/Cedega.</p>\n'}, {'answer_id': 48010, 'author': 'Vincent Robert', 'author_id': 268, 'author_profile': 'https://Stackoverflow.com/users/268', 'pm_score': 2, 'selected': False, 'text': "<p>If this is not about porting but creating, you should really consider OpenGL as this API is as powerful as DirectX and much easier to port to Mac or Linux.</p>\n\n<p>I don't know your requirements so better mention it.</p>\n"}, {'answer_id': 48155, 'author': 'Nick Stinemates', 'author_id': 4960, 'author_profile': 'https://Stackoverflow.com/users/4960', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://winehq.com" rel="nofollow noreferrer">Wine</a> is the only way to run DirectX in Linux</p>\n'}, {'answer_id': 48178, 'author': 'AzraelNewtype', 'author_id': 4628, 'author_profile': 'https://Stackoverflow.com/users/4628', 'pm_score': 2, 'selected': False, 'text': "<p>You can't link against wine as it's essentially a call interdictor/translator rather than a set of libraries you can hook into.  If linux is important go OpenGL/SDL/OpenAL.</p>\n"}, {'answer_id': 48190, 'author': 'CiNN', 'author_id': 2566, 'author_profile': 'https://Stackoverflow.com/users/2566', 'pm_score': 0, 'selected': False, 'text': '<p>you can compile a directx apps in linux, but not launching it straight away.\nif you use a crosscompilator that makes windows exe and point to the windows sdk and directx sdk.</p>\n'}, {'answer_id': 66507, 'author': 'UK-AL', 'author_id': 176514, 'author_profile': 'https://Stackoverflow.com/users/176514', 'pm_score': 2, 'selected': False, 'text': '<p>I believe(I\'ve never tried this) you can can compile Linux binarys against winelib. So it works just like a Linux executable, but with the windows libraries.</p>\n\n<p><a href="http://www.winehq.org/site/docs/winelib-guide/index" rel="nofollow noreferrer">http://www.winehq.org/site/docs/winelib-guide/index</a></p>\n'}, {'answer_id': 70695, 'author': 'Nick', 'author_id': 4949, 'author_profile': 'https://Stackoverflow.com/users/4949', 'pm_score': 4, 'selected': True, 'text': '<p>I\'ve had some luck with this. I\'ve managed to compile <a href="http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B5.aspx" rel="nofollow noreferrer">this simple Direct3D example</a>.</p>\n\n<p>I used winelib for this (wine-dev package on Ubuntu). Thanks to <a href="https://stackoverflow.com/users/9554/alastair">alastair</a> for pointing me to winelib.</p>\n\n<p>I modified the source slightly to convert the wchars to chars (1 on line 52, 2 on line 55, by removing the L before the string literals). There may be a way around this, but this got it up and running.</p>\n\n<p>I then compiled the source with the following:</p>\n\n<pre><code>wineg++ -ld3d9 -ld3dx9 triangle.cpp\n</code></pre>\n\n<p>This generates an a.out.exe.so binary, as well as an a.out script to run it under wine.</p>\n'}, {'answer_id': 15586569, 'author': 'Guest1337', 'author_id': 2202177, 'author_profile': 'https://Stackoverflow.com/users/2202177', 'pm_score': 1, 'selected': False, 'text': '<p>go to the directory with the source and type in:</p>\n\n<pre><code>winemaker --lower-uppercase -icomdlg32 -ishell32 -ishlwapi -iuser32 -igdi32 -iadvapi32 -ld3d9 .\nmake\nwine yourexecutable.exe.so\n</code></pre>\n\n<p>If you get this Error:</p>\n\n<pre><code>main.c:95:5: error: ‘struct IDirect3D9’ has no member named ‘CreateDevice’\n</code></pre>\n\n<p>make sure you have named your file main.cpp and not main.c.</p>\n'}, {'answer_id': 60591593, 'author': 'Julian Kirsch', 'author_id': 10654548, 'author_profile': 'https://Stackoverflow.com/users/10654548', 'pm_score': 0, 'selected': False, 'text': '<p>Although this question is dated, I decided to updated on it, because it keeps popping up for me as the first suggestion for this particular problem.</p>\n\n<p>As the previous answers already suggested you can compile against winelib. However, there are yet another two solutions.</p>\n\n<p>The first solution would be either to use the MinGW provided for your distributions. MinGW is a \'cross-compiler\', that compiles either from macOS or linux to windows and has support for DirectX. Note, that C++ libraries compiled with MinGW are not compatible with the MSVC compiler\'s ABI, thus cannot be consumed. However, the resulting binaries can be executed using Wine.</p>\n\n<p>The second solution would be to <a href="https://stackoverflow.com/questions/23248989/clang-c-cross-compiler-generating-windows-executable-from-mac-os-x">use clang as a cross compiler</a>. Clang usually includes the Compiler and Linker needed for Windows out of the box. However, it\'ll require you to include provide the headers and libraries yourself. On the other hand, libraries compiled this way are compatible with MSVC and, thus, can be consumed by it.</p>\n\n<p>Side note:\nLatter allows you to setup an CI server using linux (I did so on a raspberry pi), which creates compatible binaries for end users.</p>\n'}]
['https://Stackoverflow.com/questions/47975', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4949/']