开发者

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

开发者 https://www.devze.com 2023-04-02 11:46 出处:网络
I have a the mingw32 cross compiler for Linux which compiles windows binaries on linux. everything worked out pretty fine until I needed to install glut... I installed fine in linux but whenever I try

I have a the mingw32 cross compiler for Linux which compiles windows binaries on linux. 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:

/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/c开发者_运维问答cQhHDhy.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'

by linking with the dll directly

after getting these linker errors I tried linking opengl32 gdi32 winmm the glut lib file and 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. The reason why there are linking errors are probably that you do not use the correct makefile. However, there are some errors in your code. You can make the following change:

  • add glutSwapBuffers() at the end of the render function.

Then use the makefile for mingw:

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


I eventually tried freeglut and after failing cross compiling it. I got precompiled windows binaries and after changing
#include <GL/glut.h>
to
#include <GL/freeglut.h>

and linking with freeglut32 it worked and thanks sean for pointing out those errors

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号