Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] DLL loading error in F#  (Read 3619 times)

0 Members and 1 Guest are viewing this topic.

Kameko

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SOLVED] DLL loading error in F#
« on: November 02, 2015, 06:26:37 am »
Hello. I'm having some issues trying out SFML.NET. I'm not exactly sure how I'm supposed to compile an F# example manually? I don't use IDEs so I just make batch files, and, I can't seem to get this to work.

I'm getting a runtime exception that says "sfmlnet-window-2 or one of it's dependencies can't be loaded. An attempt was made to load an incorrect format". The example compiles, and it doesn't complain about any other assembly. Just that one.

I don't currently have a config file for my executable or anything, just kind of rawdogging it for now until I actually know how to use SFML from F#. So I put the four sfmlnet-*-2.dll files in the same directory as my executable, as well as all the other binaries (csfml-system-2.dll, etc.) in the same directory as well. I've already tried the precompiled "Window" example that comes with SFML.NET in the same directory, and it runs. So I don't know what's going wrong here.

This is the command I'm using:
fsc.exe test1.fs -I E:\PROJ\F_Sharp\SFML.Net-2.2\test -r sfmlnet-system-2.dll -r sfmlnet-audio-2.dll -r sfmlnet-graphics-2.dll -r sfmlnet-window-2.dll

And my code is:
namespace FSWindow

open System
open SFML
open SFML.Graphics
open SFML.Window
open SFML.System


module Window =
    [<EntryPoint>]
    let main argv =
       
        use mainWindow = new RenderWindow(VideoMode(600u, 600u), "EmptySpace")
        mainWindow.SetFramerateLimit(40u);
        mainWindow.Closed.AddHandler(fun sender args -> (sender :?> RenderWindow).Close())
       
        let rec mainLoop() =
            mainWindow.DispatchEvents()
            mainWindow.Display()
       
            match mainWindow.IsOpen with
            | true ->  mainLoop() |> ignore
            | false ->  ()
       
        mainLoop()
       
        0

 
« Last Edit: November 02, 2015, 08:51:55 am by Kameko »

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: DLL loading error in F#
« Reply #1 on: November 02, 2015, 07:08:15 am »
you also need to place 5 dll's from CSFML package.
sfmlnet-window-2.dll is just a wrapper for csfml-window.dll
« Last Edit: November 02, 2015, 07:09:53 am by mkalex777 »

Kameko

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: DLL loading error in F#
« Reply #2 on: November 02, 2015, 07:15:41 am »
Yeah, I've done that like I said in the OP: [img]

Those are the binaries from the "extlibs" folder. I've already tested the example Window.exe program and it works fine, it's only the F# code that I compile that doesn't work. I've also tested using fsc versions 12 and 14 as well.

Additionally, I just tested this with SFML.NET 2.1, and I got the same exact error. I'm not really sure what this means.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: DLL loading error in F#
« Reply #3 on: November 02, 2015, 08:04:39 am »
if you're using sfml.net 2.1, then you need to place csfml 2.1 libraries.
And make sure that your app has any cpu target and you're using csfml for appropriate target.
Actually OpenTK is not used , there is need for openal and libsnd (the last one is needed for csfml version lower than 2.3).

If you're still get the exception, please write what exactly excepion do you have.
I think that you're using csfml for incorrect cpu target
« Last Edit: November 02, 2015, 08:14:14 am by mkalex777 »

Kameko

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: DLL loading error in F#
« Reply #4 on: November 02, 2015, 08:51:39 am »
That solved it! Thank you!

I had considered the platform target, but the default is "anycpu" so I had figured it was okay. I looked at the compiler options and saw the lengthy and very specific "anycpu32bitpreferred" and tried that, and that works!

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: DLL loading error in F#
« Reply #5 on: November 02, 2015, 11:46:02 am »
That solved it! Thank you!

I had considered the platform target, but the default is "anycpu" so I had figured it was okay. I looked at the compiler options and saw the lengthy and very specific "anycpu32bitpreferred" and tried that, and that works!

It's bad. Just use any cpu and copy csfml binaries for x64 target if you run it on x64 system. If you run it on x32 system, just copy csfml binaries for x86 target. So in that way you don't need to rebuild your application. Just copy appropriate csfml binaries and that's it.

Also I described here on how to load x32/x64 libraries automatically. See my posts about linux
« Last Edit: November 02, 2015, 11:49:59 am by mkalex777 »