Jump to content
  • Advertisement
Sign in to follow this  
jmakitalo

Cross-compiling an SDL based program under Ubuntu Linux

This topic is 2802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently developing a simple OpenGL and SDL based 3D engine/game on Ubuntu Linux.
the code has dependencies to following libraries


SDL
DevIL
OpenGL
GLEW
OpenAL
ALUT
LibConfig++
Freetype
LibFTGL
SDL_net

The code is compiled with g++ on Ubuntu and I want to be able to compile it also as Windows executeable.

I'm quite sure that they are cross-platform. Well, OpenGL surely is, but I'm not sure if all the libraries have out-of-the-box cross-platform support.
It seems that most of them have .lib files for MSVC++, but I would rather not use it. One option would be to use Dev-C++ on Windows, but it uses
the .a library files, and it seems that these are not usually available.

The best option for me would be to cross-compile on Ubuntu to produce an .exe file to be ran on Windows. How demanding task would this be?
Does anyone have experience in cross-compiling with any of the above-mentioned libraries?

I have no experience in cross-compilation, but would I have to use the MinGW to compile the above libraries from their sources (maybe not all of them like OpenGL)?

Share this post


Link to post
Share on other sites
Advertisement
well, I have never done cross compilation myself, but I imagine you'd have to build all the libraries for the other platforms first, and then basically have another build chain for each platform, which links agains the specific libs. I am not sure about windows specific headers and things like that though, but I would also be greatly interested in hearing something about that!
SDL, Devil, opengl, openal, alut, glew, freetype and sdl_net are available for windows afaik. not sure about the rest.

Share this post


Link to post
Share on other sites
I followed the instructions from this sight and it worked out great. I can produce Windows executables on my Linux box.

The programs I've written depend on all kinds of libraries. I tend to keep around the following .dlls for my Windows builds.

freetype6.dll libogg-0.dll libvorbis-0.dll SDL_image.dll smpeg.dll
glut32.dll libpng12-0.dll libvorbisfile-3.dll SDL_mixer.dll zlib1.dll
jpeg.dll libtiff-3.dll SDL.dll SDL_ttf.dll

Hope the link is helpful. Good luck.

Share this post


Link to post
Share on other sites
Ok it seems that SDL with net, image and ttf is amenable to easy cross-compilation. Is SDL_ttf good/fast compared
to FTGL? How does DevIL compare to SDL_image? I really should have thought of this cross compilation issue
before starting to use all these non SDL libraries.

Share this post


Link to post
Share on other sites
I was able to setup the SDL cross-compilation. I tried to compile a simple NeHe OpenGL tutorial, which used SDL, but I was not able to link
with OpenGL libraries. I guess I need to add some library paths, but not sure. For windows, the opengl library is AFAIK libopengl32.lib. How to
link to this? Just -llibopengl32?

Share this post


Link to post
Share on other sites
Here's the makefile I'm using right now.

#make win=1 to use cross compiler
#make to make for linux
#make release=1 to use release compile flags
# else use debug flags

# Specify the main target
TARGET := zakes
# Which directories contain source files
DIRS := src/core \
src \
src/tinyxml


# Which libraries are linked
LIBS := SDL_ttf SDL_image SDL_mixer z
# Dynamic libraries
DLIBS :=
#back up directory
BACKUP_DIR := backup
#directory for windows .exe. all the .dlls should be in here
WINDIR := win

COMPILER_FLAGS :=

ifdef release
COMPILER_FLAGS = -O3
else
COMPILER_FLAGS = -g -Wall
endif

ifdef win # windows flags
SDL_FLAGS = `i586-mingw32msvc-sdl-config --cflags`
SDL_LIBS = `i586-mingw32msvc-sdl-config --libs`
OPENGL_LIBS = -lopengl32 -lglu32
CC=i386-mingw32-g++ $(COMPILER_FLAGS)
TARGET:= $(WINDIR)/$(TARGET).exe
else # nix flags
SDL_FLAGS = `sdl-config --cflags`
SDL_LIBS = `sdl-config --libs`
OPENGL_LIBS = -lX11 -lGL -glut -lGLU
CC=g++ $(COMPILER_FLAGS)
endif


CCPARAM := $(SDL_FLAGS)
LDPARAM := $(SDL_LIBS) $(OPENGL_LIBS)

# Add directories to the include and library paths
INCPATH := include \
include/tinyxml \
include/core


LIBPATH :=

# Which files to add to backups, apart from the source code
EXTRA_FILES := Makefile README.txt

# The compiler


