Error: unbound variable module import pasted by tuxbrave on Wed Oct 21 12:02:01 2015

I am trying to compile the module curl.scm with the commands and the import the library (import curl) the module doesn't load and I got the error message: Error: unbound variable: curl#curl-get when I enter curl-get in the repl, however when I type (load "curl.so") and repeat the command it works.


file: Makefile

curl:
   csc -s curl.scm  -verbose -library -j curl  $(shell curl-config --libs)
   csc -s curl.import.scm -verbose -library -j curl  $(shell curl-config --libs)

Compilation Message:

$ make curl
csc -s curl.scm  -verbose -library -j curl  -L/usr/lib/i386-linux-gnu -lcurl
'/usr/local/bin/chicken' 'curl.scm' -output-file 'curl.c' -dynamic -feature chicken-compile-shared -feature chicken-compile-shared -verbose -emit-import-library curl

Note: re-importing already imported syntax: foreign-declare
not generating import library `curl.import.scm' for module `curl' because imports did not change

....

Note: global variable `curl#CURLE_COULDNT_RESOLVE_HOST' is only locally visible and never used

Note: global variable `curl#CURLE_URL_MALFORMAT' is only locally visible and never used
'gcc' 'curl.c' -o 'curl.o' -c  -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -fPIC -DPIC -DC_SHARED -fPIC -DPIC -DC_SHARED -I"/usr/local/include/chicken"
rm curl.c
'gcc' 'curl.o' -o 'curl.so' -shared -shared -L/usr/lib/i386-linux-gnu -lcurl -L"/usr/local/lib"  -Wl,-R"/usr/local/lib" -lchicken -lm -ldl
rm curl.o
csc -s curl.import.scm -verbose -library -j curl  -L/usr/lib/i386-linux-gnu -lcurl
'/usr/local/bin/chicken' 'curl.import.scm' -output-file 'curl.import.c' -dynamic -feature chicken-compile-shared -feature chicken-compile-shared -verbose -emit-import-library curl
'gcc' 'curl.import.c' -o 'curl.import.o' -c  -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -fPIC -DPIC -DC_SHARED -fPIC -DPIC -DC_SHARED -I"/usr/local/include/chicken"
rm curl.import.c
'gcc' 'curl.import.o' -o 'curl.import.so' -shared -shared -L/usr/lib/i386-linux-gnu -lcurl -L"/usr/local/lib"  -Wl,-R"/usr/local/lib" -lchicken -lm -ldl
rm curl.import.o


file: curl.import.scm

$ cat curl.import.scm 
;;;; curl.import.scm - GENERATED BY CHICKEN 4.10.0 -*- Scheme -*-

(eval '(import
         scheme
         chicken
         scheme
         chicken
         foreign
         sclj
         srfi-4
         extras
         ports
         lolevel
         lolevel
         easyffi
         srfi-4
         easyffi))
(##sys#register-compiled-module
  'curl
  (list)
  '((curl-get . curl#curl-get)
    (curl-post . curl#curl-post)
    (curl-download . curl#curl-download)
    (curl-post-show . curl#curl-post-show)
    (curl-get-show . curl#curl-get-show)
    (curl-test-get . curl#curl-test-get)
    (curl-test-post . curl#curl-test-post)
    (curl_easy_setopt . curl#curl_easy_setopt)
    (curl_easy_init . curl#curl_easy_init)
    (enum-curlfiletype . curl#enum-curlfiletype)
    (enum-CURLcode . curl#enum-CURLcode))
  (list)
  (list))

;; END OF FILE

Trouble:

rlwrap -c --remember csi

CHICKEN
(c) 2008-2015, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.10.0 (rev b259631)
linux-unix-gnu-x86 [ manyargs dload ptables ]
compiled 2015-08-04 on yves.more-magic.net (Linux)

#;1> (import curl)
; loading ./curl.import.so ...
; loading /usr/local/lib/chicken/7/chicken.import.so ...
; loading /usr/local/lib/chicken/7/foreign.import.so ...
; loading ./sclj.import.scm ...
; loading /usr/local/lib/chicken/7/ports.import.so ...
; loading /usr/local/lib/chicken/7/srfi-4.import.so ...
; loading /usr/local/lib/chicken/7/extras.import.so ...
; loading /usr/local/lib/chicken/7/lolevel.import.so ...
; loading /usr/local/lib/chicken/7/easyffi.import.so ...

Note: the following toplevel variables are referenced but unbound:

  plist-vals
  plist-keys
  plist->alist
#;2> 

(curl-get "http://httpbin.org/get")

Error: unbound variable: curl#curl-get

	Call history:

	<syntax>	  (curl-get "http://httpbin.org/get")
	<eval>	  (curl-get "http://httpbin.org/get")	<--
#;2> 

curl-get

Error: unbound variable: curl#curl-get
#;2> 

;;; However when I type
(load "curl.so")
; loading curl.so ...
#;3> curl-get
#<procedure (curl#curl-get url1191)>
#;4> 

(curl-get "http://httpbin.org/get")
"{\n  \"args\": {}, \n  \"headers\": {\n    \"Accept\": \"*/*\", \n    \"Host\": \"httpbin.org\", \n    \"User-Agent\": \"Mozzila/4.0\"\n  }, \n  \"origin\": \"275.173.154.129\", \n  \"url\": \"http://httpbin.org/get\"\n}\n"
#;5> 



Fix of Error: unbound variable: curl#curl-get added by Fix on Wed Oct 21 12:52:32 2015

Thanks to C-Keen (IRC). 

Change (import curl) to (use curl) in the repl.  

- import just imports the namespace but does not load code
- For compiled code is better to use "use" instead of "import"

#;1> (use curl)
; loading ./curl.import.so ...
; loading /usr/local/lib/chicken/7/chicken.import.so ...
; loading /usr/local/lib/chicken/7/foreign.import.so ...
; loading ./sclj.import.scm ...
; loading /usr/local/lib/chicken/7/ports.import.so ...
; loading /usr/local/lib/chicken/7/srfi-4.import.so ...
; loading /usr/local/lib/chicken/7/extras.import.so ...
; loading /usr/local/lib/chicken/7/lolevel.import.so ...
; loading /usr/local/lib/chicken/7/easyffi.import.so ...
; loading ./curl.so ...

Note: the following toplevel variables are referenced but unbound:

  plist-vals
  plist-keys
  plist->alist
#;2> (curl-get "http://httpbin.org/get")
"{\n  \"args\": {}, \n  \"headers\": {\n    \"Accept\": \"*/*\", \n    \"Host\": \"httpbin.org\", \n    \"User-Agent\": \"Mozzila/4.0\"\n  }, \n  \"origin\": \"174.172.155.241\", \n  \"url\": \"http://httpbin.org/get\"\n}\n"
#;3>