PDA

View Full Version : Compile for Linux on Windows 10?



QuesterDesura
09-18-2017, 08:25 AM
Hello,

I made a simple application with C++ and OpenGL in Visual Studio Community 2017. How can I compile this so it runs on linux as well? I had quite some issues setting up OpenGL under Windows and I have no clue how to set this up without Visual Studio helping me. I tried creating a new plattform but it doesn't seem to know the .libs like glu or opengl32 nor I do know what exactly I need to do. Also can someone explain me why I can't compile my project without having this settings in preprocessor definition?

WIN32
_WINDOWS
TW_STATIC
TW_NO_LIB_PRAGMA
TW_NO_DIRECT3D
GLEW_STATIC
_CRT_SECURE_NO_WARNINGS
CMAKE_INTDIR="Debug"

This issue I had years ago and I did just figured it out after trying opengl again and carefully checking all settings from a different project, but in the project and in all other tutorials I found it is not mentioned that I need those defines, but I can't compile without manually adding them.

Thanks for your help :)

Dark Photon
09-18-2017, 07:57 PM
I made a simple application with C++ and OpenGL in Visual Studio Community 2017. How can I compile this so it runs on linux as well?

Use CMake. It'll generate your Makefiles on Linux and your MSVS project/solution files on Windows.

Here's a link to a short example:

* Short, standalone GLUT/GLEW test program (https://www.opengl.org/discussion_boards/showthread.php/199957-Async-buffer-copies-from-fbo-pbo-am-I-doing-it-wrong?p=1288432&viewfull=1#post1288432)

Alternatively, you can just create a completely separate Makefile for use under Linux, and then maintain both the MSVS proj/sln files and Linux Makefiles in parallel. But this is only practical for trivially-small apps (needless duplicate work gets to be a drag).


I had quite some issues setting up OpenGL under Windows and I have no clue how to set this up without Visual Studio helping me. I tried creating a new plattform but it doesn't seem to know the .libs like glu or opengl32 nor I do know what exactly I need to do. Also can someone explain me why I can't compile my project without having this settings in preprocessor definition?

Ultimately, you're trying to run compile and link commands that look something like this:



g++ -o my_exec my_exec.cpp -DWHATEVER_DEFINE -lGLEW -lglut -lGLU -lGL


or if you compile and link separately, something like this:



g++ -o my_exec.o -c my_exec.cpp -DWHATEVER_DEFINE
g++ -o my_exec my_exec.o -lGLEW -lglut -lGLU -lGL

Silence
09-20-2017, 12:42 AM
How can I compile this so it runs on linux as well?

If, what you want is not to compile it again in Linux, then the words you are looking for are cross compilation. In that case, here are some links that could be interesting:

http://metamod-p.sourceforge.net/cross-compiling.on.windows.for.linux.html
https://stackoverflow.com/questions/4769968/c-cross-compiler-from-windows-to-linux

This last one is in french, but looks more precise:
http://tcuvelier.developpez.com/tutoriels/cross-gcc/gcc-cross/?page=intro