LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-29-2006, 10:47 PM   #1
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
help translating pascal's libc "dlopen , dlsym and dlclose" into c source ...


i have encountered problems when translating a pascal procedure (which uses libc functions :: dlopen , dlsym and dlclose) into c source ... hint and direct me to the solution(preferably with smaller simpler c code examples) ...

below is the pascal code , i try to implement it in a self-contained pascal procedure with only one "includes"("uses" in pascal) libc at somewhere else ... it might not be the "correct" way of coding it but i managed to just compile and run the whole app , just run ...

Code:
procedure TForm1.Button3Click(Sender: TObject);
type
TGTKModuleHandle=Pointer;
const
NIL_MODULEHANDLE=TGTKModuleHandle(NIL);
var 
s:string;
lib_name,func_name:pchar;
call_func: function(pass_strings:Pchar):Pchar;cdecl ;
GTKModuleHandle:TGTKModuleHandle;
begin

if GTKModuleHandle <> NIL_MODULEHANDLE then
dlclose(GTKModuleHandle);
    
GTKModuleHandle:=NIL_MODULEHANDLE;

lib_name:='libcallgtk02.so';
GTKModuleHandle:=dlopen(lib_name,RTLD_NOW);

try
if GTKModuleHandle <> NIL_MODULEHANDLE then
begin
//  char *call_gtk02(char *pass_strings);   in   libcallgtk02.so
func_name:='call_gtk02';
call_func:= dlsym(GTKModuleHandle,func_name);
s:=call_func('dlopen strings to here ...');
memo1.lines.add('return from dlopen ----> '+s);
end else
 begin
 showmessage('cant locate your function ...');
 exit;
 end ;
finally
if GTKModuleHandle <> NIL_MODULEHANDLE then
dlclose(GTKModuleHandle);
end ;//end try

end;
note :: its a kylix/pascal gui with a button and a text-memo gadget and by clicking the button , it call a function came "packaged" in a shared library which run a gtk app(but modal window) , the name(in strings) of the library and the function have been known beforehand , can have a look at the shared library here :: HERE ...



//thanks in advance ...


.
 
Old 04-30-2006, 04:49 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I noticed this has been here for awhile...

I'm really not sure what your question is:

1. You're porting an application from Kylix/Pascal (essentially, a Linux version of Borland Pascal) into C. Is this correct?

2. You've encountered places in the Pascal code where it calls dlopen, etc.

These Pascal codes (as it looks like you already know) are simple wrappers around the
standard libc calls. In other words, "dlopen()" and friends are *already* in C.

3. If you want to use dlopen() etc from your C program, you can simply call them.

Most programs don't even need explicitly do a "dlopen(): everything's automagically
taken care of when the C/C++ program is linked, and the "shared libraries" are com-
pletely transparent to the developer).

4. Finally, if you're interested in how dlopen() etc are linked: just look in the kernel source (the C library function is, like your Kylix counterpart, just a thin wrapper).

'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
undefined reference to dlopen, dlclose, dlsym and dlerror patrickdepingui Slackware 5 02-14-2010 08:55 AM
FC3 misplaced vital program "dlopen" ArkyMedia Fedora 9 03-07-2005 10:15 AM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 09:40 AM
What are "libc", "glibc"? correro Linux - General 4 03-15-2003 07:36 PM


All times are GMT -5. The time now is 04:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration