OpenXcom Forum

Contributions => Programming => Topic started by: battlesquid on June 30, 2010, 12:59:00 am

Title: Compiling on Cygwin
Post by: battlesquid on June 30, 2010, 12:59:00 am
I'm trying to make this project without using visual studio (just not interested in using that), but I'm having some problems. I fetched the code, installed SDL (devel) to resolve the sdl-config dependency in openxcom Makefile.

The Makefile somehow doesn't expand backticks for me using borland make 5.2 in cygwin. I got the following error:


$ make
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
        `sdl-config --libs` -lSDL_gfx -lSDL_mixer -o openxcom
'`sdl-config' is not recognized as an internal or external command,
operable program or batch file.

** error 1 ** deleting openxcom


so I edited those lines using the output I got into:


CXXFLAGS = -Wall -O2 -I/usr/local/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main
LDFLAGS = -L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mwindows -lSDL_gfx -lSDL_mixer


and got rid of that, but still no go:


$ make
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
        L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mwindows -lSDL_gfx -lSDL_mixer -o openxcom
Fatal: Unable to execute command: L/usr/local/lib


It seems to me that at the line

$(CXX) $(LDFLAGS) -o $(PROG) $(OBJS)

CXX is not set, so it tries to execute a command  L/usr/local/lib

I'm not familiar with Makefiles so I don't know what's wrong.
Title: Compiling on Cygwin
Post by: SupSuper on June 30, 2010, 01:29:03 am
I'm not familiar with cygwin so I don't know why it wouldn't have the CXX variable set by default, but just putting "CXX = g++" yourself at the top of the makefile should fix it.
Title: Compiling on Cygwin
Post by: Eeyoocah5Moh on June 30, 2010, 05:00:04 am
The Makefile somehow doesn't expand backticks for me using borland make 5.2 in cygwin.

Why you are using borland make? You should use GNU make. AFAIK there is GNU make included in cygwin, you should just install it.
Title: Compiling on Cygwin
Post by: battlesquid on June 30, 2010, 10:08:34 pm
I tried to set CXX=g++ in the shell however had to do it inside the Makefile (probably starts a new subshell?)
I haven't installed GNU make, simply because then I have to upgrade cygwin. I will if I have to though. Right now (after setting CXX=g++) I get:

$ make
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
        g++ -L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mwindows -lSDL_gfx -lSDL_mixer -o openxcom
c:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lSDLmain
collect2: ld returned 1 exit status

** error 1 ** deleting openxcom


