SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 16/04/2017, 10:36 AM   #1
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,398
Reputation: 579
Default How to compile plugins for Linux

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 ******, 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 former commands run these too:
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 --depth 1
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 --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:
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?

Last edited by kurta999; 16/04/2017 at 04:26 PM.
kurta999 is offline   Reply With Quote
Old 16/04/2017, 01:21 PM   #2
JustMe.77
Huge Clucker
 
JustMe.77's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 265
Reputation: 60
Default Re: How to compile plugins for Linux

Awesome tutorial, nice effort
JustMe.77 is offline   Reply With Quote
Old 16/04/2017, 01:40 PM   #3
Salik
Big Clucker
 
Salik's Avatar
 
Join Date: Aug 2015
Location: Russia
Posts: 66
Reputation: 0
Default Re: How to compile plugins for Linux

GJ! Very good tutorial.
Salik is offline   Reply With Quote
Old 16/04/2017, 03:59 PM   #4
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,103
Reputation: 130
Default Re: How to compile plugins for Linux

I would not suggest installing compilers that way since it could be pain in the ass to update if needed. Just use:
Code:
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.
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 16/04/2017, 04:19 PM   #5
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,398
Reputation: 579
Default Re: How to compile plugins for Linux

Quote:
Originally Posted by DRIFT_HUNTER View Post
I would not suggest installing compilers that way since it could be pain in the ass to update if needed. Just use:
Code:
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.
kurta999 is offline   Reply With Quote
Old 16/04/2017, 05:09 PM   #6
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,103
Reputation: 130
Default Re: How to compile plugins for Linux

Quote:
Originally Posted by kurta999 View Post
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.
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 20/04/2017, 04:43 PM   #7
TheBlade
Little Clucker
 
Join Date: Apr 2016
Posts: 1
Reputation: 0
Default Re: How to compile plugins for Linux

Nice! Very good tutorial.
TheBlade is offline   Reply With Quote
Old 08/07/2017, 04:46 PM   #8
semen7907
Little Clucker
 
Join Date: Jul 2013
Posts: 11
Reputation: 0
Default Re: How to compile plugins for Linux

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$
semen7907 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updated server and plugins and now cannot compile Gongalong Scripting Help 14 19/11/2016 08:57 PM
[Ajuda] Plugins Linux? eNtinityGaming Portuguкs/Portuguese 21 29/01/2014 01:49 PM
Server wont load plugins for linux on linux server! GrantLea Help Archive 3 24/10/2010 10:55 PM


All times are GMT. The time now is 11:50 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.