# Where to store object and dependancy files.
STORE := objs
# Makes a list of the source (.cpp) files.
SOURCE := $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.cpp))
# List of header files.
HEADERS := $(foreach DIR,$(INCPATH),$(wildcard $(DIR)/*.h))
# Makes a list of the object files that will have to be created.
OBJECTS := $(addprefix $(STORE)/, $(SOURCE:.cpp=.o))
# Same for the .d (dependancy) files.
DFILES := $(addprefix $(STORE)/,$(SOURCE:.cpp=.d))

# Specify phony rules. These are rules that are not real files.
.PHONY: clean backup dirs zip

# Main target. The @ in front of a command prevents make from displaying
# it to the standard output.
$(TARGET): dirs $(OBJECTS)
@echo Linking $(TARGET).
@$(CC) -o $(TARGET) $(OBJECTS) $(LDPARAM) $(foreach LIBRARY, \
$(LIBS),-l$(LIBRARY)) $(foreach LIB,$(LIBPATH),-L$(LIB))

# Rule for creating object file and .d file, the sed magic is to add
# the object path at the start of the file because the files gcc
# outputs assume it will be in the same dir as the source file.
$(STORE)/%.o: %.cpp
@echo Creating object file for $*...
@$(CC) -Wp,-MMD,$(STORE)/$*.dd $(CCPARAM) $(foreach INC,$(INCPATH),-I$(INC))\
$(foreach MACRO,$(MACROS),-D$(MACRO)) -c {:content:}lt; -o $@
@sed -e '1s/^\(.*\)$/$(subst /,\/,$(dir $@))\1/' $(STORE)/$*.dd > $(STORE)/$*.d
@rm -f $(STORE)/$*.dd

# Empty rule to prevent problems when a header is deleted.
#%.hpp: ;

# Cleans up the objects, .d files and executables.
clean:
@echo Making clean.
@-rm -rf $(STORE)
@-rm -f $(WINDIR)/$(TARGET).exe win/*.txt
# -rm -rf $(foreach DIR,$(DIRS),$(STORE)/$(DIR)/*.d $(STORE)/$(DIR)/*.o)
@-rm -f $(TARGET)

# Backup the source files.
backup:
@-if [ ! -e ${BACKUP_DIR} ]; then mkdir ${BACKUP_DIR}; fi;
# @zip ${BACKUP_DIR}/backup_`date +%d-%m-%y_%H.%M`.zip $(SOURCE) $(HEADERS) $(EXTRA_FILES)
@tar czf ${BACKUP_DIR}/$(TARGET)-`date +%d-%m-%y_%H.%M`.tgz $(SOURCE) $(HEADERS) $(EXTRA_FILES)
@echo "Backed up."

# Zip up the windows stuff
zip:
@mkdir -p $(TARGET)
@mv README.txt ./$(TARGET)
@mv $(WINDIR)/* ./$(TARGET)
@mkdir ./$(TARGET)/logs
@mv data ./$(TARGET)
@zip -r $(TARGET)-`date +%d-%m-%y_%H.%M`.zip $(TARGET)
@mv $(TARGET)/*.dll $(WINDIR)
@mv $(TARGET)/*.exe $(WINDIR)
@mv $(TARGET)/data ./
@mv $(TARGET)/README.txt ./
@rm -rf $(TARGET)
@echo "Zipped up."

# Create necessary directories
dirs:
@-if [ ! -e $(STORE) ]; then mkdir -p $(STORE); fi;
@-$(foreach DIR,$(DIRS), if [ ! -e $(STORE)/$(DIR) ]; \
then mkdir -p $(STORE)/$(DIR); fi; )
@-if [ ! -e $(WINDIR) ]; then mkdir -p $(WINDIR); fi;

# Includes the .d files so it knows the exact dependencies for every
# source.
-include $(DFILES)


In addition I also added the following paths to my $PATH. These are the directories installed by running that sdl-cross-install.sh script.

/mingw32/bin
/mingw32/SDL/bin

Share this post


Link to post
Share on other sites
Ok, I'll bite: why are you seemingly willing to use Dev-C++ and not Visual C++? It would make your life a heck of a lot easier.

Share this post


Link to post
Share on other sites

Ok, I'll bite: why are you seemingly willing to use Dev-C++ and not Visual C++? It would make your life a heck of a lot easier.


Firstly, MSVC++ costs, at the moment I have come along just fine with free software. Dev-C++ would use the same

compiler g++ as I use in Ubuntu and I've learned that the MSVC++ is loose with C++ standards, so I do not give
much faith to it. Cross-compilation under linux would be most convenient, if setting it up wouldn't be so inconvenient.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!