简体   繁体   中英

How can I cross-compile GLEW on ubuntu to windows for a program I am cross-compiling?

I am working on a little project with OpenGL, GLU, freeGLUT, GLEW, and SOIL (an image loader for opengl textures). I would like to cross-compile my project to windows, as it is eventually going to be a game I plan to sell, and more people use Windows than Linux. Unfortunately, the cross-compiler I am using, MinGW, does not support the pre-built libraries of GLEW on the GLEW website.

I have the GLEW source code bundle downloaded, how can I compile that into the libglew32.a (and two other files I forget the name of, one is a static version I think) files I need? There is a makefile already included, should I use that? (I'm just not sure if that will make a library usable for MinGW)

TL;DR How do I compile GLEW for MinGW on ubuntu?

When creating software that's intended to run on several platforms and you're planning to cross compile, it's always a good idea to include the sources of 3rd party libraries (or the libraries themself if you don't have the source code) into your projects source and build tree.

Ideally everything can be built out-of-source-tree, but sometimes (often) that's not the case, so you've to do several builds manually, copying the resulting binaries at some place your main project's build system can access them.

For cross compiling it usually boils down to exactly specify which toolchain binaries to use. For example on Linux the MinGW cross compilers usually are named something like i686-w64-mingw32-… (or similar). When configuring the 3rd party libraries build you've to specify which ones to use. Depending on the build system this either happens through the CC , CXX , LD and some other environment variables, or through the BUILD , HOST and TARGET variables (see here https://stackoverflow.com/a/5139451/524368 ).

The best situation is, if you can integrate everything that's 3rd party into your projects build system, because that relieves you from manually managing that. Personally I've come to like the CMake build system a lot, because it supports out-of-tree builds and if you've got libraries that use CMake themself you can simply copy their source trees into a subdirectory of your project and include their CMake configuration.

Note that's it's often a valid option to replace a projects build system if the build itself is not too complicated (replacing the build system of something like the Linux kernel or ffmpeg is madness, replacing the build system of something like GLFW may be a viable option).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM