Sign in to follow this  
graveyard filla

compiling my project in Linux

Recommended Posts

hi, i am working on a 2d persistant MORPG. anyway, i want to compile the server on linux. im running on the latest version of Fedora, and using Kdevelop. but i just cant figure out the basics of this.. for example, how do i add a new library to my project? also, what happend to .dll and .lib files? im pretty sure neither of these exist on linux, so what is there replacement? i think its .a and .so, or something like that, but what are the differences exactly, and how do i add one to my project? next, must i build all libraries from scratch now? most libs come with .dll and .lib files, but i dont see any .a or .so files... so i should build the library myself then? how do i set up the compiler to build a library so it gives me the proper output i want? thanks for any help... PS, im a very very big linux newbie, so go easy on the commands and stuff =).

Share this post


Link to post
Share on other sites
You have .a for libraries (an archive, basically a container for a bunch of object files), and .so (shared object) for dynamic link libraries.

I don't like most IDEs, I usually write my makefiles by hand, something like:

program: something.o somethingelse.o
TAB g++ $^ -o$@ -la_library -lanother_library

%.o: %.cpp:
TAB g++ -c $< -o$@


and then just type 'make'. I'm sure whatever KDevelop can do whatever it is you want though, just look around. And the forums ate my whitespace. All well.

Some libraries will come with programs to print out the correct commands to use, with SDL for example you would invoke g++ `sdl-config --libs`.

I'm sure that was confusing. Just ignore me and explore your IDE some more.

Fruny: Edit - actions must be prefixed with a TAB character. make is anal in that respect.

[Edited by - Fruny on February 8, 2005 3:53:13 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla

for example, how do i add a new library to my project?


Depends on how you're using KDevelop. I don't have much experience with it myself - I just wrote a makefile and set all my command-line stuff in there by hand... KDevelop just runs gmake on it.

Quote:
also, what happend to .dll and .lib files? im pretty sure neither of these exist on linux, so what is there replacement? i think its .a and .so, or something like that, but what are the differences exactly, and how do i add one to my project?


If you want to link with libfoo.a or libfoo.so, you add -lfoo to the list of parameters you pass to GCC. It'll automatically pick the dynamic library (.so) if it is available, otherwise, or if you add the -static switch, it'll grab the static library (.a)

Most of the libraries live under /usr/lib.

Quote:
Original post by graveyard filla
next, must i build all libraries from scratch now? most libs come with .dll and .lib files, but i dont see any .a or .so files... so i should build the library myself then? how do i set up the compiler to build a library so it gives me the proper output i want?


In most cases, installing a library from the source can be done in 3 instructions (and some waiting).

./configure (execute the configure script provided by the library developer)
make (builds the library)
make install (put the files in the appropriate locations)

The configure script accepts options regarding where to install the library, and things like that (read the README, INSTALL, CONFIGURE or ... files that should come with the source).

Share this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla
hi,

i am working on a 2d persistant MORPG. anyway, i want to compile the server on linux.


we like clients, too :)

Quote:

im running on the latest version of Fedora, and using Kdevelop. but i just cant figure out the basics of this..

for example, how do i add a new library to my project?


I have never really used kdevelop, so I can't help you with specifics here.

Quote:

also, what happend to .dll and .lib files? im pretty sure neither of these exist on linux, so what is there replacement? i think its .a and .so, or something like that, but what are the differences exactly, and how do i add one to my project?


You are correct, they work similarly to Win32. The ".so" files are dynamic libs (like a DLL), ".a" files are static libs (like a .LIB). As far as adding a library to your project, that will be specific to whatever project management tools you are using (kdevelop in this case). You should probably read the kdevelop docs if this is going to be your chosen tool.



Quote:

next, must i build all libraries from scratch now? most libs come with .dll and .lib files, but i dont see any .a or .so files...


"most libs" will come with a .a or a .so if they are compiled for linux.


Quote:

so i should build the library myself then? how do i set up the compiler to build a library so it gives me the proper output i want?


This depends on what library you are talking about specifically.

EDIT: you guys are quick :)

Share this post


Link to post
Share on other sites
thanks everyone for your replies.

