简体   繁体   English

C#.Net库找不到Linux上的依赖项

[英]C# .Net library cannot find dependencies on Linux

I am having issues with dependencies linking with my SFML.Net project: I successfully imported the SFML.Net DLLs, and thus the program compiles without problems. 我在与依赖项链接到我的SFML.Net项目时遇到问题:我成功导入了SFML.Net DLL,因此程序编译没有问题。 But once I run it, it crashes, telling the following: 但是一旦我运行它,它就会崩溃,并告诉以下内容:

System.DllNotFoundException: /usr/local/lib/libcsfml-graphics.so
  at (wrapper managed-to-native) SFML.Graphics.RenderWindow:sfRenderWindow_createUnicode (SFML.Window.VideoMode,intptr,SFML.Window.Styles,SFML.Window.ContextSettings&)
  at SFML.Graphics.RenderWindow..ctor (VideoMode mode, System.String title, Styles style, ContextSettings settings) [0x00043] in <filename unknown>:0 
  at SFML.Graphics.RenderWindow..ctor (VideoMode mode, System.String title) [0x0000b] in <filename unknown>:0 
  at SFML_Test.Game.Display () [0x00010] in <filename unknown>:0 
  at SFML_Test.Program.Main (System.String[] args) [0x00010] in <filename unknown>:0 

I am using the Mono compiler and Monodevelop IDE on Ubuntu Linux, so I am using dll mapping, which works (the .Net DLL does look for the correct path for the csfml library) 我在Ubuntu Linux上使用Mono编译器和Monodevelop IDE,所以我使用了dll映射,该映射有效(.Net DLL确实为csfml库寻找正确的路径)

Permissions are all set up 权限均已设置

alex@alexpc:/usr/local/lib$ ls -l
total 960
-rwxr-xr-x 1 alex alex   55833 Mar 22 07:35 libcsfml-audio.so.2.2
-rwxr-xr-x 1 alex alex   55833 Mar 22 07:35 libcsfml-audio.so.2.2.0
-rwxr-xr-x 1 alex alex  166721 Mar 22 07:35 libcsfml-graphics.so
-rwxr-xr-x 1 alex alex  166721 Mar 22 07:35 libcsfml-graphics.so.2.2
-rwxr-xr-x 1 alex alex  166721 Mar 22 07:35 libcsfml-graphics.so.2.2.0
-rwxr-xr-x 1 alex alex   69291 Mar 22 07:35 libcsfml-network.so
-rwxr-xr-x 1 alex alex   69291 Mar 22 07:35 libcsfml-network.so.2.2
-rwxr-xr-x 1 alex alex   69291 Mar 22 07:35 libcsfml-network.so.2.2.0
-rwxr-xr-x 1 alex alex   15287 Mar 22 07:35 libcsfml-system.so
-rwxr-xr-x 1 alex alex   15287 Mar 22 07:35 libcsfml-system.so.2.2
-rwxr-xr-x 1 alex alex   15287 Mar 22 07:35 libcsfml-system.so.2.2.0
-rwxr-xr-x 1 alex alex   32179 Mar 22 07:35 libcsfml-window.so
-rwxr-xr-x 1 alex alex   32179 Mar 22 07:35 libcsfml-window.so.2.2
-rwxr-xr-x 1 alex alex   32179 Mar 22 07:35 libcsfml-window.so.2.2.0

And the code is minimal: 代码是最少的:

Program.cs Program.cs

using System;

namespace SFML_Test
{
    public class Program 
    {
        public static void Main (string[] args)
        {
            Console.WriteLine("Starting window");
            Game game = new Game ();
            try
            {
                game.Display ();
            }
            catch (Exception e) {

                Console.WriteLine (e.ToString());
            }
        }
    }
}

Game.cs Game.cs

using System;
using SFML;
using SFML.Window;
using SFML.Graphics;
using SFML.System;

namespace SFML_Test
{
    class Game
    {
        private RenderWindow _window;

        public void Display ()
        {
            _window = new RenderWindow(new VideoMode(800, 600), "SFML window");
            _window.SetVisible(true);
            _window.Closed += new EventHandler(OnClosed);
            while (_window.IsOpen)
            {
                _window.DispatchEvents();
                _window.Clear(Color.Red);
                _window.Display();
            }
        }

        private void OnClosed(object sender, EventArgs e)
        {
            _window.Close();
        }
    }
}

I just don't get why the .Net dlls cannot find the csfml linux library even tho it clearly looks at the right directory and should find them without problems. 我只是不明白为什么.Net dll无法找到csfml linux库,即使它清楚地位于正确的目录下也应该没有问题地找到它们。

Of course I also tried removing the path from the mapping so the program would look into the executable's folder, to no avail 当然,我也尝试从映射中删除路径,以便程序可以查看可执行文件的文件夹,但无济于事

Anyone knows why this problem could be? 有人知道为什么会出现这个问题吗? Does the .Net DLL searches in some other folder (like /some/library/folder/usr/local/lib/libcsfml-graphics.so)? .NET DLL是否在其他文件夹中搜索(例如/some/library/folder/usr/local/lib/libcs​​fml-graphics.so)? That would explain why the file is plain not found. 这将解释为什么找不到纯文件。

I am kinda desperate at this point so if anyone knows, thumbs up for any answer! 在这一点上,我有点绝望,所以如果有人知道,竖起大拇指寻求任何答案!

Alex 亚历克斯

tl;dr: Mono compiler / Linux, .Net DLL cannot find another dependency even tho it searches in the right folder tl; dr:Mono编译器/Linux、.Net DLL即使在正确的文件夹中搜索也找不到其他依赖项

Oh boy, there is so much to say 哦,男孩,有太多话要说

so the problem was that the C binding needs the C++ sfml library, and it could not find it. 因此,问题在于C绑定需要C ++ sfml库,但找不到它。 I tried to move files around to make the libs in the same folder as my executable, and of course that was the windows way of doing it. 我试图四处移动文件以使这些库与我的可执行文件位于同一文件夹中,当然这是Windows的处理方法。 Turns out in Linux, the norm is to use the library cache to find said file. 事实证明,在Linux中,规范是使用库缓存来查找所述文件。 So I cached the sfml libraries using the ld.so.conf file, and it all worked out 因此,我使用ld.so.conf文件缓存了sfml库,并且全部解决了

Thanks to Evk for the clues 感谢Evk提供的线索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM