.dll, .so and Cuda in Julia


#1

Hey there, I am kinda new to using C and Julia together and to using C altogether, so I have a few questions.

  1. Is it possible to load a .so library in a Windows version of Julia possibly with some help from Mingw?

  2. How can I view all the functions that a .dll or .so library exposes in Julia?

  3. Can a .dll or .so library have .cu (Cuda) files embedded and what is the right way to do that in Visual Studio or preferrably using the nvcc, gcc or clang compilers in command line?

  4. What is the easiest free way to have a Linux development environment in Windows with access to Linux versions of C, Julia and Cuda drivers (the VM killer, as far as I know), or is this too much to ask for from existing technology and I should just opt for dual boot?

  5. Finally, I keep getting “Unable to start program dll” in Visual Studio 2013 when I try making my first test dll (I am a dll virgin), and Julia cannot load it too. I tried loading other dll’s from existing software and it worked, so I am sure the problem is with my Visual Studio. So just like this is not the right place to ask most of the previous questions, I should be grateful if one of you would give me an out-of-place answer to how to solve this problem too.

Thanks a lot for everything you people are offering. Cheers!


#2

yes, provided it exposes C-callable functions (mingw not necessarily required)

https://docs.julialang.org/en/stable/stdlib/libdl/?highlight=dlopen#Base.Libdl.dlopen

Check exports with nm on most unix-like systems, otool on Mac or BSD, Dependency Walker (or many other options) on Windows.

This is kind of out of scope; check compiler and vendor documentation, try asking on StackOverflow, etc.

Probably too much. I believe Julia mostly works on WSL, but I doubt you can access raw GPU.

Dependency Walker may be useful here. (and StackOverflow: many detailed discussions of DLL issues).


#3

Thanks for your comments.

I tried a test .so file and I got the following error. This is also the same error I get when I try to open the (possibly corrupt) test .dll file. Is there something I am clearly doing wrong here?

julia> Libdl.dlopen("$(pwd())\\testFile.so")
ERROR: could not load library "C:\Users\user\Desktop\Learning C\testFile.so"
The operation completed successfully.

 in dlopen(::String, ::UInt32) at .\libdl.jl:90 (repeats 2 times)

Does that mean there is no way to do it from within Julia? Is it to be expected in future versions?


#4

Maybe compiling as ELF on Windows? Hard to say. Again, try Dependency Walker first (it’s free) and see if you have a valid COFF file (Windows DLL/.exe format) with the exports you expect.

There is no way to enumerate shared library symbols in base Julia, and probably won’t be added; you can use Libdl.dlsym to check for a specific symbol name. There are pure-Julia packages to read COFF, ELF, and MachO – you could try those (NAME.jl for each in google) – but probably better to use the recommended system tools while you are still getting familiar with compiler issues.


#5

Interestingly confusing. I think I will try again later, perhaps first on a Linux machine. Thanks for your time anyways.