aliens

Author Topic: Building OpenXCom on Windows with Mingw  (Read 16538 times)

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Building OpenXCom on Windows with Mingw
« on: August 25, 2013, 07:50:48 pm »
Hello buddies,

As I try to see what I can do to modify OpenXCom, I'm trying to build it on my computer. I am using Mingw. (Please do not ask me to install what everybody seems to want me to install, because this EDI sucks).

I downloaded SDL for developers and built a small test program with SDL.
I downloaded SDL_mixer source and 32-bit DLL and built a small test program with SDL_mixer and SDL.
I downloaded SDL_image source and 32-bits DLL and built a small test program with SDL_image and SDL.

I downloaded SDL_gfx, tried to build it with the makefile for MinGW, had problems, found this, built it and built a small test program with SDL_gfx and SDL.

I downloaded yaml-cpp (version 0.5.1) and cmake, tried to use cmake to generate makefile, realized boost was necessary, downloaded boost, tried to build boost, failed to build boost, realized yaml-cpp would perhaps only need boost header files, tried to generate makefile for dynamic build, had problems, found this, decided to build a static library, generated makefile, built yaml-cpp, built a small test program with yaml-cpp. (I have headaches now)

Now, I'm trying to build OpenXCom itself, and of course, it doesn't work.

This is the makefile I have written:
Code: [Select]
PROG=OpenXCom

MINGW=i686-w64-mingw32-

SRC=$(wildcard src/*.cpp src/*/*.cpp src/*/*/*.cpp)
OBJ=$(SRC:.cpp=.o)
BIN=bin\$(PROG).exe

WINVER=0x0400
CC=$(MINGW)g++
CFLAGS=-DWINVER=$(WINVER) -I..\SDL-1.2.15\include\SDL -I..\SDL_mixer-1.2.12 -I..\SDL_image-1.2.12 -I..\SDL_gfx-2.0.24 -I..\yaml-cpp-0.5.1\include -I..\boost_1_54_0
LDFLAGS=-L..\SDL-1.2.15\lib -L..\yaml-cpp-0.5.1\build -lmingw32 -lSDLmain ..\SDL-1.2.15\bin\SDL.dll ..\SDL_mixer-1.2.12\bin\SDL_mixer.dll ..\SDL_image-1.2.12\bin\SDL_image.dll ..\SDL_gfx-2.0.24\bin\SDL_gfx.dll -lyaml-cpp

.PHONY:all compile depends mrproper clean rebuild

all:compile

compile:$(BIN)

depends:
AppDep -n -l "# Dependencies" makefile
for %%i in ($(SRC:.cpp=)) do $(CC) $(CFLAGS) -MM "%%i.cpp" -MT "%%i.o" >> makefile

$(BIN):$(OBJ)
$(CC) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS)

%.o:%.cpp
$(CC) $(CFLAGS) -o $@ -c $<

mrproper:clean
for %%i in ($(BIN)) do if exist "%%~fi" del "%%~fi"

clean:
for %%i in ($(OBJ)) do if exist "%%~fi" del "%%~fi"

rebuild:mrproper all

