[Tutorial] How to compile plugins for Linux
#1

I see that for a few people it is still problem to compile plugins for linux. But nowadays it's very easy, even easier than it was before. I will demostrate my two best solutions.

THIS TUTORIAL IS TESTED ON UBUNTU 14.04

Solution 1 - Compiling plugins under linux with GCC:

First of all, you have to understand the basic linux command line commands.

cd - change directory.
dir - list directory

For more use ******, now we don't need them right now.

If you have a cleary setted up Linux machine, then you first need to install GCC compiler. You can do it with these commands: (paste every command to your command line at once)
(We are going to install GCC4.8 + 6.0, 4.8 is old and doesn't support C++14 standard. To avoid problems in future, this is the best solution)

Source: https://gist.github.com/application2...cf9f56315a2d91
Код:
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-snapshot -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
sudo apt-get install gcc-4.8 g++-4.8 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;
If you have x64 OS, then after former commands run these too:
Код:
sudo apt-get install gcc-6.0-multilib g++-6.0-multilib
sudo apt-get install gcc-4.8-multilib g++-4.8-multilib
Done.

OPTIONAL: It will use GCC6 by default, but if you want to change it then do with this command: sudo update-alternatives --config gcc

Now you have two choise:
1.) You can download the project from github with command line:

First you have to download the application which handles git.

Код:
sudo apt-get install git
Okey.

Now let's clone the project which you want to compile:

Код:
git clone https://github.com/kurta999/YSF YSF --depth 1
We have to go to the given directory with cd command.
Код:
cd ./YSF
And let's build the project wit GCC/G++.
Код:
make
After "make", you should see something similar like this:
Код:
g++ -m32 -std=c++14 -Ilib -fno-stack-protector -D YSF -c -O3 -fpack-struct=1 -fPIC -w -DLINUX ./lib/sdk/*.cpp
g++ -m32 -std=c++14 -Ilib -fno-stack-protector -D YSF -c -O3 -fpack-struct=1 -fPIC -w -DLINUX ./lib/raknet/*.cpp
gcc -m32 -Ilib -fno-stack-protector -D YSF -c -O3 -fpack-struct=1 -fPIC -w -DLINUX ./lib/subhook/subhook.c
g++ -m32 -std=c++14 -Ilib -fno-stack-protector -D YSF -c -O3 -fpack-struct=1 -fPIC -w -DLINUX ./src/*.cpp
gcc -m32 -Ilib -fno-stack-protector -nodefaultlibs -fshort-wchar -shared -o "./YSF.so" *.o
It means that project has been successfully compiled and the binary file located in the project directory.

2). Suppose that you already have a source files already on linux machine

Now you have to go to project dir with "cd" command, where it's located. Eg cd /location/of/project

And let's build the project wit GCC/G++.
Код:
make
Solution 2 - Compiling plugin for linux under Windows 10:

If you don't have Windows 10, then it won't work for you! You even must have Windows 10 Redstone update for this solution, Microsoft implemented Linux Subsystem here.

First step is enabling Linux Subsystem: https://www.howtogeek.com/249966/how...on-windows-10/

If you did it succesfully, compiling works in same way as in the first solutin, you only need to specify differenct directory.

For installing compiler, use the commands above.

Cloning YSF repository to: C:\YSF
Код:
git clone https://github.com/kurta999/YSF /mnt/c/YSF --depth 1
cd /mnt/c/YSF
make
Now you see that it's fucking easy, you don't need to download compiled binaries from remote computer, you have it right now on your hard disk.
But it can be even easyer, you can access linux subsystem bash with a .bat file. Let's create a .bat file in your project dir, eg: "linux_compile.bat" and write this line to it:
Код:
bash -c "cd /mnt/c/YSF; make YSF"
Save it and now you can launch that .bat file to compile your project! Easy, isn't it?
Reply
#2

Awesome tutorial, nice effort
Reply
#3

GJ! Very good tutorial.
Reply
#4

I would not suggest installing compilers that way since it could be pain in the ass to update if needed. Just use:
pawn Код:
sudo apt-get install build-essential
That will install make, gcc, g++, dpkg-dev. Most of the time that is all you will ever need. Since its a single line you can also get rid of it very easy, with just one line.

Also for git clone, add --depth 1. We dont need whole repository history. But then again i always use wget and one of the releases because they are the ones considered stable.
Reply
#5

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
I would not suggest installing compilers that way since it could be pain in the ass to update if needed. Just use:
pawn Код:
sudo apt-get install build-essential
That will install make, gcc, g++, dpkg-dev. Most of the time that is all you will ever need. Since its a single line you can also get rid of it very easy, with just one line.

Also for git clone, add --depth 1. We dont need whole repository history. But then again i always use wget and one of the releases because they are the ones considered stable.
Thanks for the advices.

sudo apt-get install build-essential - for me this didn't worked, it only installs GCC 4.8 or 4.9.2 on debian which is horribly outdated.
Reply
#6

Quote:
Originally Posted by kurta999
Посмотреть сообщение
Thanks for the advices.

sudo apt-get install build-essential - for me this didn't worked, it only installs GCC 4.8 or 4.9.2 on debian which is horribly outdated.
Yeah you are right... Versions may be a bit of problem, they are always way behind, specially on long time support versions.
Reply
#7

Nice! Very good tutorial.
Reply
#8

pls help compiling plugin. gcc -v 4.8

it Audio Plugin server

Quote:

...........
.......
.........
/usr/bin/ld: obj/linux/Release/main.o: relocation R_X86_64_32 against hidden symbol `natives' can not be used when making a shared object
/usr/bin/ld: obj/linux/Release/natives.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; перекомпилируйте с параметром -fPIC
/usr/bin/ld: obj/linux/Release/server.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; перекомпилируйте с параметром -fPIC
/usr/bin/ld: obj/linux/Release/session.o: relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3. 4' can not be used when making a shared object; перекомпилируйте с параметром -fPIC
/usr/bin/ld: final link failed: Раздел, непредставимый для вывода
collect2: error: ld returned 1 exit status
audio.make:104: ошибка выполнения рецепта для цели «bin/linux/Release/audio.so»
make[1]: *** [bin/linux/Release/audio.so] Ошибка 1
Makefile:16: ошибка выполнения рецепта для цели «audio»
make: *** [audio] Ошибка 2
trojan@trojan-VirtualBox:~/Загрузки/samp-audio-server-plugin-0.5-r2$

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)