Sonicadvance1 / OpenMystera

OpenMystera
0 stars 0 forks source link

Server needs to compile scripts to dynamic libraries #2

Open Sonicadvance1 opened 11 years ago

Sonicadvance1 commented 11 years ago

Was messing with it a bit. GCC requires that a any function called main() is required to return int. So we need batch modify every script file to replace the void with a int. Compiling them in to a shared file is easy enough.

g++ -o 1.so -fPIC -shared -Wl,-soname,1.so -x c++ -Iserver/INCLUDE -Icommon/Include -include script_commands.h serverdata/scripts/1.txt

Breaking that down it does this: g++ -o 1.so // Sets the output name to 1.so g++ -o 1.so -fPIC // Makes sure that the code is position independent. Required for shared libraries -fPIC -shared // Says that it is a shared library -shared -Wl,-soname,1.so // Bit weird looking, but it sets a suboption for setting the name of the shared library INSIDE the file itself. -Wl,-soname,1.so -x c++ // Makes sure that the file is compiled as C++, needed since GCC detects file types from file extensions -x c++ -Iserver/INCLUDE -Icommon/Include // Includes both the common include folders so the script can use those headers. -Iserver/INCLUDE -Icommon/Include -include script_commands.h // This forces the header script_commands.h to be included in the script file no matter what. Since none of the script files have a include line for it, this is needed -include script_commands.h serverdata/scripts/1.txt // This is the file that it is compiling.

So relatively easy to make a shared library file. Just need to make sure to copy over the header files to the correct places when making them. We'll need to create a bash file so the options aren't hard coded in to the server for compiling these scripts. probably just like the Windows one used. it'll take two arguments, one containing the location of the .txt file, and one containing where we want the .so file to end up.

Then we can just use dlopen to pull in the information and run it.

Sonicadvance1 commented 11 years ago

You could probably get this done relatively quickly if you worked on it. Would be a good learning experience.