linker - Cross-compiling OpenGL / glew on linux for windows -


i'm trying cross-compile small test opengl/glew program , linker errors undefined references.

$ /usr/bin/i486-mingw32-g++ -i/usr/i486-mingw32/include -l/usr/i486-mingw32/lib/ -lglfw -lglew32 -lopengl32 main.cc /tmp/cct8opvh.o:main.cc:(.text+0x50): undefined reference `glfwinit' /tmp/cct8opvh.o:main.cc:(.text+0xa6): undefined reference `glfwopenwindowhint' ... 

the same code work when compiling linux:

$ g++ -i/usr/include -l/usr/lib/ -lglfw -lglew -lgl main.cc 

one thing caught eye every exported symbol cross-compiled libraries has underscore prefix:

$ nm /usr/lib/libglfw.a | grep glfwinit$ 00000000 t glfwinit  $ /usr/i486-mingw32/bin/nm /usr/i486-mingw32/lib/libglfw.a | grep glfwinit$ 00000000 t _glfwinit 

this seems common thing since libstdc++.a shares property, why cross-compiler linker looking non-underscore symbols?

running arch following packages (local means aur):

community/mingw32-binutils 2.23.1-3 community/mingw32-gcc 4.7.2-1 local/mingw32-glew 1.9.0-1 local/mingw32-glfw 2.7.7-1 community/mingw32-pthreads 2.9.1-1 community/mingw32-runtime 3.20-4 community/mingw32-w32api 3.17-1 

edit

after playing out both pkg-config , watching glfw recompile , test itself, came following magic seems work, @ least i'm compiling:

 /usr/bin/i486-mingw32-g++ -i/usr/i486-mingw32/include -l/usr/i486-mingw32/lib -mwindows main.cc -lglew32 /usr/i486-mingw32/lib/libglfw.a /usr/i486-mingw32/lib/libopengl32.a -static-libgcc 

there few questions though:

  • what difference between linking -l , without?
  • why need use -l glew , cannot glfw

i able solve problem and, in case ever runs similar situation hope helps you.

  • there 2 versions of glew32 -library in system, glew32.a , glew32.dll.a.
    • glew32.a not allow using --static, glew32.dll.a does.

the 2 commands compile succesfully, first of i've run are:

/usr/bin/i486-mingw32-g++ -i/usr/i486-mingw32/include -l/usr/i486-mingw32/lib main.cc -lglew32.dll -lglfw -lopengl32 --static /usr/bin/i486-mingw32-g++ -i/usr/i486-mingw32/include -l/usr/i486-mingw32/lib main.cc -lglew32 -lglfw -lopengl32 

looking @ old compiling attempts, problem wrong order of libraries , main.cc after libraries.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -