Executables and Dynamic Linking

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
iamnotanumber10
Posts: 4
Joined: Wed Jul 11, 2012 4:36 pm
Location: Finland

Executables and Dynamic Linking

Post 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?

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Executables and Dynamic Linking

Post by cormullion »

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Executables and Dynamic Linking

Post 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.

iamnotanumber10
Posts: 4
Joined: Wed Jul 11, 2012 4:36 pm
Location: Finland

Re: Executables and Dynamic Linking

Post 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)
?

iamnotanumber10
Posts: 4
Joined: Wed Jul 11, 2012 4:36 pm
Location: Finland

Re: Executables and Dynamic Linking

Post 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

Locked