spvessel / spacevil

Simple examples of SpaceVIL implementation for C# / .NET Framework, C# / .NET Core and Java.
https://spvessel.com
MIT License
56 stars 7 forks source link

Unable to find an entry point named 'glfwGetMonitorContentScale' in shared library 'glfw' #4

Closed spektro37 closed 4 years ago

spektro37 commented 4 years ago

When following the steps to create a project using SpaceVIL on Ubuntu 18.04 using Dot Net Core 3.1 following the steps from the official website (https://spvessel.com/#downloads) an unhandled exception is thrown:

Unhandled exception. System.EntryPointNotFoundException: Unable to find an entry point named 'glfwGetMonitorContentScale' in shared library 'glfw'.
   at A.b.A(q , Single* , Single* )
   at A.b.A(q , Single& , Single& )
   at SpaceVIL.Common.CommonService.InitSpaceVILComponents()
   at MyApp.Program.Main(String[] args) in /home/username/MyApp/Program.cs:line 10

Code

Program.cs

using System;
using SpaceVIL;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if(!SpaceVIL.Common.CommonService.InitSpaceVILComponents())
            {
                return;
            }
            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();
        }
    }
}

MainWindow.cs

using SpaceVIL;

namespace MyApp
{
    public class MainWindow : ActiveWindow
    {
        public override void InitWindow()
        {
            SetParameters(nameof(MainWindow), nameof(MainWindow), 800, 600);
            SetMinSize(400, 300);
            SetBackground(32, 34, 37);
        }
    }
}

MyApp.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="SpaceVIL.dll" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="System.Drawing.Common" Version="4.6.0-preview7.19362.9" />
  </ItemGroup>

</Project>
spvessel commented 4 years ago

What is the version of glfw you are using? Glfw version must be 3.3.2 or later. What do you get if you call Console.WriteLine(SpaceVIL.Common.CommonService.GetSpaceVILInfo()) before InitSpaceVILComponents()?

spektro37 commented 4 years ago

I believe the newest version of GLFW available from Ubuntu repositories is 3.2.1-1. This is the version being installed when I execute the sudo apt-get install libglfw3 command as per the guide on the official web site. Is there a version of SpaceVIL that can work with this version of GLFW?

Using Console.WriteLine(SpaceVIL.Common.CommonService.GetSpaceVILInfo()) has provided the following output:

SpaceVIL version: 0.3.5.0-ALPHA - January 2020
Platform: .Net Core
OS type: Linux
spvessel commented 4 years ago

The best solution in this case is to extract libglfw.so from LWJGL.

  1. Download ZIP archive of LWJGL for Linux at https://www.lwjgl.org/customize (be sure that you selected GLFW and Linux Natives checkboxes). In archive you will find lwjgl-glfw-natives-linux.jar.
  2. Extract archive and you will get libglfw.so v3.3.2.
  3. Just copy that library inside the directory where your executable .Net Core DLL is located.
  4. After that try to run your app again.

Another solution is compile GLFW by yourself...

PS. you could also try SpaceVIL 0.3.4.3-ALPHA 10.03.2019 at https://spvessel.com/previous_versions.html

spvessel commented 4 years ago

By the way, download Nightly build of LWJGL (Release build do not contains libglfw.so version 3.3.2 )

spektro37 commented 4 years ago

I have compiled the GLFW myself and removed the GLFW packages I have installed previously from the Ubuntu repository. After that I have placed the libglfw.so file into the same folder where MyApp is being built to (.../Debug). However, I am getting a new error message now:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
 ---> System.DllNotFoundException: Unable to load DLL 'libgdiplus': The specified module could not be found.
   at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()
   --- End of inner exception stack trace ---
   at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)
   at System.Drawing.Image.InitializeFromStream(Stream stream)
   at System.Drawing.Bitmap..ctor(Stream stream, Boolean useIcm)
   at System.Drawing.Bitmap..ctor(Stream stream)
   at SpaceVIL.Common.DefaultsService.a()
   at SpaceVIL.Common.CommonService.InitSpaceVILComponents()
   at MyApp.Program.Main(String[] args) in /home/username/MyApp/Program.cs:line 10

Do I need to do anything additional (e.g. register the libglfw.so anywhere or add it to the .csproj file)?

spvessel commented 4 years ago

You need to install libgdiplus.so Try this https://github.com/stulzq/dotnetcore-image Or https://zoomadmin.com/HowToInstall/UbuntuPackage/libgdiplus

PS. I completely forgot to mention this in guide for Linux users. Sorry, my bad.

spektro37 commented 4 years ago

Thanks, now the demo is working!

I think it might be worthwhile mentioning in the guide that Ubuntu doesn't have the required version of GLFW (3.3.2) at the moment and that GLFW needs to be built and placed next to the SpaceVIL.dll (if I got it right) as a separate step.