zentara has asked for the wisdom of the Perl Monks concerning the following question:

Hi, after the recent discussion here about Inline C, I decided to try one of the examples from the cookbook: how to access an so lib. But for some reason, I'm getting unresolved symbols, even though it builds properly. The example below is taken almost verbatim from the cookbook.

#!/usr/bin/perl
print get('http://localhost');

use Inline C => Config =>
LIBS => '-lghttp',
INC => '-I/opt/gnome/include/';
use Inline C => <<'END_OF_C_CODE';

#include <ghttp.h> 

char *get(SV* uri) {
SV* buffer;
ghttp_request* request;

buffer = NEWSV(0,0);
request = ghttp_request_new();
ghttp_set_uri(request, SvPV(uri, PL_na));

ghttp_set_header(request, http_hdr_Connection, "close");

ghttp_prepare(request);
ghttp_process(request);

sv_catpv(buffer, ghttp_get_body(request));

ghttp_request_destroy(request);

return SvPV(buffer, PL_na);
}

END_OF_C_CODE

#################################################################### 
#When I run it, it compiles fine, but I get this error when running: 
Had problems bootstrapping Inline module 'gethttp_bce4'

Can't load '_Inline/lib/auto/gethttp_bce4/gethttp_bce4.so' 
for module gethttp_bce4: _Inline/lib/auto/gethttp_bce4/gethttp_bce4.so: 
undefined symbol: http_hdr_Connection at /DynaLoader.pm line 229. 
at /usr/lib/perl5/site_perl/5.8.0/Inline.pm line 432 
##################################################################### 
 
OK, so now I go to the gethttp_bce4.so and do an nm on it: 
Here is the relevant section of the output: 
nm gethttp_bce4.so -> 
 
00000d00 t frame_dummy 
000015b0 T get 
U ghttp_get_body 
U ghttp_prepare 
U ghttp_process 
U ghttp_request_destroy 
U ghttp_request_new 
U ghttp_set_header 
U ghttp_set_uri 
U http_hdr_Connection 
00002874 d p.0 
U pthread_getspecific 
 
Well all the subroutines needed are undefined. Why?? 
If I do an nm on libghttp.so.1, they are defined : 
nm libghttp.so.1 -> 
 
00003170 T ghttp_get_body 
000031c0 T ghttp_get_body_len 
000030b0 T ghttp_get_error 
00003030 T ghttp_get_header 
00003070 T ghttp_get_header_names 
00003150 T ghttp_get_socket 
00002e40 T ghttp_get_status 
000030e0 T ghttp_parse_date 
00002ab0 T ghttp_prepare 
00002c80 T ghttp_process 
00003130 T ghttp_reason_phrase 
000025f0 T ghttp_request_destroy 
00002570 T ghttp_request_new 
00003210 T ghttp_set_authinfo 
00002a00 T ghttp_set_body 
00002fd0 T ghttp_set_chunksize 
00002ff0 T ghttp_set_header 
000028a0 T ghttp_set_proxy 
00003450 T ghttp_set_proxy_authinfo 
00002a70 T ghttp_set_sync 
000028f0 T ghttp_set_type 
000027a0 T ghttp_set_uri 
00003110 T ghttp_status_code 
00002760 T ghttp_uri_validate 
00006430 T http_base64_encode 
00003690 T http_date_to_time 
000067a3 R http_hdr_Accept 
000067aa R http_hdr_Accept_Charset 
000067b9 R http_hdr_Accept_Encoding 
000067c9 R http_hdr_Accept_Language 
0000687c R http_hdr_Accept_Ranges 
0000688a R http_hdr_Age 
000066d4 R http_hdr_Allow 
000067d9 R http_hdr_Authorization 
00006759 R http_hdr_Cache_Control 
00006767 R http_hdr_Connection 
 
########################################################### 
 
So, what am I missing to cause those subroutines to get 
linked in? 
 

Replies are listed 'Best First'.
Re: Inline C, accessing an so lib
by derby (Abbot) on Nov 15, 2002 at 13:39 UTC
    What platform? Linux? If so, type

    ldd libghttp_bce4.so

    to see exactly which libghttp.so you're linked to. It may be wrong or it may not be fully qualified in which case you would need to set your LD_LIBRARY_PATH to include the directory containing libghttp.so or if you're real paranoid about security, add the directory to /etc/ld.so.conf.

    -derby

Re: Inline C, accessing an so lib
by hawtin (Prior) on Nov 15, 2002 at 13:33 UTC

    The obvious thing to check is that the $LD_LIBRAY_PATH is set when your script runs. Try printing the value of

    $ENV{"LD_LIBRARY_PATH"}

    From the script. If it doesn't have the right directory the library won't be found

Re: Inline C, accessing an so lib
by Anonymous Monk on Nov 15, 2002 at 16:04 UTC
    Well I'm using linux, with perl5.80.  The so library in
    question, is listed in my cache, with ldconfig -p  
    If I do an ldd on gethttp_bce4.so 
    it dosn't list libghttp.so.1.0.0  as being linked. 
    I did manage to get it to run by wrapping it in a  shell script:
    ###########################################
    #!/bin/sh
    LD_PRELOAD=/opt/gnome/lib/libghttp.so.1.0.0
    export LD_PRELOAD
    gethttp.pl
    #######################################
    
    But it sure seems like a clunky way to access a so lib
    from perl. Is there a way to do this all from within the
    perl script?  I couldn't get the export command to work
    with a system command, or it didn't affect the loading.
    
      Ooops, sorry for the confusion. that anonymous monk is zentara. :-)