[getdns-users] SWIG, PHP, and Undefined Functions

Willem Toorop willem at nlnetlabs.nl
Mon Feb 2 13:03:30 UTC 2015


Hi Scott,

Exactly repeating your steps works with me:

php > include('getdns.php');
php > print_r(get_extension_funcs("getdns"));
Array
(
    [0] => getdns_bindata_size_set
    [1] => getdns_bindata_size_get
    [2] => getdns_bindata_data_set
    [3] => getdns_bindata_data_get
    [4] => new_getdns_bindata
    [5] => getdns_strerror
    [6] => getdns_list_get_length
    [7] => getdns_list_get_data_type
    [8] => getdns_list_get_dict
    [9] => getdns_list_get_list
    [10] => getdns_list_get_bindata
    [11] => getdns_list_get_int
    [12] => getdns_dict_get_names
    [13] => getdns_dict_get_data_type
    [14] => getdns_dict_get_dict
    [15] => getdns_dict_get_list
    [16] => getdns_dict_get_bindata
    [17] => getdns_dict_get_int
    [18] => getdns_list_create
    [19] => getdns_list_create_with_context
    [20] => getdns_list_create_with_memory_functions
    [21] => getdns_list_create_with_extended_memory_functions
    [22] => getdns_list_destroy
    [23] => getdns_list_set_dict
    [24] => getdns_list_set_list
    [25] => getdns_list_set_bindata
    [26] => getdns_list_set_int
    [27] => getdns_dict_create
    [28] => getdns_dict_create_with_context
    [29] => getdns_dict_create_with_memory_functions
    [30] => getdns_dict_create_with_extended_memory_functions
    [31] => getdns_dict_destroy
    [32] => getdns_dict_set_dict
    [33] => getdns_dict_set_list
    [34] => getdns_dict_set_bindata
    [35] => getdns_dict_set_int
    [36] => getdns_dict_remove_name
    [37] => getdns_general
    [38] => getdns_address
    [39] => getdns_hostname
    [40] => getdns_service
    [41] => getdns_context_create
    [42] => getdns_context_create_with_memory_functions
    [43] => getdns_context_create_with_extended_memory_functions
    [44] => getdns_context_destroy
    [45] => getdns_cancel_callback
    [46] => getdns_general_sync
    [47] => getdns_address_sync
    [48] => getdns_hostname_sync
    [49] => getdns_service_sync
    [50] => getdns_convert_dns_name_to_fqdn
    [51] => getdns_convert_fqdn_to_dns_name
    [52] => getdns_convert_ulabel_to_alabel
    [53] => getdns_convert_alabel_to_ulabel
    [54] => getdns_validate_dnssec
    [55] => getdns_pretty_print_dict
    [56] => getdns_display_ip_address
    [57] => getdns_context_set_context_update_callback
    [58] => getdns_context_set_resolution_type
    [59] => getdns_context_set_namespaces
    [60] => getdns_context_set_dns_transport
    [61] => getdns_context_set_limit_outstanding_queries
    [62] => getdns_context_set_timeout
    [63] => getdns_context_set_follow_redirects
    [64] => getdns_context_set_dns_root_servers
    [65] => getdns_context_set_append_name
    [66] => getdns_context_set_suffix
    [67] => getdns_context_set_dnssec_trust_anchors
    [68] => getdns_context_set_dnssec_allowed_skew
    [69] => getdns_context_set_upstream_recursive_servers
    [70] => getdns_context_set_edns_maximum_udp_payload_size
    [71] => getdns_context_set_edns_extended_rcode
    [72] => getdns_context_set_edns_version
    [73] => getdns_context_set_edns_do_bit
    [74] => getdns_context_set_memory_functions
    [75] => getdns_context_set_extended_memory_functions
    [76] => getdns_context_get_api_information
    [77] => getdns_root_trust_anchor
    [78] => getdns_context_set_return_dnssec_status
    [79] => getdns_dict_util_set_string
    [80] => getdns_dict_util_get_string
    [81] => getdns_context_set_use_threads
    [82] => getdns_context_get_num_pending_requests
    [83] => getdns_context_process_async
    [84] => getdns_eventloop_event_userarg_set
    [85] => getdns_eventloop_event_userarg_get
    [86] => getdns_eventloop_event_read_cb_set
    [87] => getdns_eventloop_event_read_cb_get
    [88] => getdns_eventloop_event_write_cb_set
    [89] => getdns_eventloop_event_write_cb_get
    [90] => getdns_eventloop_event_timeout_cb_set
    [91] => getdns_eventloop_event_timeout_cb_get
    [92] => getdns_eventloop_event_ev_set
    [93] => getdns_eventloop_event_ev_get
    [94] => new_getdns_eventloop_event
    [95] => getdns_eventloop_event_init
    [96] => getdns_eventloop_vmt_set
    [97] => getdns_eventloop_vmt_get
    [98] => new_getdns_eventloop
    [99] => getdns_eventloop_vmt_cleanup_set
    [100] => getdns_eventloop_vmt_cleanup_get
    [101] => getdns_eventloop_vmt_schedule_set
    [102] => getdns_eventloop_vmt_schedule_get
    [103] => getdns_eventloop_vmt_clear_set
    [104] => getdns_eventloop_vmt_clear_get
    [105] => getdns_eventloop_vmt_run_set
    [106] => getdns_eventloop_vmt_run_get
    [107] => getdns_eventloop_vmt_run_once_set
    [108] => getdns_eventloop_vmt_run_once_get
    [109] => new_getdns_eventloop_vmt
    [110] => getdns_context_set_eventloop
    [111] => getdns_context_detach_eventloop
    [112] => getdns_context_run
    [113] => swig_getdns_alter_newobject
    [114] => swig_getdns_get_newobject
)