Compilation just (seems to) works fine.
But at the very last step, linker fails and give the following errors:
Code: [Select]
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x240): undefined reference to `_imp__glGenTextures@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x26d): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x393): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x4c1): undefined reference to `_imp__glBindTexture@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x4ee): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x60a): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x63e): undefined reference to `_imp__glPixelStorei@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x66b): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x787): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x7f3): undefined reference to `_imp__glTexImage2D@36'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x820): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x93c): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xbd8): undefined reference to `_imp__glClearColor@16'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xbe9): undefined reference to `_imp__glClear@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xbf3): undefined reference to `_imp__glFlush@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xc4b): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xe8b): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xfb1): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0xfeb): undefined reference to `_imp__glTexParameteri@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1016): undefined reference to `_imp__glTexParameteri@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1048): undefined reference to `_imp__glTexParameteri@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1084): undefined reference to `_imp__glTexParameteri@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x10b1): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x11cd): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x11f7): undefined reference to `_imp__glMatrixMode@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x120b): undefined reference to `_imp__glLoadIdentity@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1269): undefined reference to `_imp__glOrtho@48'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1290): undefined reference to `_imp__glViewport@16'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x12a1): undefined reference to `_imp__glMatrixMode@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x12ab): undefined reference to `_imp__glLoadIdentity@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x12cb): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x13e7): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x145f): undefined reference to `_imp__glPixelStorei@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x148c): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x15a8): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x161c): undefined reference to `_imp__glTexSubImage2D@36'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x16bb): undefined reference to `_imp__glBegin@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x16d6): undefined reference to `_imp__glTexCoord2f@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x16f6): undefined reference to `_imp__glVertex3i@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x171b): undefined reference to `_imp__glTexCoord2f@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x173a): undefined reference to `_imp__glVertex3i@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x175f): undefined reference to `_imp__glTexCoord2f@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1780): undefined reference to `_imp__glVertex3i@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x17b1): undefined reference to `_imp__glTexCoord2f@8'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x17d1): undefined reference to `_imp__glVertex3i@12'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x17db): undefined reference to `_imp__glEnd@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x17fb): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1917): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x193a): undefined reference to `_imp__glFlush@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1964): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x1a80): undefined reference to `_imp__glGetError@0'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x245a): undefined reference to `_imp__glDisable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x246b): undefined reference to `_imp__glDisable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x247c): undefined reference to `_imp__glDisable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x248d): undefined reference to `_imp__glDisable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x249e): undefined reference to `_imp__glDisable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x24af): undefined reference to `_imp__glEnable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x24c0): undefined reference to `_imp__glEnable@4'
src/Engine/OpenGL.o:OpenGL.cpp:(.text+0x275a): undefined reference to `_imp__glDeleteTextures@8'
d:/prog/i686-w64-mingw32-gcc-4.5.4-release-win32_rubenvb/bin/../lib/gcc/i686-w64-mingw32/4.5.4/../../../../i686-w64-mingw32/bin/ld.exe: src/Engine/OpenGL.o: bad reloc address 0xbc in section `.rdata'
collect2: ld returned 1 exit status
makefile:25: recipe for target `bin\OpenXCom.exe' failed
gmake: *** [bin\OpenXCom.exe] Error 1

What am I doing wrong? (except refusing to install you-know-what).
Please, tell me I'm just missing something easy to repair...
Do I miss an openGL library?
« Last Edit: August 27, 2013, 12:30:26 am by Juju Dredd »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2161
    • View Profile
Re: Building OpenXCom on Windows with Mingw
« Reply #1 on: August 25, 2013, 08:09:46 pm »
You need to set up OpenGL with MingW: https://www.opengl.org/wiki/MinGW
It looks like you are forgetting to link the OpenGL libraries: "-lglu32 -lopengl32"

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: Building OpenXCom on Windows with Mingw
« Reply #2 on: August 25, 2013, 08:16:38 pm »
You need to set up OpenGL with MingW: https://www.opengl.org/wiki/MinGW
It looks like you are forgetting to link the OpenGL libraries: "-lglu32 -lopengl32"

If OpenGL is necessary (and the errors I have seems to indicate it is) then you are perfectly right, I have installed no OpenGL library at all. Shouldn't it be mentioned in this url?

I'm going to download OpenGL then check I can use it with MinGW. I have already done that on another PC so I think I should succeed.

Edit: By the way, what "-w" and "-std" options should I use with g++?
« Last Edit: August 25, 2013, 08:23:08 pm by Juju Dredd »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2161
    • View Profile
Re: Building OpenXCom on Windows with Mingw
« Reply #3 on: August 25, 2013, 09:16:45 pm »
Most compilers/systems come with OpenGL, which is why it isn't mentioned (it would've worked off the bat with you-know-what ;)).

Anyways the wiki is open so feel free to update it if you find it inaccurate. I would recommend using the Makefiles in the source code as a basis to see what flags we normally use with g++.

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: Building OpenXCom on Windows with Mingw
« Reply #4 on: August 25, 2013, 09:44:11 pm »
Most compilers/systems come with OpenGL, which is why it isn't mentioned (it would've worked off the bat with you-know-what ;)).

Anyways the wiki is open so feel free to update it if you find it inaccurate. I would recommend using the Makefiles in the source code as a basis to see what flags we normally use with g++.

My bad, I have found opengl headers in my MinGW directories, MinGW do include OpenGL. I am currently checking glut.

Edit: this is really strange, but I have not install glut and the compilation works, provided I had the linker options you said. I also must add -lshellapi. The game launch, do you think it could crash because of an incomplete compilation or something like that?

Edit2: linking work without -lglu32. Are you sure glut is used, or did you add it by force of habit?

Edit3: I'm not familiar with this forum, is there a way to add a "resolved" tag or something?
« Last Edit: August 25, 2013, 10:12:00 pm by Juju Dredd »

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: [resolved] Building OpenXCom on Windows with Mingw
« Reply #5 on: August 26, 2013, 02:03:04 pm »
I have look into provided makefiles and there is one thing I don't understand: what does the -include pch.h stand for? Do I have to use it or not? I have tried the two ways, I cannot see what is the difference.

Edit: I have updated the wiki in case someone other than me try to build OpenXcom with the same tools.
« Last Edit: August 26, 2013, 05:41:24 pm by Juju Dredd »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2161
    • View Profile
Re: Building OpenXCom on Windows with Mingw
« Reply #6 on: August 26, 2013, 08:36:31 pm »
My bad, I have found opengl headers in my MinGW directories, MinGW do include OpenGL. I am currently checking glut.

Edit: this is really strange, but I have not install glut and the compilation works, provided I had the linker options you said. I also must add -lshellapi. The game launch, do you think it could crash because of an incomplete compilation or something like that?

Edit2: linking work without -lglu32. Are you sure glut is used, or did you add it by force of habit?
I just took it out of Google. :P I guess it doesn't use GLUT, otherwise the compilation would fail.

I have look into provided makefiles and there is one thing I don't understand: what does the -include pch.h stand for? Do I have to use it or not? I have tried the two ways, I cannot see what is the difference.

Edit: I have updated the wiki in case someone other than me try to build OpenXcom with the same tools.
The "-include pch.h" is for using the precompiled header to speed up compile time, if you don't have it set up you don't need to use it.

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: [resolved] Building OpenXCom on Windows with Mingw
« Reply #7 on: August 26, 2013, 09:43:18 pm »
Okay, thanks a lot for your help.
I'm now trying to see if I can build some sort of custom build.

I have just realized, I believe I created this topic in the wrong forum, you could perhaps move it to the "build & ports" forum...

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: Building OpenXCom on Windows with Mingw
« Reply #8 on: August 27, 2013, 12:37:26 am »
I have another problem: I tried to use winres to incorporate resources, but I had to update src/resource.h and src/OpenXcom.rc because they weren't ANSI text files, they were UTF-16LE (according to Notepad++) and I found no way to use them other than changing their character set to ANSI. Is the use of this character set voluntary and relevant? I see only standard ascii characters in this files...

Online Yankes

  • Commander
  • *****
  • Posts: 3248
    • View Profile
Re: Building OpenXCom on Windows with Mingw
« Reply #9 on: August 27, 2013, 12:56:47 am »
I dont see any thing that is useful in "src/OpenXcom.rc", I use too MinGW and I dont include this files. This is form VS2008 & VS2010.
You should skip them.

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2161
    • View Profile
Re: Building OpenXCom on Windows with Mingw
« Reply #10 on: August 27, 2013, 02:42:21 am »
I have another problem: I tried to use winres to incorporate resources, but I had to update src/resource.h and src/OpenXcom.rc because they weren't ANSI text files, they were UTF-16LE (according to Notepad++) and I found no way to use them other than changing their character set to ANSI. Is the use of this character set voluntary and relevant? I see only standard ascii characters in this files...
I doubt it matters, they are just source files generated by VS.

I dont see any thing that is useful in "src/OpenXcom.rc", I use too MinGW and I dont include this files. This is form VS2008 & VS2010.
You should skip them.
OpenXcom.rc/resource.h handle the Windows embedded application icon / version information. You can ignore them if you want but they make it look more like a "proper" program.

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: Building OpenXCom on Windows with Mingw
« Reply #11 on: August 27, 2013, 09:28:52 pm »
I dont see any thing that is useful in "src/OpenXcom.rc", I use too MinGW and I dont include this files. This is form VS2008 & VS2010.
You should skip them.

As explains SupSuperGod, without resources:


and with resources:

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: Building OpenXCom on Windows with Mingw
« Reply #12 on: August 27, 2013, 11:17:33 pm »
I have tried upgrading MingW32 to the last release version I could find, the problem was the same.
I tried windres option "--codepage" it seems to ignore it.
Only solution seems to be converting OpenXcom.rc and resource.h. I recorded it in the wiki page for compiling with MinGW.

Perhaps MinGW64 does not have the same flaw, but I have found no SDL developer pack for MinGW with a 64bits build. Guess I could build it using CMake, but I will try that another day.

@Yankes, as you use MinGW, could you please take a look on the wiki page just to give me your advice?
« Last Edit: August 27, 2013, 11:23:25 pm by Juju Dredd »

Online Yankes

  • Commander
  • *****
  • Posts: 3248
    • View Profile
Re: Building OpenXCom on Windows with Mingw
« Reply #13 on: August 28, 2013, 01:02:23 am »
I use MinGW (g++ 4.7 niXman build 32bit) with NetBeans IDE. I dont use any makefile form OpenXcom only one generated by NB by including all source files from OpenXcom. My building of openxcom is bit messy, I added whole ymal-cpp src to project because I couldnt find working binary with my MinGW. I add too WinMain.cpp from SDL to project because including lib SDLmain didnt work.

to linker I add additional switchs:
-mwindows -lmingw32 -lshlwapi -lws2_32 -lopengl32 -lglu32

And after that I can compile OpenXcom without probem, but I dont know if this is good example how to do it :)

Offline Juju Dredd

  • Captain
  • ***
  • Posts: 68
    • View Profile
    • My gamer website (french)
Re: Building OpenXCom on Windows with Mingw
« Reply #14 on: August 28, 2013, 01:24:56 am »
Oh, you do it a way rather different from mine...