Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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"}]
share|improve this question
4  
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. –  Sjoerd C. de Vries Dec 7 '12 at 13:31
    
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"]? –  Todd Gayley Dec 7 '12 at 19:37
    
@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? –  James Kanze Dec 10 '12 at 15:29
    
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? –  Todd Gayley Dec 12 '12 at 8:40
add comment

2 Answers 2

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]
share|improve this answer
    
Actually / works as a file name separator on Windows. Generally, Win32 API functions accept paths with /. –  Szabolcs Dec 7 '12 at 18:39
    
@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. –  halirutan Dec 7 '12 at 18:45
    
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 –  Szabolcs Dec 7 '12 at 20:53
add comment

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" } ]

share|improve this answer
    
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 '/'.) –  James Kanze Dec 7 '12 at 18:20
    
That was what I explained before in my comment below the question. I also offered a better way of handling names using FilenameJoin. –  Sjoerd C. de Vries Dec 7 '12 at 22:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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