Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
160 user(s) are online (109 user(s) are browsing Forums)

Members: 0
Guests: 160

more...

Headlines

 
  Register To Post  

Link between 2 static lib
Quite a regular
Quite a regular


See User information
Hi All,

I'd like to make all my plugins for AmiDARK Engine become static lib but I need to have 1 lib be able to call a function located in another 1
It's a need for the system.

I know some will say that I must not do that but it's simply for 1 function that need this and I can't code it otherwise because this function centralize the plugin system and its activation.

Is there a way to do that ?

Thank you.

Kindest Regards,
Freddix

All we have to decide is what to do with the time that is given to us.
Go to top
Re: Link between 2 static lib
Just can't stay away
Just can't stay away


See User information
@freddix

Why do you think this would be a problem?

Let's say that you have two libs called lib1.a and lib2.a and one or more functions in lib1.a used functions and/or variables from lib2.a.

When you list static libraries on the commandline you always list first the libraries that use other libs so in this case you would simply add "-l1 -l2" to the commandline when linking your program.

OTOH if some functions in lib1.a used stuff from lib2.a and some functions in lib2.a used stuff from lib1.a then you might have to use something like "-l1 -l2 -l1" to make it work.

Go to top
Re: Link between 2 static lib
Quite a regular
Quite a regular


See User information
@salass00
Yes, but if lib2 does not exist when I compiles lib1, I will get an error message on compilation ?

In fact, I've just minded that I must create lib2, and then compiles lib1 with the reference to lib2 in the compilation command line.

Right ?

All we have to decide is what to do with the time that is given to us.
Go to top
Re: Link between 2 static lib
Just popping in
Just popping in


See User information
@freddix

How do you intend to 'plug-in' a static lib anyway? For plug-ins you'll need dynamic libs.

Go to top
Re: Link between 2 static lib
Just can't stay away
Just can't stay away


See User information
@freddix

Quote:

Yes, but if lib2 does not exist when I compiles lib1, I will get an error message on compilation ?


No. You will only get undefined reference errors when linking to create a final executable.

To produce the static library simply compile the source code files into object (.o) files and then use ar:

gcc -c -o file1.o file1.c
gcc -c -o file2.o file2.c
gcc -c -o file3.o file3.c
ar -crv lib1.a file1.o file2.o file3.o

Go to top
Re: Link between 2 static lib
Just can't stay away
Just can't stay away


See User information
@DaveAE

Maybe he means compile-time plugins?

Go to top
Re: Link between 2 static lib
Just popping in
Just popping in


See User information
@salass00

Perhaps my definition of plug-in is different then! :)
Anyway, I'd expect plug-ins to have the same interface which is kinda hard with static linking.

Go to top
Anonymous
Re: Link between 2 static lib
Using the .o sharing method, without judicious use of extern you are going to get duplicate symbol errors if you statically link both libraries to another object file.

Go to top
Re: Link between 2 static lib
Quite a regular
Quite a regular


See User information
or as @freddix

You won't be able to do that : let's say your plugins have a function called Init that has to be called in order to init its operation. Now imagine you have two plugins and that you are linking statically both of them how would your code be able to know which Init function you are calling at which time ?
I suspect what you need on the other hand is a way to add/remove plugins just like what was in effect in AMOS with its extensions don't you ? Then you don't need (and must not) to statically link with your plugins as this would then mean they will all be included in your exe and you won't be able to add new ones without recompiling. I guess what you need is a way to open an arbitrary file, check its a plugin of your engine and then activate it in order to be able to use its functionnality, if you are targeting OS4 you can have a look at this article or as indicated in one comment you can also try to use shared objects for that.

EDIT: turning a static library (.a) into a shared object (.so) is a matter of compilation flags AFAIK, then you'll have to write something remotely semblable to :
handle dlopen("thisfile.so");  //open the file
myfunc dlsym(handle"myfunction");  // look for function named myfunction
if( myfunc )
{
    
myfunc(<parameters>);
}
else
{
    
// big error that's not a valide AmiDarkPlugin
}
dlclose(handle);

Back to a quiet home... At last
Go to top
Re: Link between 2 static lib
Quite a regular
Quite a regular


See User information
@All :
Thank you for your comment.

@abalaban
Your 99% right :)
It's something really near to this that I want to do but, my project will be splitted into 2 projects.

1. The game engine for C/C++ that is composed of a couple of plugins files (for example 1 for Basic3D, 1 for Basic2D, 1 for music, etc ...)
and the main object will open all other and call function to initialize them.. Each object has its own setup name convention : FILENAME_Constructor() so the main file know all constructors to call for C.

2. The Basic language based on the C/C++ engine will do what you said with your comment on compiled programs :)
I check your link now :)
Thank you.

EDIT : Abalaban, do you have a copy of the plugin_example.lha ? Because the link does not work ... And the one from Rachy in the comments does not work too...

Kindest Regards,
Fred


Edited by freddix on 2009/7/29 21:58:38
All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project