ok, i think i managed to build RakNet. i also believe SDL comes already set up on this distro, so now i only have to build MySQL++.

however, im having some problems. i cant figure out how to add the .a file to the project.. anyone have any clue how to do this in kdevelop?

also, does anyone know how i can specify an "includes directory"? VS.net has this. basically, i specify a folder and the compiler / IDE will check this folder automatically for header files when i #include them.

thanks for any more help.

Share this post


Link to post
Share on other sites
Here's how the whole magic works:

there's /usr/include which has lots of include files.
there's /usr/lib which has lots of library files.

when you compile and install a library, it puts things in /usr/include and /usr/lib.

To include that libraries headers, they're probably installed either in /usr/include itself or a subdir. You include like so (respectively)
#include <include.h>
#include <subdir/include.h>

To link the library, you add -lLIBNAME to the linker line. This is what you'll really look for in kdevelop. Linker options or Additional libraries or something like that. Add -lSDL to get sdl, for example. -lSDL tells the compiler to go find some horrendous file called something like libSDL.0.so.2.0.1 off in /usr/lib someplace, and make your executable dynamically link with that.

If you're targeting fedora for this server, I suggest you first look to see if there are fedora packages for the libraries you use, or already made port of those libraries for fedora (there probably are). Install these and just mark your final server as depending on these other packages, rather than compiling the libraries yourself.

Share this post


Link to post
Share on other sites
thanks for the reply. however im still getting errors about missing header files. i checked usr/include and dont see either RakNet nor MySQL++ header files in here. for Raknet, i just did "make static" and then "make install". for MySQL++ i did "./configure", "make", "su", "make install". this is what the README's told me to do, but im still getting a million errors.

also, i searched for linker options but no luck. about finding Fedora packages, it came with SDL but i couldnt find one for MySQL++ and the RakNet site is down (plus i doubt it would have it anyway).

thanks for any more help.

Share this post


Link to post
Share on other sites
Check /usr/local/include and /usr/local/lib for the files. If they're not ther, try find /usr | grep mysql, which should return all of the mysql-related files (replace "mysql" with whatever you want to look for).

Since you're using fedora, there's a good chance you'll be able to find RPMs (Red Hat Package Manager) for any major library you need. Make sure you also get the developer RPMs as well.

Share this post


Link to post
Share on other sites
thanks! you were right - i found the MySQL++ includes and .a files in the usr/local versions.. still no sign of the RakNet versions though, but im guessing that i have to put them in their myself? still have no clue on why kdevelop is not recognizing any of this though... im starting to think about wussing out and just installing windows 2000 on this box [grin]. although after sitting through the downloading / burning / installing of this four CD monster i really dont want to do that.

Share this post


Link to post
Share on other sites
To make gcc find a directory of header files (on the system, or your own), put on the command line

-I/directory/where/headers/are

and that dir will get searched. Make sure you include files from the dir with

#include <bla>

and not

#include "bla"


When you install libs make sure you install the development lib as well. For instance, if you install libSDL package and want to write programs with SDL, there will almost always be a libSDL-dev package as well. That is, most joe-blow users won't need the dev package for many libraries, they just need the library itself to run programs. So don't forget to install the dev package if one exists if you want to program with it. The dev packages include the source and headers to compile with.

Please note if you have not already that UNIX environments are very case-sensitive. Including <sdl/sdl.h> is a common mistake (should be <SDL/SDL.h>)

If you really want to get good with compiling and distribution on linux systems, you should start reading some tutorials on MAKEFILEs and ween yourself off KDevelop (at least for learning). For my project, i've developed the whole thing with nothing more than a text editor and a makefile i made. It's totally inflexable and it's a miracle it even compiles, but you do not need a fancy IDE to get work done, is the point.

If you get frustrated, you might also look into getting some different distributions. I would recommend the latest Mandrake for beginners because it has URPMI which takes care of .rpm dependency nightmares. You might also try Debian for the ultimate in packaging goodness. I've successfully gotten my project to compile on Debian, Redhat 9.0, and Mandrake 9.1.



Share this post


Link to post
Share on other sites
hi everyone,

