Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

[Tutorial] How to compile plugins for Linux

$
0
0
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 TESTED ON UBUNTU 14.04, DEBIAN VERSION COMMING SOON!

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 google, 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
Code:

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 above run these:
Code:

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.

Code:

sudo apt-get install git
Okey.

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

Code:

git clone https://github.com/kurta999/YSF YSF
We have to go to the given directory with cd command.
Code:

cd ./YSF
And let's build the project wit GCC/G++.
Code:

make
After "make", you should see something similar like this:
Code:

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++.
Code:

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
Code:

git clone https://github.com/kurta999/YSF /mnt/c/YSF
cd /mnt/c/YSF
make

Now you see that it's fucking easy, you don't need to download compiler 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:
Code:

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?

Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>