# 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 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 on other sites
Quote:
 Original post by graveyard fillafor 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 fillanext, 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 on other sites
Quote:
 Original post by graveyard fillahi,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 on other sites

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 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 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 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 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 on other sites
You did "su root" before "make install" on both?

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

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 on other sites
Welcome to linux. The world of RTFM for hours before you can accomplish your task.

hi everyone,