as you can see I have installed mingw (wtf is up with the relative path there... maybe that's a clue), and it reports that it cannot fin -lSDLmain for some reason.
Title: Compiling on Cygwin
Post by: SupSuper on July 01, 2010, 04:11:17 am
Doesn't look like you installed SDL properly. Check if the libraries are in the respective folders and the paths are right, maybe you forgot a step. These links might help:

https://www.libsdl.org/extras/win32/cygwin/README.txt
https://www.devolution.com/pipermail/sdl/2002-February/042594.html

And remember you won't need just SDL (https://www.libsdl.org/download-1.2.php) but also SDL_mixer (https://www.libsdl.org/projects/SDL_mixer/) and SDL_gfx (https://www.ferzkopp.net/joomla/content/view/19/14/).
Title: Compiling on Cygwin
Post by: battlesquid on July 02, 2010, 12:09:28 am
Probably SDL isn't installed properly. I started from scratch and followed the guide. At make i get an error


asn@dingo ~/dev/sdl/SDL-1.2.14
$ make
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
Error makefile 77: Command syntax error
*** 1 errors during make ***


I suspect this has something to do with not using GCC so I'll try installing that first.

asn@dingo ~/dev/sdl/SDL-1.2.14
$ type make
make is hashed (/cygdrive/c/Borland/BCC55/Bin/make)

Title: Compiling on Cygwin
Post by: battlesquid on July 02, 2010, 01:15:43 am
Installing GNU make and reinstalling SDL made progress, thankfully. Still I get an error and a whole lot of warnings. The last lines of output:


...

Music.h:35: error: ISO C++ forbids declaration of `Mix_Music' with no type
Music.h:35: error: expected `;' before '*' token

...
Bar.h:65:7: warning: no newline at end of file
In file included from BaseInfoState.h:30,
                 from BasescapeState.h:32,
                 from GeoscapeState.h:36,
                 from NewGameState.h:28,
                 from MainMenuState.h:28,
                 from AbandonGameState.h:29,
                 from AbandonGameState.cpp:19:
TextEdit.h:75:7: warning: no newline at end of file
AbandonGameState.cpp:90:2: warning: no newline at end of file
make: *** [AbandonGameState.o] Error 1


The full output here https://pastebin.ca/1893077 (https://pastebin.ca/1893077)


The warnings are probably nothing to worry about, but the error I have to sort out. Maybe this error is related to SDL_mixer... The dependency resolving continues... Tomorrow.
Title: Compiling on Cygwin
Post by: SupSuper on July 02, 2010, 02:36:27 am
Yeah all the errors are from SDL_mixer and SDL_gfx missing, once you sort those out you should be settled.
Title: Compiling on Cygwin
Post by: battlesquid on July 02, 2010, 09:50:51 pm
I've installed latest SDL_mixer and SDL_gfx and got no errors doing so. Still I get an error making openxcom https://pastebin.com/huYsmmHG (https://pastebin.com/huYsmmHG)

There's no lines other than the last one saying error. They're all warnings it appears. Did I miss something? What can I do to find the error?

--Edit--
The only thing I can think of (and maybe that's enough)

Screen.h:23:26: SDL_rotozoom.h: No such file or directory
SDL_gfxPrimitives.h: No such file or directory


Those two files not found is probably a bad thing. But why wouldn't it find them...
Title: Compiling on Cygwin
Post by: SupSuper on July 03, 2010, 01:16:22 am
It's still not finding SDL_gfx. These are the steps for compiling it on Linux from the SDL_gfx source folder:

Code: [Select]
./autogen.sh    (optional)
./configure
make
make install
ldconfig

I assume the same works on cygwin. Make sure the library is in /usr/local/lib and the include files are in /usr/local/include (or equivalent in cygwin), they're the ones popping up on the error messages.
Title: Compiling on Cygwin
Post by: battlesquid on July 03, 2010, 05:12:15 pm
Everything up to ldconfig went fine, but it cannot find ldconfig. I did a search for cygwin + ldconfig and here it says it isn't needed under windows:
https://www.cygwin.com/ml/cygwin/2002-03/msg00798.html (https://www.cygwin.com/ml/cygwin/2002-03/msg00798.html)

As the first step was marked 'optional' I thought I had made no progress with this, but apparently running autogen was not optional for me, because I made a lot of progress. It looked like it would be a complete build, but unfortunately not there yet. The output from make was so long it used up my screen buffer and some was cut off. I searched through it for 'error' and 'no such file' but got no hits. The last two lines were:

collect2: ld returned 1 exit status
make: *** [openxcom] Error 1


I don't know what collect2 means. Everything else seems to be warnings, but it's hard to tell since the logging is so flooded with warnings. How can I adjust verbosity or ignoring warnings with make? I didn't find anything applicable with make --help...
Title: Compiling on Cygwin
Post by: michal on July 03, 2010, 05:31:56 pm
Maybe you will have more luck with mingw + msys (this should contain make). It's alternative solution to cygwin. Unfortunately i don't have experience in both solutions, so i can't tell if it's better or if it help you.

https://www.mingw.org/
Title: Compiling on Cygwin
Post by: battlesquid on July 03, 2010, 05:42:44 pm
I did some research on the resulting objects and it seems although I got an error at the end, there were as many .o files as .h files which makes me think make did what it was supposed to
https://imagebin.ca/img/bPVxkQg.gif (https://imagebin.ca/img/bPVxkQg.gif)

So how do I go from these object files into OpenXcom.exe?

Running gcc *.o -o OpenXcom.exe gave me 'undefined reference' all over the place

main.o:main.cpp:(.text+0x63c): undefined reference to `std::ios_base::Init::Init()'
main.o:main.cpp:(.text+0x658): undefined reference to `std::ios_base::Init::~Init()'
main.o:main.cpp:(.gcc_except_table+0x28): undefined reference to `typeinfo for char*'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):(.text+0xa9): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status


...but that might not be the right way to do it anyway
Title: Compiling on Cygwin
Post by: SupSuper on July 04, 2010, 09:55:46 pm
I did some research on the resulting objects and it seems although I got an error at the end, there were as many .o files as .h files which makes me think make did what it was supposed to
https://imagebin.ca/img/bPVxkQg.gif (https://imagebin.ca/img/bPVxkQg.gif)

So how do I go from these object files into OpenXcom.exe?

Running gcc *.o -o OpenXcom.exe gave me 'undefined reference' all over the place

main.o:main.cpp:(.text+0x63c): undefined reference to `std::ios_base::Init::Init()'
main.o:main.cpp:(.text+0x658): undefined reference to `std::ios_base::Init::~Init()'
main.o:main.cpp:(.gcc_except_table+0x28): undefined reference to `typeinfo for char*'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):(.text+0xa9): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status


...but that might not be the right way to do it anyway
The .o files mean the Makefile managed to compile all the individual source files (so all the include files are correct), but failed at the final step where it puts everything together into an executable (you didn't show any errors from there) since you mention there isn't one.

The errors you got above are because you're supposed to use g++ not gcc (if that doesn't help you might also need to add -lstdc++ afterwards), make sure you have that properly setup. In any case the Makefile should already include the full proper command.


Also if you don't mind me asking, if you're not familiar with compiling and debugging, why are you trying to compile OpenXcom yourself? There's pre-compiled Downloads freely available if you just wanna try it out.
Title: Compiling on Cygwin
Post by: battlesquid on July 05, 2010, 10:06:33 pm
Man, compiling C++ is a lot of work... As you probably have guessed I'm actually not a C++ developer, but a Java developer. Still I'd like to be able to build the project if not to contribute anything immediately. I have tried the precompiled distribution and it runs fine :)

I was hoping this make business would come to an end soon enough, but I realize now that's probably not going to happen  :( So I understand if you don't want to spend more time helping out a beginner. It's unlikely I'd be able to contribute even something small in a long time anyway. But if there's time to help me out, I'd apprechiate it. Learning C++ with a project that's interesting for me and at the same time quite young seems appealing to me. Running g++ in stead of gcc resulted in less "undefined reference" lines. When running make now I get https://pastebin.com/Y1dFQihP (https://pastebin.com/Y1dFQihP) which is fewer lines than last time I think. So it seems now it can't find SDL_mixer and SDL_gfx even though they are referenced at the first line as you can see. I believe I have installed those as described earlier, but apparently something is not right.
Title: Compiling on Cygwin
Post by: SupSuper on July 06, 2010, 05:14:00 am
No problem, I was just curious, and I'm not too familiar with cygwin myself so you caught me off-guard. ;)

Aside from double-checking the library files, my last suggestion would be to try and recompile it from scratch (use "make clean" to delete all the object files and then try "make" again) in case your previous failed attempts are messing it up.
Title: Compiling on Cygwin
Post by: battlesquid on July 07, 2010, 03:43:06 pm
I'm not the only one with this problem it seems. I did the same as this guy https://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-May/050095.html (https://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-May/050095.html) and was able to get the linked file. As I expected from the other guys post, running it resulted in an error that did't really tell me anything:
 
(https://imagebin.ca/img/jcDgOrx.png)

So I closed that useless window and had a look at the directory where I found stdout.txt to my surprise telling me something I could understand :) "Loading resources..." So that had to be it couldn't find the DATA dir. I would prefer if the program had told me this, but it didn't take long to find that file. Now the precompiled binary distribution comes with some requirements like DLL files and DATA dir needs to be in the same folder. So I tried to add those to see if I could get some more feedback. Not only feedback here, the game is up and running!
 :o

So, here's my cygwin Makefile in case anyone else wants to compile the project under cygwin: https://pastebin.com/5TxMiY7z (https://pastebin.com/5TxMiY7z)
There's only one thing that differ from the original Makefile: the libraries have to be specified after the object files:

$(CXX) $(OBJS) $(LDFLAGS) -o $(PROG)

Title: Compiling on Cygwin
Post by: michal on July 07, 2010, 05:53:48 pm
Good to know, you managed to compile everything.

I have and idea for first feature you could implement ;) At game starting check if DATA contains ufo game. If not, show some message explaining that user needs to put ufo contents in DATA directory.
Title: Compiling on Cygwin
Post by: SupSuper on July 07, 2010, 09:18:43 pm
Glad you got it working, I'll remember to fix the makefile. Funny how the weirdest things can cause problems. You probably also needed the SDL DLLs to run the game since you're building for Windows.

As for the DATA thing, I will admit that the error handling at this point is vague to nearly non-existant, it's not really a priority, but you should at least see an error message if the game fails to load (or at least I do):
(https://i6.photobucket.com/albums/y237/supsuper/openxcom_error.png)

Yes it's not very descriptive or very flashy, but it does the job, and I would expect people to be able to read a few instructions. The current builds aren't intended for the average user after all. ;) Of course I have no idea what'll happen if your computer decides to not show the console. The message might jump into an abyss. The program might just crash. Who knows.

But I can't use anything platform-specific like MessageBox() either. I'd have to render a message myself onto the SDL screen. Problem is, if the game fails to load the resources, there aren't even any palettes or fonts to draw a message! I'd need some kind of failsafe resources to manage to scribble a desperate cry for help on the screen. :P Again, another thing for the TODO list.
Title: Compiling on Cygwin
Post by: battlesquid on July 07, 2010, 10:47:14 pm
I suppose it would be useful to have some basic error handling routines in place. Using some default non-xcom font shouldn't be a problem, the main point is to let the user know what's wrong.

I was just thinking - maybe someone could add the required steps for Cygwin to the https://openxcom.ninex.info/index.php/compiling/ (https://openxcom.ninex.info/index.php/compiling/) page? I'm sure there are others that would like to compile under windows without using VS. And it's easy now that we know how  :D
Title: Re: Compiling on Cygwin
Post by: SupSuper on July 09, 2010, 11:24:01 pm
I suppose it would be useful to have some basic error handling routines in place. Using some default non-xcom font shouldn't be a problem, the main point is to let the user know what's wrong.

I was just thinking - maybe someone could add the required steps for Cygwin to the https://openxcom.ninex.info/index.php/compiling/ (https://openxcom.ninex.info/index.php/compiling/) page? I'm sure there are others that would like to compile under windows without using VS. And it's easy now that we know how  :D
I have split this into a separate thread and might link it up later on the main site like I did for Mac OS. :)