UnableToLoad
UnableToLoad

Reputation: 315

load library from lisp script, working directory and path

I need to load a library in a LISP script.

The script "loader.lisp" and the library "mylib.dll" are in the same folder "parent_dir".

If I run the script from inside the folder (current directory = "parent_dir") it works fine:

(load "loader.lisp") ;OK lib loaded successfully

but if the current directory is somewhere else, it fails to load (of course it looks for the lib in the wrong dir):

(load "parent_dir/loader.lisp") ;ERROR, of course I'm in the wrong working dir!

;Error opening shared object "mylib.dll":
;dlopen(mylib.dll, 10): image not found.

The "loader.lisp" script contains (also) the following code:

(setq LIB_PATH "mylib.dll")

(if (string= (software-type) "Darwin")
    (setq LIB_PATH "mylib_osx.lib"))

#+allegro
  (load LIB_PATH)
#+sbcl
  (sb-alien:load-shared-object LIB_PATH)

The question is: how can I make the loader.lisp script "working directory"-independent?

UPDATE: I specify that the script ant the interpreter executable are not in the same directory.

Thank you very much!

Upvotes: 0

Views: 675

Answers (1)

Mark Karpov
Mark Karpov

Reputation: 7599

I would suggest the following solutions:

  • Use full path;
  • Keep the library file always in the same directory as your program (well, sometimes it's not a bad idea);
  • Change parameter "start in" of your program;
  • Add path to your library file into OS variable "PATH".

It's rather a question about concept of OS working directory than about Lisp itself.

As far as I see solution involving "PATH" variable could be the best one. You can just test this method and tell us if it worked.

How to set path in Windows.

Upvotes: 1

Related Questions