简体   繁体   English

交叉编译linux-> windows:使用opengl32.dll获得更新的OpenGL支持

[英]Cross-compiling linux-->windows: Getting newer OpenGL support with opengl32.dll

I'm using x86_64-w64-mingw32 toolset, with gcc version 4.8.2 to cross-compile 64-bit windows binaries and libraries from my ubuntu 14.04.1 machine. 我正在使用x86_64-w64-mingw32工具集和gcc版本4.8.2从我的ubuntu 14.04.1计算机上交叉编译64位Windows二进制文件和库。

I've had no problems cross-compiling and testing my project and various libraries: SDL2 , SDL2_image , SDL2_mixer , SDL2_ttf , libfreetype , libpng , libjpeg , libz , libvorbis , libogg , bullet , flite , polyvox , libnoise . 我没有交叉编译和测试我的项目以及各种库的问题: SDL2SDL2_imageSDL2_mixerSDL2_ttflibfreetypelibpnglibjpeglibzlibvorbisliboggbulletflitepolyvoxlibnoise

However, I have issues linking to OpenGL when I'm using features that only exist in newer versions of OpenGL . 但是,当我使用仅在较新版本的OpenGL存在的功能时,我在链接到OpenGL时遇到问题。

First, let me state a few preconceptions, and please correct me if I'm wrong. 首先,让我陈述一些先入之见,如果我做错了,请纠正我。

  • The opengl32.a I'm linking to (in particular, /usr/x86_64-w64-mingw32/lib/libopengl32.a , that I have from ubuntu package mingw-w64-x86-64-dev version 3.1.0-1 ) is from the mesa project. opengl32.a我链接到(特别是/usr/x86_64-w64-mingw32/lib/libopengl32.a ,我是从Ubuntu的软件包具有mingw-w64-x86-64-dev版本3.1.0-1 )来自mesa项目。
  • This libopengl32.a targets an OpenGL version that seems old. 这个libopengl32.a目标是一个看起来旧的OpenGL版本。 It contains function definition for glBegin 它包含glBegin函数定义

     $ nm /usr/x86_64-w64-mingw32/lib/libopengl32.a | grep ' glBegin$' 0000000000000000 T glBegin 

    But the same with glCreateShader has no matches. 但是与glCreateShader相同,没有匹配项。

    With the linux library GL.so , both have matches: 使用linux库GL.so ,它们都有匹配项:

     $ readelf -Ws /usr/lib/nvidia-331/libGL.so | grep ' glCreateShader$\\|glBegin$' 2129: 000000000030eaa0 0 FUNC GLOBAL DEFAULT 17 glCreateShader 2312: 00000000002fe940 0 FUNC GLOBAL DEFAULT 17 glBegin 

My question is whether or not: 我的问题是:

  1. I'm just doing things wrong. 我做错事了。 That for windows, all OpenGL > 1.1 function calls have to be dynamically loaded through extensions, and that I've been spoiled by SDL2/SDL_opengl.h and/or GL/glext . 对于Windows,所有OpenGL > 1.1函数调用都必须通过扩展程序动态加载,而SDL2/SDL_opengl.h和/或GL/glext破坏了我的GL/glext If this is the case, why does GL.so have symbols for all the OpenGL functions, while libopengl32.a does not? 如果是这样,为什么GL.so的所有OpenGL函数都有符号,而libopengl32.a没有? And, how do I unify this so that my code becomes unaware of cross-compilation, while using OpenGL 4.0 functions? 而且,在使用OpenGL 4.0函数时,如何统一此代码,以使我的代码不知道交叉编译?

  2. I have to cross-compile a newer version of libopengl32.a from scratch from the mesa source code. 我必须从mesa源代码从头开始交叉编译libopengl32.a的较新版本。 (note: I'm not even sure libopengl32.a comes from the mesa project) (注意:我什至不确定libopengl32.a来自mesa项目)

  3. ??? (something else entirely) (其他完全)

If this is the case, why does GL.so have symbols for all the OpenGL functions, while libopengl32.a does not? 如果是这样,为什么GL.so的所有OpenGL函数都有符号,而libopengl32.a没有?

Because the developers of the particular implementation in question didn't bother to hide, ie not expose the symbols to the outside. 因为所讨论的特定实现的开发人员不会费心隐藏,即不会将符号暴露在外面。 The OpenGL operating system ABIs just specify which symbols must be available. OpenGL操作系统ABI仅指定哪些符号必须可用。 They don't specify that additional symbols may not be exposed. 他们没有指定可能不会公开其他符号。

I have to cross-compile a newer version of libopengl32.a from scratch from the mesa source code. 我必须从mesa源代码从头开始交叉编译libopengl32.a的较新版本。 (note: I'm not even sure libopengl32.a comes from the mesa project) (注意:我什至不确定libopengl32.a来自mesa项目)

DON'T DO THIS! 不要这样做! In fact you should never link against a specific version of a OpenGL implementation at all (except if you want to ship that very implementation as a fallback). 实际上,您绝对不应该链接到特定版本的OpenGL实现(除非您要将该实现作为后备交付)。 Always link to some generic interface specification. 始终链接到一些通用接口规范。 Never expect anything outside the specified ABIs (not API. ABI = Application Binary Interface) to be exposed. 绝不要暴露指定的ABI(不是API。ABI=应用程序二进制接口)之外的任何东西。 For Windows that's OpenGL-1.1, for Linux at the moment OpenGL-1.2. 对于Windows,即OpenGL-1.1,对于Linux,目前为OpenGL-1.2。 Anything beyond can be accessed reliable only through the extension mechanism. 只有通过扩展机制,才能可靠地访问任何超出范围的内容。

??? ??? (something else entirely) (其他完全)

You may want to look at glloadgen ( https://bitbucket.org/alfonse/glloadgen/wiki/Home ), a set of Lua scripts which creates a tightly tailored OpenGL interface loader. 您可能想看看glloadgen( https://bitbucket.org/alfonse/glloadgen/wiki/Home ),这是一组Lua脚本,它们创建了紧密定制的OpenGL接口加载器。 With the code generated by glloadgen you don't link against opengl32.lib libopen32.a or libGL.so at all. 使用glloadgen生成的代码,您根本不会链接到opengl32.lib libopen32.alibGL.so The library is loaded and all symbols resolved at runtime, largely avoiding all the headaches that you get from a mixed loading environment. 库已加载,所有符号都在运行时解析,从而极大地避免了混合加载环境带来的所有麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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