Help with compiling a plugin

Help with Setup, Hardware, Performance or other Issues...Or just pimp your rig.
Post Reply
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Help with compiling a plugin

Post by Teak »

I have figured out how to write a plugin, but I am clueless when it comes to compiling it and using it. I am new to C, but know other programming languages. (So I'm not completely clueless) Is it even possible to compile on a Mac? I know how to run a server, I just need to compile my .cpp, so I can use it. (Or do you have to? I don't even know. :? ) I've searched all over these forums and found nothing. (Maybe I'm searching for the wrong thing...)

Any help would be great...
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

1. First of, BZFlag plugins are written in C++ ;)

2. Yes it is possible to compile on a Mac. I develop all my plugins on a Mac :D

3. How to (Note this is all command-line work, so get Terminal ready):
Let's start off, you need download the BZFlag source code. Once you get the BZFlag source, 'cd' into the source and do:

Code: Select all

sh autogen.sh
./configure --prefix=$HOME/bzbuild
make
All of the above simply configures and makes BZFlag, BZAdmin, and BZFS. This also configures BZFlag and, in this case, plugins will be stored in '~/bzbuild' Once that is done, type:

Code: Select all

cd ./plugins
Once you are in this folder, type:

Code: Select all

sh newplug.sh <name of your plugin w/o an extension>
(The folder name should match the file name of the .cpp file) You will now have a new folder in the 'plugins' folder. Go into the folder with Finder and place your .cpp file in there. Once it's inside the folder, you're going to have to fix the name of a file in order to compile. So type:

Code: Select all

cd ./MyPlugin/.deps
mv SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.Plo MyPlugin_la-MyPlugin.Plo
(You will replace 'MyPlugin' with the name of the plugin [the same name as the folder you just created with the newplug.sh script])

Now type:

Code: Select all

cd ..
make
make install
You will now have your compiled .so located in '~/bzbuild/lib/bzflag/MyPlugin.so'


If you keep the same Terminal window open throughout the entire process, this little guide should work out perfectly. Let me know if you need help :D

-allejo
Last edited by allejo on Wed Jul 13, 2011 5:52 pm, edited 1 time in total.
User avatar
blast
General
General
Posts: 4931
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: Help with compiling a plugin

Post by blast »

allejo wrote:(The folder name should match the file name of the .cpp file) You will now have a new folder in the 'plugins' folder. Go into the folder with Finder and place your .cpp file in there. Once it's inside the folder, you're going to have to fix the name of a file in order to compile. So type:

Code: Select all

cd ./MyPlugin/.deps
mv SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.Plo MyPlugin_la-MyPlugin.Plo
That .Plo file is automatically generated, so you don't actually need to rename that. You should just delete it, along with Makefile, Makefile.am, SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.lo, and SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.o files, and the .deps/ and .libs/ directories. Then you run autogen, configure, and make again.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

allejo wrote:1. First of, BZFlag plugins are written in C++ ;)
I know it's C++, I'm just new to all of C in general.
allejo wrote:(Note this is all command-line work, so get Terminal ready):
I'm very comfortable with the terminal too. (For my other programming work.)

Thank you very much for that guide. I will try it asap and post if I have problems...

Thanks - Teak
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

I get this problem:

Code: Select all

teaksmacbook:bzflag-2.4.0 admin$ ./configure --prefix=~/bzbuild
configure: error: expected an absolute directory name for --prefix: ~/bzbuild
I also tried this: (With a space after the "=")

Code: Select all

teaksmacbook:bzflag-2.4.0 admin$ ./configure --prefix= ~/bzbuild
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: /Users/admin/bzbuild
************************************************
*** Configuring BZFlag 2.4.0, Build 20110713 ***
************************************************
checking build system type... Invalid configuration `/Users/admin/bzbuild': machine `/Users/admin/bzbuild' not recognized
configure: error: /bin/sh misc/config.sub /Users/admin/bzbuild failed
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

Woops!! My mistake!! So sorry about that. Try this:

Code: Select all

