Can't cross compile opengl program with mingw - c++

I want to compile program for windows from debian
> '/opt/mingw32/bin/i686-w64-mingw32-g++' '/home/redrockfish/Projects/OpenGl0/main.cpp' -o arcanoid.exe -static-libstdc++ -static-libgcc -lglu32 -lopengl32 -lglut32
/tmp/ccrvQIKM.o:main.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit#12'
/tmp/ccrvQIKM.o:main.cpp:(.text+0x3e): undefined reference to `_imp____glutCreateWindowWithExit#8'
/tmp/ccrvQIKM.o:main.cpp:(.text+0x60): undefined reference to `_imp____glutCreateMenuWithExit#8'
/opt/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.0/../../../../i686-w64-mingw32/bin/ld: /tmp/ccrvQIKM.o: bad reloc address 0x0 in section `.ctors'
collect2: error: ld returned 1 exit status
if I remove -lglut32 the number of underfined references increases. header if freeglut.h, taken from official website. replacing glut32 with glut, adding -lGLU didn't help. with -lGL
cannot find -lGL
collect2: error: ld returned 1 exit status

Functions like __glutCreateWindowWithExit are not part of the official GLUT API. Actually, that function is an extension made by freeglut (and not even part of their external API), so you must not link some random GLUT DLL, but a freeglut one (which are available for windows).

Related

undefined reference to FOLDERID_.. - C++

compiling c++ from linux to windows using g++ and got an error.
Error:
undefined reference to `FOLDERID_RoamingTiles'
collect2: error: ld returned 1 exit status
I'm guessing there is a library I have to reference but I don't know what the name is.
also if that's the case what are the ways I could find the name of the library I have to reference, if that happens again in the future?
thanks.
I'm compiling under msys2/gcc. linking to uuid helped me.
g++ -luuid -o ....

Undefined Reference to `SDL2_Init` with LD when G++ is not giving an error

(FYI Yes I do know that a similar question exists, But I have already tried all the answers.)
I'm trying to setup SDL2 with MinGW and I have everything set up beside one thing. Whenever I try to compile G++ gives no errors but then LD gives me a: undefined reference to SDL_Init Error.
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc28dE2R.o: in function `SDL_main':
C:\Users\user\Documents\SDL2/src/main.cpp:11: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:14: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:18: undefined reference to `IMG_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:20: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lmingw32 -lSDL2main -lSDL2_image -lSDL2" terminated with exit code: 1.
I have tried to move the args around. doing -mwindows, adding -lmingw32. I still keep getting the same errors.. I was able to fix the WinMain Error.. But everything else I couldn't fix.
The command I'm Running to compile:
C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lSDL2main -lSDL2_image -lSDL2
If i could get any help that would be amazing
The common cause of mysterious undefined reference errors on MinGW is using libraries compiled for x64 with an x32 compiler, or vice versa. SDL ships both x32 and x64 ones, try the other ones.
I was able to fix the WinMain Error
Be aware that the intended way of fixing undefined reference to WinMain#16 is not adding #define SDL_MAIN_HANDLED and not doing #undef main. Once you get the right libraries (see the first paragraph), the error should disappear by itself.
Make sure you use int main(int, char**) (and not int main() nor void main()), otherwise it won't work.
-ID:C:\MinGW\include -LD:C:\MinGW\lib
You shouldn't need those flags. Those directories will be searched automatically.
Since you didn't specify any other directories, I assume you placed the SDL files directly into the compiler directories, which isn't a good practice, IMO.
I assume D:C: a typo?
-mwindows
The only purpose of this flag (that I know of) is to prevent your app from automatically opening a terminal window for itself, for release builds.

Qt: compilation issue with minGW

I got a Qt environment that I need to compile.
But when compiling, I get the following messages:
g++ -Wl,-s -mthreads -Wl,-subsystem,windows -o release\Prog.exe object_script.Prog.Release -L"c:\DevProgs\Qt\4.8.6\lib" -lmingw32 -lqtmain build\objects\myapp_res.o -LC:/Windows/System32 -lftd2xx -LC:/qwt-6.0.1/lib -lqwt -lQtSql4 -lQtGui4 -lQtNetwork4 -lQtCore4
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x1fb): undefined reference to `_imp__Sleep#4'
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x293): undefined reference to `_imp__SetUnhandledExceptionFilter#4'
Makefile.Release:303: recipe for target 'release\Prog.exe' failed
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x2a7): undefined reference to `_set_invalid_parameter_handler'
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x475): undefined reference to `_imp__GetStartupInfoA#4'
[MGWPATH]/i686-w64-mingw32/bin/ld.exe: [MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o: bad reloc address 0x0 in section `.CRT$XCAA'
collect2.exe: error: ld returned 1 exit status
where [MGWPATH] is C:/DevProgs/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../..
I sucessfully ran small demos of Qt4.8.6 alone and one with Qwt.
The only doubt I have is regarding the ftd2xx lib.
But, I think it is linked properly because I am able to produce errors of undefined function if I don't link the DLL.
The error message is not clear to me. So, I have absolutely no idea where to look from here!
Could someone help me?
Thank you!

__imp link errors using g++ running under mingw

I have a simple socket program that I'm trying to compile using g++ running in mingw (both the latest versions) on a Win8 system. I'm getting the common linker errors
undefined reference to `__imp_socket'
undefined reference to `__imp_gethostbyname'
I've tried adding -lws2_32 with no luck; i.e. it still can't find the references. Can someone suggest something else I might be missing?
Here's the full output:
G:\source\kak>g++ -o ./test_client -lws2_32 test_client.C
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x4f): undefined reference to `__imp_inet_addr'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x6b): undefined reference to `__imp_socket'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x8b): undefined reference to `__imp_connect'
d:/program files/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o: bad reloc address 0xc in section `.xdata'
collect2.exe: error: ld returned 1 exit status
Try putting the -lws2_32 after the test_client.C parameter. The linker of gcc (ld) is touchy about the order of linkable things, this is probably why it doesn't find your imported functions at link time.

Cygwin OpenGL compiling returns undefined references to imp_iob

I'm attempting to compile this tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/ with Cygwin. I'm getting the following errors:
$ g++ main.cpp -o main -lm -lgl -lglut -lglew -lglfw -lopengl32 -lglu32 -lglaux
-lodbc32 -lodbccp32
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x11a0): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x11c8): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x11f0): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x1394): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x1661): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x1696): more undefined references to `_imp___iob' follow
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: /usr/lib/gc
c/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o): bad reloc address 0x0
in section `.rdata'
collect2: error: ld returned 1 exit status
What may be causing this?
When you see unresolved symbols to _imp__, it implies you are trying to link against a library that was built to use a DLL at run-time. Technically, the problem is how the MSVC compiler mangles the import stub for __stdcall functions - it pre-fixes an underscore, which gcc is not expecting (e.g. _imp instead of imp).
cygwin/MinGW needs a little bit of extra help (either they must use a library that was compiled with gcc or the MSVC DLL-based import library must be altered). There is an article that explains this here.
However, the vast majority of the time the simpler solution is simply to link against the static linking version of your library. In the case of GLEW and glfw, they both ship with static libraries. You will need to define GLEW_STATIC and link against glew32s instead of glew. As for glfw, I am not as familiar - consult the documentation for glfw to find out how to do this.