Maybe it mattered that I had /usr/local/lib in my LD_LIBRARY_PATH though.

But this very direct approach doesn't give me an usable php interface
yet.  I guess you have to work around the pass by reference style of
returning values (besides the return code).

php > $c = NULL;
php > $r = getdns_context_create($c,1);
php > print "$r\n";

(i.e. 311 == GETDNS_RETURN_INVALID_PARAMETER)

php > $r = getdns_context_create(&$c,1);
PHP Fatal error:  Call-time pass-by-reference has been removed in php
shell code on line 1


Cheers,

-- Willem

Op 02-02-15 om 13:14 schreef Hollenbeck, Scott:
> I've been playing around with SWIG (http://www.swig.org/) in an attempt to create PHP language bindings for getdns. I've been able to build a PHP extension, but when I try to use it I get an "undefined function" error:
> 
> Fatal error: Call to undefined function getdns_context_create() in /path/getdns.php on line 679
> 
> These is the result of print_r(get_extension_funcs("getdns")):
> 
> Array
> (
>     [0] => getdns_address
>     [1] => getdns_address_sync
>     [2] => getdns_hostname
>     [3] => getdns_hostname_sync
>     [4] => getdns_service
>     [5] => getdns_service_sync
>     [6] => getdns_general
>     [7] => getdns_general_sync
>     [8] => getdns_dict_destroy
>     [9] => swig_getdns_alter_newobject
>     [10] => swig_getdns_get_newobject
> )
> 
> Here's some of what nm reports (note the undefined symbols):
> 
> sah at sah-vb:~/projects/getdns/src/php$ nm getdns.so|grep context
>                  U getdns_context_create
>                  U getdns_context_create_with_extended_memory_functions
>                  U getdns_context_create_with_memory_functions
>                  U getdns_context_destroy
> 
> My swig interface file:
> 
> %module getdns
> %{
> /* Put headers and other declarations here. */
> #include <getdns.h>
> #include <getdns_extra.h>
> %}
> 
> %include <getdns.h>
> %include <getdns_extra.h>
> 
> Here's how I'm building the extension:
> 
> swig -php -outcurrentdir -I/usr/local/include/getdns ../getdns.i
> gcc `php-config --includes` -fPIC -c -I/usr/local/include/getdns getdns_wrap.c
> gcc getdns_wrap.o -o getdns.so -shared -L/usr/local/lib -lgetdns
> 
> I wrote a small C program that works just fine using the same getdns shared library. I'm pretty sure I'm missing something obvious in the way I set up my SWIG interface and the code it produces, but I'm a SWIG noob - what did I miss?
> 
> Scott
> 
> _______________________________________________
> Users mailing list
> Users at getdnsapi.net
> http://getdnsapi.net/mailman/listinfo/users
> 




More information about the Users mailing list