project-navigation
Personal tools

Author Topic: [RESOLVED] Crosscompiling from Linux for Windows  (Read 11194 times)

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
[RESOLVED] Crosscompiling from Linux for Windows
« on: September 20, 2010, 03:11:50 pm »
Hi Devs,
I'm currently attempting to cross compile latest git version (20/09/2010) from a custom Linux toolchain (MinGW-Cross-Env) to Windows.

with a

Code: [Select]
SDL_LIBS="`/opt/mingw/usr/i686-pc-mingw32/bin/sdl-config --libs` -lrtmp -lz -lws2_32 -lwinmm -lssl -lgdi32 -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lz -lfreetype -lwinmm" ./configure --host='i686-pc-mingw32' --with-curl-config=/opt/mingw/usr/i686-pc-mingw32/bin/curl-config
I get this error while linking:

Code: [Select]
* [GAM] ... linking  ()
 * [UFO] ... linking   (-L/opt/mingw/usr/i686-pc-mingw32/lib -lvorbis -lm -logg       -lz  -L/opt/mingw/usr/i686-pc-mingw32/lib -lcurl -L/opt/mingw/usr/i686-pc-mingw32/lib -L/opt/mingw/usr/i686-pc-mingw32/lib -lidn -lwldap32 -lws2_32 -lgcrypt -liconv -L/opt/mingw/usr/i686-pc-mingw32/lib -lgpg-error -lz -lgnutls -lws2_32 -lgcrypt -liconv -L/opt/mingw/usr/i686-pc-mingw32/lib -lgpg-error -ljpeg  -L/opt/mingw/usr/i686-pc-mingw32/lib -lpng14 -lz   -L/opt/mingw/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -lwinmm -mwindows -liconv -lm -luser32 -lgdi32 -lwinmm -ldxguid -lrtmp -lz -lws2_32 -lwinmm -lssl -lgdi32 -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lz -lfreetype -lwinmm -mwindows -L/opt/mingw/usr/i686-pc-mingw32/lib -lSDL_image -ltiff -ljpeg -lmingw32 -lSDLmain -lSDL -liconv -lm -luser32 -lgdi32 -lwinmm -ldxguid -lpng14 -lz   -mwindows -L/opt/mingw/usr/i686-pc-mingw32/lib -lSDL_mixer -lmikmod -lpthread -lsmpeg -lstdc++ -lmingw32 -lSDLmain -lSDL -liconv -luser32 -lgdi32 -lwinmm -ldxguid -lvorbisfile -lvorbis -lm -logg   -lSDL_ttf  -logg  -lxvidcore  -L/opt/mingw/usr/i686-pc-mingw32/lib -ltheora -logg   -lintl -lxvidcore  -lws2_32 -lwinmm -lgdi32 -lopengl32 -L/opt/mingw/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -lwinmm -mwindows -liconv -lm -luser32 -lgdi32 -lwinmm -ldxguid -lrtmp -lz -lws2_32 -lwinmm -lssl -lgdi32 -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lz -lfreetype -lwinmm)
Warning: resolving _timeBeginPeriod by linking to _timeBeginPeriod@4
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
 * [DED] ... linking   (-lz  -L/opt/mingw/usr/i686-pc-mingw32/lib -lcurl -L/opt/mingw/usr/i686-pc-mingw32/lib -L/opt/mingw/usr/i686-pc-mingw32/lib -lidn -lwldap32 -lws2_32 -lgcrypt -liconv -L/opt/mingw/usr/i686-pc-mingw32/lib -lgpg-error -lz -lgnutls -lws2_32 -lgcrypt -liconv -L/opt/mingw/usr/i686-pc-mingw32/lib -lgpg-error -lws2_32 -lwinmm -lgdi32 -L/opt/mingw/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -lwinmm -mwindows -liconv -lm -luser32 -lgdi32 -lwinmm -ldxguid -lrtmp -lz -lws2_32 -lwinmm -lssl -lgdi32 -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lz -lfreetype -lwinmm)
debug-mingw32-i386/server/ports/windows/win_main.o: In function `Sys_Init':
/opt/src/ufoai/src/ports/windows/win_main.c:48: undefined reference to `_timeBeginPeriod'
collect2: ld returned 1 exit status
make: *** [ufoded] Errore 1

Ehm... to tell the truth I have _timeBeginPeriod@4 defined in winmm.a, anyway do I need to put -lwinmm in a particular place?

Thanks!
« Last Edit: September 25, 2010, 02:32:21 pm by MarcoBi »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Crosscompiling from Linux for Windows
« Reply #1 on: September 20, 2010, 06:49:05 pm »
well - i don't know about that linking problem - maybe add the -lwinmm stuff to build/plattform_specific.mk

it would be very nice if you could test the patch for the new build system with mingw-cross-env. the patch is at http://mattn.ninex.info/files/newbuildsystem.diff

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
Re: Crosscompiling from Linux for Windows
« Reply #2 on: September 21, 2010, 03:15:56 pm »
well - i don't know about that linking problem - maybe add the -lwinmm stuff to build/plattform_specific.mk

it would be very nice if you could test the patch for the new build system with mingw-cross-env. the patch is at http://mattn.ninex.info/files/newbuildsystem.diff

Do I need to apply it to latest git? I'm asking because of lot of "rejected" errors... { Reversed (or previously applied) patch detected!  Assume -R? [n] } 

Offline bayo

  • Professional loser
  • Project Coder
  • Captain
  • ***
  • Posts: 733
    • View Profile
Re: Crosscompiling from Linux for Windows
« Reply #3 on: September 21, 2010, 04:33:46 pm »
I dont check to patch, but it is not yet applied to the repository.

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Crosscompiling from Linux for Windows
« Reply #4 on: September 21, 2010, 05:02:58 pm »
yes, you have to apply it - but try to use git apply patch.diff

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
Re: Crosscompiling from Linux for Windows
« Reply #5 on: September 22, 2010, 12:27:15 pm »
yes, you have to apply it - but try to use git apply patch.diff

I have configured with
Code: [Select]
./configure --enable-release --disable-signals --disable-backtraces --target-os=mingw32
and then tweaked a little mingw32.mk as
Code: [Select]
SO_EXT                    = dll
SO_LDFLAGS                = -shared
SO_CFLAGS                 = -shared

EXE_EXT                   = .exe

CC_PATH                   = /opt/mingw/usr/i686-pc-mingw32

# TODO: config.h
CFLAGS                   += -DSHARED_EXT=\"$(SO_EXT)\"
CFLAGS                   += -DGETTEXT_STATIC
# Windows XP is the minimum we need
CFLAGS                   += -DWINVER=0x501