./configure --prefix=$HOME/bzbuild/
(I edited my first post to fix my error as I do not want others to get the same error, so don't think you did the wrong thing.)
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

blast wrote:That .Plo file is automatically generated, so you don't actually need to rename that. You should just delete it, along with Makefile, Makefile.am, SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.lo, and SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.o files, and the .deps/ and .libs/ directories. Then you run autogen, configure, and make again.
blast, Why would you want to take a more time running autogen, configure, and make after each new plugin you create with newplug.sh? Simply renaming the .Plo file is quicker and it still works.
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

Okay all is well with compiling, but how do I run it?

I've tried this in my config file and it says "can't load plugin":

Code: Select all

-loadplugin ~/bzbuild/lib/bzflag/testplugin.so
Also, maybe someone should put something like this on the wiki for future people like me...
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

I need more information than "can't load plugin" because there can be a number of reasons why your plugin isn't loading. When you run bzfs add -dd to your config file and tell me what it says when it says it "can't load plugin."
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

Here is the relevant part, it looks like it can't find it, but why, I have no idea:

Code: Select all

Plugin: ~/bzbuild/lib/bzflag/testplugin.so not found, error dlopen(, 9): no suitable image found.  Did find:
	/usr/local/lib/: not a file
	/usr/lib/: not a file
WARNING: unable to load the plugin; ~/bzbuild/lib/bzflag/testplugin.so
(I can post the rest if you need it, but it's kinda long...)
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

There we go, your plugin can't be found. Try using the complete path to your plugin. I'm assuming (from your previous post where you showed the path of your home directory)

Code: Select all

-loadplugin /Users/admin/bzbuild/lib/bzflag/testplugin.so
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

Okay, now it gives me this error:

Code: Select all

Plugin: /Users/admin/bzbuild/lib/bzflag/testplugin.so not found, error dlopen(/Users/admin/bzbuild/lib/bzflag/testplugin.so, 9): no suitable image found.  Did find:
	/Users/admin/bzbuild/lib/bzflag/testplugin.so: mach-o, but wrong architecture
WARNING: unable to load the plugin; /Users/admin/bzbuild/lib/bzflag/testplugin.so
Wrong architecture?
Last edited by Teak on Wed Jul 13, 2011 8:15 pm, edited 1 time in total.
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

Wait, I'm not sure I'm following, how does shGenerator.so appear in the error? And are you using the correct version of bzfs with the correct version of the plugin? Plugins for BZFlag 2.4 use a different API than the plugins for BZFlag 2.0.x.
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

Okay never mind, I got it working with my custom build version of bzfs...
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

allejo wrote:Wait, I'm not sure I'm following, how does shGenerator.so appear in the error? And are you using the correct version of bzfs with the correct version of the plugin? Plugins for BZFlag 2.4 use a different API than the plugins for BZFlag 2.0.x.
Sorry, I was editing the name to make it make more sense. I'm using a test plugin that I built with a different name.
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

Teak wrote:Sorry, I was editing the name to make it make more sense. I'm using a test plugin that I built with a different name.
Oh alright, I'm assuming you got your plugin working because of your previous post, am I correct? :)
User avatar
Teak
Private First Class
Private First Class
Posts: 18
Joined: Sun Sep 12, 2010 6:48 pm
Location: Victoria, BC Canada

Re: Help with compiling a plugin

Post by Teak »

Yes it's working, thank you very much for all your help. And again, someone should make a wiki page for this. One would have been very helpful three days ago... (I don't think I'm qualified to make a wiki page on something I didn't know how to do three hours ago.)
User avatar
blast
General
General
Posts: 4931
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: Help with compiling a plugin

Post by blast »

allejo wrote:
blast wrote:That .Plo file is automatically generated, so you don't actually need to rename that. You should just delete it, along with Makefile, Makefile.am, SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.lo, and SAMPLE_PLUGIN_la-SAMPLE_PLUGIN.o files, and the .deps/ and .libs/ directories. Then you run autogen, configure, and make again.
blast, Why would you want to take a more time running autogen, configure, and make after each new plugin you create with newplug.sh? Simply renaming the .Plo file is quicker and it still works.
Why would you not just run ./newplug.sh before you run autogen and configure the first time? Besides, you SHOULD be running it afterwards, since you also have to add a reference to the new Makefile to configure.ac, which requires running autogen.sh again since you are modifying the file that helps generate the configure script.

So, yeah, I'd rather do it properly instead of just hoping that it works out okay. That, and I have a quad-core processor. :P
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

blast, I believe we are at a misunderstanding. I did not intend to imply that you should run newplug.sh before autogen, configure, and make. The reason I stated that .Plo file should be renamed is because I don't know why exactly, but I always get a .Plo file for SAMPLE_PLUGIN whenever I run newplug.sh and never for the actual plugin. I have modified my newplug.sh file to rename the .Plo automatically for me but with the default newplug.sh it doesn't rename the .Pla file, hence I mentioned that it had to be renamed.
User avatar
blast
General
General
Posts: 4931
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: Help with compiling a plugin

Post by blast »

No, my point is that you can run the newplug.sh file before autogen and configure. Then you don't get the extra files, and you're only running autogen and configure once (unless you decide to add another plugin).
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: Help with compiling a plugin

Post by allejo »

blast wrote:No, my point is that you can run the newplug.sh file before autogen and configure. Then you don't get the extra files, and you're only running autogen and configure once (unless you decide to add another plugin).
Oh right. My bad for the misunderstanding. :)
Post Reply