ok, i found the RakNet files inside /usr/lib. i still cant figure out how to give command line arguments though. also, how do i know what to put exactly for each library? im not finding any info in the readme's about RakNet, and havent checked yet for MySQL++. also, i think i found how to add new libraries, but it doesnt seem like the format you guys are talking about. i started the project with as a "default SDL app" and in this menu to add external libraries it has SDL as "$(LIBSDL_LIBS)"..

Share this post


Link to post
Share on other sites
Here is what my makefile looks like, if it's of any help to you:


#use "g++" to compile source files.
CC = g++

#use "g++" to link the object files.
LD = g++

#Compiler flags:
CFLAGS = -Wall -pedantic `sdl-config --cflags` `freetype-config --cflags`
#-I/usr/include/SDL

#Linker flags:
LDFLAGS = $(shell sdl-config --libs)

#Dependency generator:
MDEPEND = g++ -M

#Clean-up command:
RM = /bin/rm -f

# dirs to search for files in
VPATH = ..


# The list of source files:
SRCS = Texture.cpp MusicTrack.cpp Sound.cpp Fonts.cpp ResourceMgr.cpp BasicWidget.cpp UniversalObserver.cpp main.cpp InputHandler.cpp InputActions.cpp Commands.cpp GameApplication.cpp Timer.cpp ColorCurve.cpp Polygon.cpp PolygonTools.cpp Vector.cpp Particle.cpp ParticleSource.cpp drawing.cpp PollingObject.cpp CollisionObjects.cpp PhysicalObject.cpp TestCritters.cpp BackgroundImage.cpp GameSpace.cpp LifeObject.cpp QuadtreeNode.cpp Quadtree.cpp LogManager.cpp Animation.cpp Explosion1.cpp BasicLaserShot.cpp GameSpaceMap.cpp LightSphere.cpp LightFlare.cpp PollingEngine.h Sequencer.h Player.cpp






#Libraries to include when linking:
LIBS = /usr/lib/libSDL.so -lSDL_image -lSDL_mixer -lfreetype -lGL -lGLU /usr/local/lib/libftgl.a


# program executable file name.
PROG = ark



# keep these seperate since they get compiled seperately
TINYXML_OBJS = src/utilities/TinyXML/tinyxml.o src/utilities/TinyXML/tinystr.o src/utilities/TinyXML/tinyxmlparser.o src/utilities/TinyXML/tinyxmlerror.o

# list of generated object files.
OBJS = $(TINYXML_OBJS) src/core/Texture.o src/core/MusicTrack.o src/core/Sound.o src/core/Fonts.o src/etc/Timer.o src/core/ResourceMgr.o src/UI/widgets/BasicWidget.o src/objects/UniversalObserver.o src/core/InputHandler.o src/core/InputActions.o src/core/Commands.o src/core/GameApplication.o src/etc/ColorCurve.o src/algo/collision/Polygon.o src/algo/collision/PolygonTools.o src/algo/collision/Vector.o src/objects/PollingEngine.o src/core/Sequencer.o src/core/main.o src/fx/Particle.o src/fx/ParticleSource.o src/core/drawing.o src/objects/PollingObject.o src/objects/CollisionObjects.o src/objects/PhysicalObject.o src/objects/TestCritters.o src/fx/backgrounds/BackgroundImage.o src/core/GameSpace.o src/objects/LifeObject.o src/algo/QuadtreeNode.o src/algo/Quadtree.o src/utilities/LogManager.o src/fx/animation/Animation.o src/fx/animation/Explosion1.o src/objects/weapons/BasicLaserShot.o src/objects/map/GameSpaceMap.o src/fx/light/LightSphere.o src/fx/light/LightFlare.o src/objects/player/Player.o



######## RULES ########

# Top-level rule: compile everything
all: $(PROG)

# The program link rule:
$(PROG): $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROG)

# Meta rule for compiling ".cpp" files
%.o: %.cpp
$(CC) $(CFLAGS) -c $< -o $@

# Rule for cleaning up before a recompile:
clean:
$(RM) $(PROG) $(OBJS)

# Rule for creating dependency lists and writing them into a dependency file:
.depend:
$(RM) .depend
$(MDEPEND) $(SRCS) > .depend

#Include dependency list:
#include .depend

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this