CURL_CONFIG              ?= $(CC_PATH)/bin/curl-config
CURL_LIBS                ?= $(shell $(CURL_CONFIG) --libs) -lrtmp -lssl -lcrypto -lz -lws2_32 -lwinmm -lgdi32
CURL_CFLAGS              ?= $(shell $(CURL_CONFIG) --cflags)
SDL_CONFIG               ?= $(CC_PATH)/bin/sdl-config
SDL_LIBS                 ?= $(shell $(SDL_CONFIG) --libs)
SDL_CFLAGS               ?= $(shell $(SDL_CONFIG) --cflags)
OPENGL_CFLAGS            ?=
OPENGL_LIBS              ?= -lopengl32
PKG_CONFIG               ?= $(CROSS)pkg-config
SDL_TTF_LIBS             ?= $(call PKG_LIBS,SDL_ttf) $(call PKG_LIBS,freetype2)
SDL_TTF_CFLAGS           ?= $(call PKG_CFLAGS,SDL_ttf) $(call PKG_CFLAGS,freetype2)
SDL_IMAGE_LIBS           ?= $(call PKG_LIBS,SDL_image)
SDL_IMAGE_CFLAGS         ?= $(call PKG_CFLAGS,SDL_image)
SDL_MIXER_LIBS           ?= $(call PKG_LIBS,SDL_mixer)
SDL_MIXER_CFLAGS         ?= $(call PKG_CFLAGS,SDL_mixer)
OPENAL_CFLAGS            ?= $(call PKG_CFLAGS,openal)
OPENAL_LIBS              ?= $(call PKG_LIBS,openal)
THEORA_CFLAGS            ?= $(call PKG_CFLAGS,theora)
THEORA_LIBS              ?= $(call PKG_LIBS,theora)
GLIB_CFLAGS              ?= $(call PKG_CFLAGS,glib-2.0)
GLIB_LIBS                ?= $(call PKG_LIBS,glib-2.0)
GTK_CFLAGS               ?= $(call PKG_CFLAGS,gtk+-2.0)
GTK_LIBS                 ?= $(call PKG_LIBS,gtk+-2.0)
GTK_SOURCEVIEW_CFLAGS    ?= $(call PKG_CFLAGS,gtksourceview-2.0)
GTK_SOURCEVIEW_LIBS      ?= $(call PKG_LIBS,gtksourceview-2.0)
GTK_GLEXT_CFLAGS         ?= $(call PKG_CFLAGS,gtkglext-1.0)

ufo_LDFLAGS              += -lws2_32 -lwinmm -lgdi32 -lintl -lfreetype
ufoded_LDFLAGS           += -lws2_32 -lwinmm -lgdi32
testall_LDFLAGS          += -lwinmm -lgdi32
ufo2map_LDFLAGS          += -lwinmm
ufomodel_LDFLAGS         += -lwinmm
uforadiant_LDFLAGS       += -lglib-2.0 -lgtk-win32-2.0 -lgobject-2.0 -lstdc++

