Using RakNet in Linux(?)

Started by
13 comments, last by jordanpx 13 years, 10 months ago
Hi,

I'm trying to use RakNet in linux. I don't know nor have Windows installed, so the tutorials on RakNets website don't help me much. I'm also not terribly experienced in this area anyway... but so far what I have done is...

Go to source directory..
cd ~/RakNet-4.0.Beta2/Source/


Compile objects:
g++ -w  -c *.cpp


Create "shared":
g++ -shared -o ./libraknet.so *.o


Create "Static":
ar rcs ./libraknet.a *.o


outcome:
libraknet.a libraknet.so


So.. my question is with, now that I have these files ( I'm not sure if I even created them correctly .. ), how do I link against them?

And, does anyone know of any simple examples or tutorials of RakNet deployed in a program under Linux?

Ok, thanks in advance and all that =D

Regards,
Pyrath

[Edited by - pyrathian on June 21, 2010 5:21:43 AM]
Advertisement
Quote:Original post by pyrathian
Hi,

I'm trying to use RakNet in linux. I don't know nor have Windows installed, so the tutorials on RakNets website don't help me much. I'm also not terribly experienced in this area anyway... but so far what I have done is...

Go to source directory..
cd ~/RakNet-4.0.Beta2/Source/


Compile objects:
g++ -w  -c *.cpp


Create "shared":
g++ -shared -o ./libraknet.so *.o


Create "Static":
ar rcs ./libraknet.a *.o


outcome:
libraknet.a libraknet.so


So.. my question is with, now that I have these files ( I'm not sure if I even created them correctly .. ), how do I link against them?


In order to link against this (or any library) you'll need two options in GCC:

-L/path/to/library/directory/ This is the path where the libraknet.* are located (apparently, ~/RakNet-4.0.Beta2/Source/)

-lraknet This is the name of the library (minus the lib prefix, which is added by the linker) If I remember correctly, gcc will prefer to use the dynamic version (.so) instead of the static (.a) I would recommend to just create one of the two, depending on whatever your want, to avoid any confusion.


Also worth mentioning that in order to be able to locate RakNet's header files, you should pass to gcc the -I/path/to/headers/ option.


Quote:Original post by pyrathian

And, does anyone know of any simple examples or tutorials of RakNet deployed in a program under Linux?


I have never used RakNet, but looking at the tutorial section on its web page, I see no reason why it shouldn't work on Linux. It isn't using any Win32 specific calls, just console stuff.
You shouldn't have to go to all that work at all. RakNet definatly works just fine in linux. I'm tired though, and can't seem to find the actual RakNet page that walks you through the install.
So, from memory, you should be able to:

Just go to the directory where you extracted the .zip file.
type:
cmake -i

I think you also have to add a '-D' flag, but it should error out telling you what you actually need to type in for the -D target.
answer the prompts, then type:
make && make install

compile your target programs with:
 -lRakNet -lpthread -lrt


If you don't have cmake, you should be able to
sudo atp-get install cmake


The benifit of just using there make file is that it is not only faster to get everything up and running. But it should also compile and install all the samples for you, so you can run those right off the bat as well.
Thanks a lot for the information, it's what I needed!

Regarding using cmake,
cmake . make && make install
crashes, and I don't know how to fix this ( I'm probably missing something ).

[ 76%] Building CXX object Samples/Tests/CMakeFiles/Tests.dir/MaximumConnectTest.cpp.o/home/pyrath/Baixades/RakNet-4.0.Beta2/Samples/Tests/MaximumConnectTest.cpp: In member function ‘virtual int MaximumConnectTest::RunTest(DataStructures::List<RakNet::RakString>, bool, bool)’:/home/pyrath/Baixades/RakNet-4.0.Beta2/Samples/Tests/MaximumConnectTest.cpp:46: warning: taking address of temporary/home/pyrath/Baixades/RakNet-4.0.Beta2/Samples/Tests/MaximumConnectTest.cpp:46: error: invalid conversion from ‘int’ to ‘RakNet::SocketDescriptor*’/home/pyrath/Baixades/RakNet-4.0.Beta2/Samples/Tests/MaximumConnectTest.cpp:46: error:   initializing argument 2 of ‘virtual RakNet::StartupResult RakNet::RakPeerInterface::Startup(short unsigned int, RakNet::SocketDescriptor*, unsigned int, int)’/home/pyrath/RakNet-4.0.Beta2/Samples/Tests/MaximumConnectTest.cpp:46: error: invalid conversion from ‘RakNet::SocketDescriptor*’ to ‘unsigned int’/home/pyrath/Baixades/RakNet-4.0.Beta2/Samples/Tests/MaximumConnectTest.cpp:46: error:   initializing argument 3 of ‘virtual RakNet::StartupResult RakNet::RakPeerInterface::Startup(short unsigned int, RakNet::SocketDescriptor*, unsigned int, int)’make[2]: *** [Samples/Tests/CMakeFiles/Tests.dir/MaximumConnectTest.cpp.o] Error 1make[1]: *** [Samples/Tests/CMakeFiles/Tests.dir/all] Error 2make: *** [all] Error 2 
That error makes it look like someone updated the interface to the function, but didn't fix up all the sample apps.
If that is the only one that is broken, and you don't care about that particular sample, I'd just comment the line out.

But it looks like there is just a misplaced "30" there. They seem to have removed the second parameter. That's quite annoying, since I'm positive that would break my code when I update the libs....

Ok... so, ... after editing the code in the following files it compiled and installed.

FlowControlTest.cppDroppedConnectionTest.cppChat Example Server.cppChat Example Client.cppServerClientTest2.cppDroppedConnectionConvertTest.cppMaximumConnectTest.cpp


By editing, I just mean commenting things out, mostly things to do with:
error: ‘ID_MODIFIED_PACKET’ was not declared in this scope


I probably borked something... =l but it's all installed now XD''

Pyrath

edit: Forgot to mention removing the "30" thing mentioned in the prior post by KulSeran.
So, you got a number of compile errors, called them "crashes," and just commented out the lines that had problems without understanding what each problem was?
And now you think that you'll have a working version?
Clearly, the test programs won't work -- so how do you know that the compiled library will work?
The first time something goes wrong, you'll have no idea whether the problem is with your code, or with the things you commented out.

Don't take this the wrong way, but this all suggests to me that you need to learn more about how C++ and your tool chain (compiler/linker/libraries/debugger) works, before you can actually make good progress on trying to build distributed systems (which is what networking is all about).
enum Bool { True, False, FileNotFound };
Quote:
So, you got a number of compile errors, called them "crashes," and just commented out the lines that had problems without understanding what each problem was?

I'll admit it probably wasn't good form to suggest exactly that. But my install of RakNet had very similar issues. Many of the sample programs weren't updated alongside the API, and I just didn't care about some of them working either, since I could get around to making something like the "autopatcher" sample work later when I actually wanted to play with it.

I don't recall seeing the "error: ‘ID_MODIFIED_PACKET’ was not declared in this scope" error, and that might actually be a sign of a problem with the install.
But I do recall several errors along the lines of the "error: initializing argument 2 of ‘virtual RakNet::StartupResult RakNet::RakPeerInterface::Startup(short unsigned int, RakNet::SocketDescriptor*, unsigned int, int)’" one. Startup might not have been the same function I had problems with, but there were some API calls who's function signature changed and the test program wasn't updated to reflect that.

edit: looks like this was back around 1/20/2010 when I was doing this. And I don't have the origional .zip to check the files against to see what I had to change to make it all compile.


[Edited by - KulSeran on June 21, 2010 11:50:35 PM]
Thanks for the opinion, hplus0603. In case you didn't get the drift from all my autodegrading commentary, it's pretty obvious I need to learn more, oh guess what, I'm doing that now and indefinitely. Anyway, english isn't even my first language, no point in attacking my vocabulary, or lack of.

Quote:I probably borked something... =l but it's all installed now XD'

Quote:And now you think you have a working version?


Obviously, I do not think that.

Also, I only edited the examples., the main Source compiled just fine from the start. And after changing the function for example, that had not been updated, and removing a couple case entries about ID_MODIFIED_PACKET ( which it was stated on RakNet forums that it is not needed anymore ), the examples at least superficially "work".
I don't mind your English, it's fine (except for the difference between "crashes" and "errors" which I think is semantic, not linguistic).

I think you are in over your head, and you will probably make better headway learning if you focus on one thing at a time. If you want to learn network programming, I suggest using a version of a library where all the examples actually work. This means that you can compile, run and study the examples, and learn from them! (That's exactly what examples are for)

My main point is this: If the samples don't work, and you disable them, then what makes you think that the library will work? Just because the library compiles doesn't mean it actually does what it says it will do, unless there is some test program that actually proves that it does.

Trying to learn network programming on top of a broken version of RakNet using a language and compiler that you don't really understand, is akin to trying to learn trigonometry from a textbook written in Latin -- where half the pages are gone! Not only do you have to learn trigonometry (network programming), but you have to learn Latin (C++ with GCC in this case), and decipher what's supposed to be on the pages that are missing (example programs).

If you think it's fun, feel free to keep going, but if your goal is to efficiently learn distributed systems development in C++, there are probably more efficient ways to go about it.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement