Page 1 of 1
Executables and Dynamic Linking
Posted: Tue Aug 21, 2012 9:34 am
by iamnotanumber10
Hi, I'm following a tutorial
http://www.newlisp.org/newLISP_in_21_minutes.html and came to this part...
Executables and Dynamic Linking. I created hw.lsp and launched it from the command line successfully.
asdf@asdf:~$ newlisp hw.lsp
Hello World!
I tried to reproduce the executable example in the tutorial though and got the following...
asdf@asdf:~$ newlisp
newLISP v.10.4.3 on Linux IPv4/6 UTF-8 libffi, execute 'newlisp -h' for more info.
> (link "newlisp" "hw" "hw.lsp")
ERR: invalid function : (link "newlisp" "hw" "hw.lsp")
I'm using Ubuntu 12.04 32bit. Any ideas why the function is invalid?
Re: Executables and Dynamic Linking
Posted: Tue Aug 21, 2012 11:26 am
by cormullion
Can you try using the full pathname of the newLISP executable, eg /usr/bin/newlisp
Re: Executables and Dynamic Linking
Posted: Tue Aug 21, 2012 1:57 pm
by Lutz
Use the link procedure only on Windows. On Unix this procedure will not work when the newlisp executable is not in the current directory.
On Unix use script files with "#!/usr/bin/newlisp" in "#!/usr/bin/env newlisp" in the first line.
But when looking at your example, it looks as if you don't have loaded the file link.lsp which contains the link function.
Re: Executables and Dynamic Linking
Posted: Wed Aug 22, 2012 4:50 pm
by iamnotanumber10
Hi,
Whoops, it looks like I forgot to call link.lsp, but I still must be doing something wrong...
asdf@asdf:~$ newlisp link.lsp
newLISP v.10.4.3 on Linux IPv4/6 UTF-8 libffi, execute 'newlisp -h' for more info.
> (link "newlisp" "hw" "hw.lsp")
ERR: invalid function : (link "newlisp" "hw" "hw.lsp")
Updated hw.lsp file...
#!/usr/bin/newlisp
; hw.lsp
(println "Hello World!")
(exit)
?
Re: Executables and Dynamic Linking
Posted: Mon Sep 03, 2012 6:30 pm
by iamnotanumber10
Ok Folks, I've cracked it!
> (load "/usr/share/newlisp/util/link.lsp")
(lambda (orgExe newExeName lispSourceName) (println "original newlisp executable:"
orgExe)
(println "new executable:" newExeName)
(println "source:" lispSourceName)
(set 'size (first (file-info orgExe)))
(copy-file orgExe newExeName)
(set 'buff (pack "ld" size))
(set 'handle (open newExeName "u"))
(search handle "@@@@@@@@")
(write-buffer handle buff 4)
(set 'buff (read-file lispSourceName))
(set 'keylen (pack "ld" (length buff)))
(write-buffer handle keylen 4)
(seek handle size)
(set 'buff (encrypt buff (string (length buff))))
(write-buffer handle buff (length buff))
(close handle))
then
> (link "/usr/bin/newlisp" "hw" "hw.lsp")
original newlisp executable:/usr/bin/newlisp
new executable:hw
source:hw.lsp
true