but...
Code: [Select]
marco@MarcoBi:/opt/src/ufoai$ make
Platform:     linux
Target:       mingw32
Architecture: i386
Compiler:     i686-pc-mingw32-cc
Targets:      game testall ufo ufo2map ufoded ufomodel uforadiant uforadiant-brushexport
===> LD [base/game.dll]
===> LD [testall.exe]
===> LD [ufo.exe]
===> LD [ufo2map.exe]
===> LD [ufoded.exe]
===> LD [ufomodel.exe]
===> LD [radiant/uforadiant.exe]
release-linux-i386/uforadiant/tools/radiant/radiant/dialogs/about.cpp.o: In function `_Z7DoAboutv':
/opt/src/ufoai/src/tools/radiant/radiant/dialogs/about.cpp:130: undefined reference to `__imp__gtk_micro_version'
/opt/src/ufoai/src/tools/radiant/radiant/dialogs/about.cpp:130: undefined reference to `__imp__gtk_minor_version'
/opt/src/ufoai/src/tools/radiant/radiant/dialogs/about.cpp:130: undefined reference to `__imp__gtk_major_version'
/opt/src/ufoai/src/tools/radiant/radiant/dialogs/about.cpp:140: undefined reference to `__imp__gtkglext_micro_version'
/opt/src/ufoai/src/tools/radiant/radiant/dialogs/about.cpp:140: undefined reference to `__imp__gtkglext_minor_version'
/opt/src/ufoai/src/tools/radiant/radiant/dialogs/about.cpp:140: undefined reference to `__imp__gtkglext_major_version'
collect2: ld returned 1 exit status
make: *** [radiant/uforadiant.exe] Errore 1

I have only static libraries, so... do I need shared libraries? (that's not the case of mingw cross env)

Best reagrds

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Crosscompiling from Linux for Windows
« Reply #6 on: September 22, 2010, 04:39:36 pm »
yes, in mingw32.mk is the pkg-config call for the libs of gtkglext missing.

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Crosscompiling from Linux for Windows
« Reply #7 on: September 22, 2010, 04:40:16 pm »
btw. please post a diff when you fixed something on the makefile, not the full file.

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
Re: Crosscompiling from Linux for Windows
« Reply #8 on: September 22, 2010, 05:22:07 pm »
btw. please post a diff when you fixed something on the makefile, not the full file.

Here is the patch for my modified mingw32.mk Makefile.

Can I repost my compilation attempt when I'll rebuild a shared version of the GTK stack in my cross compile env?

Bye!

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
Re: Crosscompiling from Linux for Windows
« Reply #9 on: September 22, 2010, 05:23:51 pm »
yes, in mingw32.mk is the pkg-config call for the libs of gtkglext missing.

It's not missing, I have
Code: [Select]
GTK_GLEXT_CFLAGS         ?= $(call PKG_CFLAGS,gtkglext-1.0)
GTK_GLEXT_LIBS           ?= $(call PKG_LIBS,gtkglext-1.0)

Bye

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Crosscompiling from Linux for Windows
« Reply #10 on: September 22, 2010, 06:33:53 pm »
you should add your the mingw-cross-env bin dir to your path then you don't have to patch the makefiles (see Makefile.local)

about the missing libs for mingw - that should not be added like this but like this:
Code: [Select]
ufo_LDFLAGS              += -lws2_32 -lwinmm -lgdi32 -lintl -lfreetype
ufoded_LDFLAGS           += -lws2_32 -lwinmm -lgdi32
testall_LDFLAGS          += -lwinmm -lgdi32
ufo2map_LDFLAGS          += -lwinmm
ufomodel_LDFLAGS         += -lwinmm
uforadiant_LDFLAGS       += -lglib-2.0 -lgtk-win32-2.0 -lgobject-2.0

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Crosscompiling from Linux for Windows
« Reply #11 on: September 22, 2010, 06:37:53 pm »
there is still a problem in the makefiles about linking, even if i only type "make ufo" the game.so/dll is linked again.

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
Re: Crosscompiling from Linux for Windows
« Reply #12 on: September 23, 2010, 12:14:29 pm »
you should add your the mingw-cross-env bin dir to your path then you don't have to patch the makefiles (see Makefile.local)

about the missing libs for mingw - that should not be added like this but like this:
Code: [Select]
ufo_LDFLAGS              += -lws2_32 -lwinmm -lgdi32 -lintl -lfreetype
ufoded_LDFLAGS           += -lws2_32 -lwinmm -lgdi32
testall_LDFLAGS          += -lwinmm -lgdi32
ufo2map_LDFLAGS          += -lwinmm
ufomodel_LDFLAGS         += -lwinmm
uforadiant_LDFLAGS       += -lglib-2.0 -lgtk-win32-2.0 -lgobject-2.0

I prefer to keep isolated a program I use to get a x-compiled binary from a x-compiled binary itself but you're right... keeping everythin in $PATH is a lot easier to manage!
Also if I don't add -lstdc++ in uforadiant_LDFLAGS I get a very long list of errors as shown in this attachment

Offline MarcoBi

  • Rookie
  • ***
  • Posts: 19
    • View Profile
[Resolved] Re: Crosscompiling from Linux for Windows
« Reply #13 on: September 25, 2010, 02:32:01 pm »
well - i don't know about that linking problem - maybe add the -lwinmm stuff to build/plattform_specific.mk

it would be very nice if you could test the patch for the new build system with mingw-cross-env. the patch is at http://mattn.ninex.info/files/newbuildsystem.diff

OK, the new build system now works for me.
Just for reference:
- build shared GTK
- add -lstdc++ for uforadiant & uforadiant-brushexport

Now I only need to find how to compile maps and to find a way to package everything!
« Last Edit: September 26, 2010, 10:13:03 am by MarcoBi »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: [RESOLVED] Crosscompiling from Linux for Windows
« Reply #14 on: September 25, 2010, 02:35:15 pm »
what is -lrtmp?