简体   繁体   English

如何在Linux上使用带有Windows交叉编译器的过剩?

[英]How can I use glut with a Windows cross-compiler on Linux?

I have a the mingw32 cross compiler for Linux which compiles windows binaries on linux. 我有一个用于Linux的mingw32交叉编译器,它在linux上编译windows二进制文件。 everything worked out pretty fine until I needed to install glut... I installed fine in linux but whenever I try to compile the same program on windows I can boil it down to: 一切都很顺利,直到我需要安装过剩...我在linux上安装得很好但是每当我尝试在Windows上编译相同的程序时,我可以将其归结为:

/tmp/ccQhHDhy.o:main.cpp:(.text+0xf): undefined reference to __imp__glClear' /tmp/ccQhHDhy.o:main.cpp:(.text+0x1e): undefined reference to _ imp _glBegin' /tmp/ccQhHDhy.o:main.cpp:(.text+0x3d): undefined reference to __imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x5c): undefined reference to _ imp _glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x7b): undefined reference to __imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x85): undefined reference to _ imp _glEnd' /tmp/ccQhHDhy.o:main.cpp:(.text+0xf):对__imp__glClear'/tmp/ __imp__glClear' /tmp/ccQhHDhy.o:main.cpp:(.text+0x1e): undefined reference to _ imp _glBegin'/ tmp的__imp__glClear' /tmp/ccQhHDhy.o:main.cpp:(.text+0x1e): undefined reference to /ccQhHDhy.o:main.cpp:(.text+0x3d):对__imp__glVertex3f'/tmp/ccQhHDhy.o __imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x5c): undefined reference to _ imp _glVertex3f'/ tmp / ccQhHDhy的__imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x5c): undefined reference to .o:main.cpp :(。text + 0x7b):对__imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x85): undefined reference to :main.cpp:(.text+0x85)的未定义引用__imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x85): undefined reference to _ imp _glEnd'的__imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x85): undefined reference to

by linking with the dll directly 通过直接链接到DLL

after getting these linker errors I tried linking opengl32 gdi32 winmm the glut lib file and glu32 在得到这些链接器错误之后,我尝试将opengl32 gdi32 winmm与glut lib文件和glu32连接起来

but still the same this 但仍然是这样的

heres the source code: 继承源代码:

#include <stdlib.h>
#include <GL/glut.h>
using namespace std;
void render(void);
int main(int argc, char **argv){
    glutInit(&argc, argv);
    glutInitWindowPosition(-1,-1);
    glutInitWindowSize(500,500);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("My First Glut Application");
    glutDisplayFunc(render);
    glutMainLoop();
    return 0;
}

void render(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
        glVertex3f(-0.5, -0.5, 0.0);
        glVertex3f(0.5, 0.0, 0.0);
        glVertex3f(0.0, .5, 0.0);
    glEnd();


}

Your program can be compiled without errors in Windows. 您的程序可以在Windows中无错误地编译。 The reason why there are linking errors are probably that you do not use the correct makefile. 存在链接错误的原因可能是您没有使用正确的makefile。 However, there are some errors in your code. 但是,您的代码中存在一些错误。 You can make the following change: 您可以进行以下更改:

  • add glutSwapBuffers() at the end of the render function. render函数的末尾添加glutSwapBuffers()

Then use the makefile for mingw: 然后使用makefile进行mingw:

g++ -o prog -c prog.cpp -lopengl32 -lfreeglut -lglu32

I eventually tried freeglut and after failing cross compiling it. 我最终尝试了freeglut并且在交叉编译失败之后。 I got precompiled windows binaries and after changing 我有预编译的Windows二进制文件和更改后
#include <GL/glut.h>
to
#include <GL/freeglut.h>

and linking with freeglut32 it worked and thanks sean for pointing out those errors 并与freeglut32链接它工作,并感谢肖恩指出这些错误

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

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