Executables and Dynamic Linking

Started by iamnotanumber10, August 21, 2012, 02:34:05 AM

Previous topic - Next topic

iamnotanumber10

Hi, I'm following a tutorial http://www.newlisp.org/newLISP_in_21_minutes.html">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.
Quoteasdf@asdf:~$ newlisp hw.lsp

Hello World!

I tried to reproduce the executable example in the tutorial though and got the following...
Quoteasdf@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?

cormullion

#1
Can you try using the full pathname of the newLISP executable, eg /usr/bin/newlisp

Lutz

#2
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.

iamnotanumber10

#3
Hi,

Whoops, it looks like I forgot to call link.lsp, but I still must be doing something wrong...
Quoteasdf@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...
Quote#!/usr/bin/newlisp

;  hw.lsp



(println "Hello World!")

(exit)


?

iamnotanumber10

#4
Ok Folks, I've cracked it!


Quote> (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
Quote> (link "/usr/bin/newlisp" "hw" "hw.lsp")

original newlisp executable:/usr/bin/newlisp

new executable:hw

source:hw.lsp

true