Xiaodan Tang(deleted)
|
RE: Choosing between libraries with same API at run-time
|
Xiaodan Tang(deleted)
02/02/2009 12:08 PM
post21239
|
RE: Choosing between libraries with same API at run-time
You write youn own library, implement the API
mq_open()/mq_send()/mq_receive()/..., has your application link to your
own library.
During the initilize period, (or the first call of a mq_open() into your
library), you find out the 2 set of mq_* functions.
dlopen("libc.so.3", ...)
libc_mq_open = dlsym(..., "mq_open");
...
dlopen("libmq.so", ...)
libmq_mq_open = dlsym(..., "mq_open");
...
And they you decided how to switch between the 2.
-xtang
> -----Original Message-----
> From: Andrew Sherk [mailto:community-noreply@qnx.com]
> Sent: Monday, February 02, 2009 12:03 PM
> To: ostech-core_os
> Subject: Choosing between libraries with same API at run-time
>
> Hello,
>
> I wish to write a program that at run-time can choose between
> libc's mqueue (mq_*) API and libmq.so's API.
>
> Since they have exactly the same function names (mq_send,
> mq_receive, etc.), how can I link to both libraries but at
> runtime choose which actual implementation's code to execute?
>
> The purpose of this application is so that the user can at
> run-time decide if they want to run a performance test with
> mq or mqueue.
>
> -asherk
>
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post21237
>
>
|
|
|
Xiaodan Tang(deleted)
|
Re: Choosing between libraries with same API at run-time
|
Xiaodan Tang(deleted)
02/02/2009 12:17 PM
post21240
|
Re: Choosing between libraries with same API at run-time
Actually, if you don't need dynamic switch. There is much easy way.
Write your test application normally, link it with libc.
If you run it directly, it use mq_* in libc.
If you want to use libmq, try this:
# LD_PRELOAD=/full/path/libmq.so ./mytestapp
|
|
|