I'm running the Wolfram Finance Package version of Mathematica 8, under Windows 7 Professional. Any time I attempt to call LibraryFunctionLoad, the Kernel seems to hang; I have to kill it (Evaluation->Quit Kernel->Local) in order for any further input in the notebook to be taken into account. (When I kill it, it leaves an orphaned java.exe still running, which I have to kill using the Task Manager.) I originally thought it might be something to do with the way I generated the DLL, but even when giving it the name of an non-existent file, it hangs (rather than giving an error message).

I was able to load and execute my program under Linux (with a demo version of Mathematica 8). What is different, and why don't I at least get an error message when the file doesn't exist? Also, I get similar symptoms when I use a \ as a path separator, rather than a /, even for simpler operations like

Join[$LibraryPath, {"C:\Users\jkanze"}]
  • 4
    $\begingroup$ For forming filename strings you should use FileNamejoin. This command takes care of the OS-specific filename seperators. Linux uses forward slashes. The backslash used in windows has the meaning of escape in strings. Think of the \n in C which means return. So a literal backslash in a string has to be escaped as well and becomes "\\". If you use FileNameJoin things like that are automatically covered and your code becomes more compatible. $\endgroup$ – Sjoerd C. de Vries Dec 7 '12 at 13:31
  • $\begingroup$ I'm interested in the case where it hangs even when the dll file doesn't exist. What happens when you execute FindFile["DoesNotExist.dll"]? $\endgroup$ – Todd Gayley Dec 7 '12 at 19:37
  • $\begingroup$ @ToddGayley It hung Friday, with a complete path (using /). It doesn't today, although I still cannot load my DLL. In fact, my file system was partially corrupted, with a lot of files suddenly belonging to Administrator (and thus not being accessible) rather than to me. This still doesn't explain why the errors caused the kernel to hang, but I'm unable to reproduce the problem since the admin fixed the file system, so who knows? $\endgroup$ – James Kanze Dec 10 '12 at 15:29
  • $\begingroup$ So we can write some of this off to the filesystem corruption? Sounds good to me. But you say you still cannot get the DLL to load. What happens? Does it hang or give you an error message? $\endgroup$ – Todd Gayley Dec 12 '12 at 8:40

Turning Sjoerd's comment into an answer: For forming file-name strings you should use FileNamejoin. This command takes care of the OS-specific file-name separators. The separator for directories for your specific OS is stored in the variable $PathnameSeparator and can be used too if you ever have to tweak things manually.

In your case, when I see this right, you shouldn't need this at all. It looks like your path is just your $HomeDirectory which can of course be accessed directly

AppendTo[$LibraryPath, $HomeDirectory]
| improve this answer | |
  • $\begingroup$ Actually / works as a file name separator on Windows. Generally, Win32 API functions accept paths with /. $\endgroup$ – Szabolcs Dec 7 '12 at 18:39
  • $\begingroup$ @Szabolcs I'm not sure this is true in general. I had situations where compiler calls on the commandline went wrong if you don't use backslash. In most cases it maybe works, but the OP used \ which stalled the kernel in the first place. If he would have used the appropriate functions without caring about the separator he wouldn't have lost debugging time. $\endgroup$ – halirutan Dec 7 '12 at 18:45
  • $\begingroup$ Yes, I agree that FileNameJoin is generally the safest. Also, as you noted, / is used an an "option character" for many built-in terminal commands, so it might mess things up on the command line. I just often find it tedious to type a path that's the same on all systems (e.g. in $InstallDirectory) as a list instead of just separating with / and appending to the base path $\endgroup$ – Szabolcs Dec 7 '12 at 20:53

For the path separator part, as the same for nearly all programming languages, '\' is a Escape character (http://en.wikipedia.org/wiki/Escape_character). To use it you will have to put it like:

Join [ $LibraryPath, { "C:\\Users\\jkanze" } ]

| improve this answer | |
  • $\begingroup$ Or just use '/', which works equally well in Windows and Unix. I'd figured out the problem with the '\', but still doesn't explain why the kernel hangs. (And it hangs in LibraryFunctionLoad even when I use '/'.) $\endgroup$ – James Kanze Dec 7 '12 at 18:20
  • $\begingroup$ That was what I explained before in my comment below the question. I also offered a better way of handling names using FilenameJoin. $\endgroup$ – Sjoerd C. de Vries Dec 7 '12 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.