How do you link to windows system .dlls from ubuntu while cross-compiling? (Using codeblocks)

I have set up a mingw cross-compiler (i686-w64-mingw32) to compile a windows .exe on ubuntu with the Codeblocks IDE. My "hello world" test shows this to be working. I am now trying to cross-compile my full app which statically links to a number of SDL2 libraries. I am facing this list of errors:

||=== Build: Windows in MyAppSDL (compiler: Windows X-Compile MinGW 32) ===|

windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `timeSetPeriod':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|58|undefined reference to `_imp__timeBeginPeriod@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|52|undefined reference to `_imp__timeEndPeriod@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|58|undefined reference to `_imp__timeBeginPeriod@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `SDL_TicksInit':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|106|undefined reference to `_imp__timeGetTime@0'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `timeSetPeriod':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|52|undefined reference to `_imp__timeEndPeriod@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|52|undefined reference to `_imp__timeEndPeriod@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `SDL_GetTicks_REAL':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|159|undefined reference to `_imp__timeGetTime@0'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `timeSetPeriod':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|58|undefined reference to `_imp__timeBeginPeriod@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `SDL_TicksInit':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|106|undefined reference to `_imp__timeGetTime@0'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `timeSetPeriod':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|52|undefined reference to `_imp__timeEndPeriod@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `SDL_GetTicks_REAL':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|159|undefined reference to `_imp__timeGetTime@0'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `timeSetPeriod':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|58|undefined reference to `_imp__timeBeginPeriod@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `SDL_TicksInit':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|106|undefined reference to `_imp__timeGetTime@0'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_systimer.o)||In function `timeSetPeriod':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c|52|undefined reference to `_imp__timeEndPeriod@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windows.o)||In function `WIN_CoInitialize':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/core/windows/SDL_windows.c|68|undefined reference to `_imp__CoInitializeEx@8'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windows.o)||In function `WIN_CoUninitialize':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/core/windows/SDL_windows.c|87|undefined reference to `_imp__CoUninitialize@0'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowsmouse.o)||In function `WIN_CreateCursor':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowsmouse.c|91|undefined reference to `_imp__CreateDIBSection@24'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowsmouse.c|92|undefined reference to `_imp__CreateBitmap@20'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowsmouse.c|102|undefined reference to `_imp__DeleteObject@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_SetupAPI':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|596|undefined reference to `ImmGetIMEFileNameA@12'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|609|undefined reference to `ImmGetContext@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|612|undefined reference to `ImmReleaseContext@8'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_GetId':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|530|undefined reference to `ImmGetIMEFileNameA@12'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|545|undefined reference to `GetFileVersionInfoSizeA@8'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|549|undefined reference to `GetFileVersionInfoA@16'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|550|undefined reference to `VerQueryValueA@16'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `UILess_GetCandidateList':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|966|undefined reference to `_imp__SysFreeString@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_ClearComposition':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|662|undefined reference to `ImmGetContext@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|666|undefined reference to `ImmNotifyIME@16'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|670|undefined reference to `ImmNotifyIME@16'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|671|undefined reference to `ImmReleaseContext@8'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_Disable':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|344|undefined reference to `ImmAssociateContext@8'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_ClearComposition':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|668|undefined reference to `ImmSetCompositionStringW@24'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|662|undefined reference to `ImmGetContext@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|666|undefined reference to `ImmNotifyIME@16'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|670|undefined reference to `ImmNotifyIME@16'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|671|undefined reference to `ImmReleaseContext@8'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|668|undefined reference to `ImmSetCompositionStringW@24'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `UIElementSink_BeginUIElement@12':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|1033|undefined reference to `_imp__SysFreeString@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `UIElementSink_UpdateUIElement@8':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|1060|undefined reference to `_imp__SysFreeString@4'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_Init':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|289|undefined reference to `_imp__CoCreateInstance@20'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|303|undefined reference to `ImmGetContext@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|304|undefined reference to `ImmReleaseContext@8'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `UILess_SetupSinks':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|1174|undefined reference to `_imp__CoCreateInstance@20'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_GetId':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|530|undefined reference to `ImmGetIMEFileNameA@12'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|545|undefined reference to `GetFileVersionInfoSizeA@8'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|549|undefined reference to `GetFileVersionInfoA@16'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_GetReadingString':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|402|undefined reference to `ImmGetContext@4'|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|477|undefined reference to `ImmReleaseContext@8'|
windowsLibs/SDL2x86/lib/libSDL2.a(SDL_windowskeyboard.o)||In function `IME_GetId':|
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c|550|undefined reference to `VerQueryValueA@16'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 10 second(s)) ===|

I have done a bit of research, and from what I gather, it is because SDL2 wants to dynamically link to some of the windows system libraries. I have also gathered that either mingw or SDL2 comes with the resources to resolve these issues, but I can't figure out what or where these are. While some resources seem to solve the issue, I can never totally follow what the solution actually was. Here are a small selection of the resources I have found on stackoverflow that I think are relevant:

Receiving undefined references to various Windows libraries when compiling with SDL 2 and -static? wxWidgets how to cross compile an application for windows from linux using codeblocks? Linking libcurl while cross compiling with mingw32 under Linux for Windows

The first link lists the .dlls that SDL2 wants to link to. The solution didn't however mention how to link to them. I have found all these libraries on my windows machine, and I did naively attempt to put them in my project folder and dynamically link them, but ubuntu doesn't recognise the .dlls.

The second link is regarding cross-compiling a wxWidgets app for windows, from ubuntu, using Codeblocks IDE. A particular couple of lines from the solution interest me. They regard setting up the compiler.

Compiler Settings >  Other Options : `/usr/local/i586-mingw32/bin/wx-config --cxxflags` 
Linker Settings > Other Options : `/usr/local/i586-mingw32/bin/wx-config --libs`

This is the only part of the solution's compiler setup that differ from my own compiler setup. I have nothing in either of these "Other Options" sections. Obviously the particular filepaths/filenames relate to wxWidgets specifically, but I was wondering if I would need to find some similar files for my SDL2 libraries? I have had a scout around the file system, and no luck.

The third link discusses linking to a .dll, by cross-compiling it in mingw first. I don't understand all the instructions there, maybe because I've had my life sugarcoated with IDE's and have never dealt with the nitty-gritty of compiling a program, regardless, I am fairly certain this resource is relevant.

Any help will be much appreciated!

Pete.

Answers


Ok, so I have today managed to cross-compile my SDL2 dependant app for Windows from Ubuntu.

My first error was to try to statically link to the SDL2 windows libraries (.lib). What I needed to do was to link to the .dll.a files for compilation. These are supplied with SDL2 in the mingw folders. These folders are:

i686-w64-mingw32 for the 32 bit libraries x86_64-w64-mingw32 for the 64 bit libraries

I then faced a number of other errors before I actually got it working. I have listed the steps I took to solving these problems in an answer to another post:

SDL doesn't compile in native enviroment


Need Your Help

Setting theta-ticks in matplotlib polar plots

python matplotlib

My question is related to the following:

Restricting a page view using spring security in a grails application

spring grails filter spring-security

So I've got a standard grails 2.2.1 app using spring-security-core:1.2.7.3. I've a custom filter that validates a password to a restricted part of the application.