Skip to content

Doesn't run on linux (Kubuntu 18.10), but compiles without any issues #83

Closed

Description

@FilipeSilvens

Unhandled Exception: System.IO.FileNotFoundException: Failed to load native core functions! Couldnt find at location /home/shiruba/ReClass.NET/ReClass.NET/bin/Debug/x64/NativeCore.so

Compiled and then moved the NativeCore shared object to the directory of the executable and ran it with mono (tried with root as well).

Distro: Kubuntu 18.10
Mono version: 5.18.0.225

Activity

  1. changed the title [-]Doesn't run on linux (Kubuntu 18.10), but compiles without an issue[/-] [+]Doesn't run on linux (Kubuntu 18.10), but compiles without any issues[/+] on Jan 7, 2019
  2. KN4CK3R commented on Jan 7, 2019

    @KN4CK3R
    Member

    That's the same problem I had in #47 or? If so, I haven't figured out what the problem was/is. Maybe dlopen can't load a dependency?

  3. FilipeSilvens commented on Jan 7, 2019

    @FilipeSilvens
    Author

    Does it successfully import libdl.so?

    [DllImport("libdl.so")]
    private static extern IntPtr dlopen(string fileName, int flags);

  4. KN4CK3R commented on Jan 7, 2019

    @KN4CK3R
    Member

    I think so. dlopen just returns IntPtr.Zero. Are you able to compile ReClass.NET? You could add a dlerror call to see if the error message tells something usefull.

    The new code could look like this:

    public IntPtr LoadLibrary(string fileName)
    {
    	var handle = dlopen(fileName, RTLD_NOW);
    	if (handle.IsNull())
    	{
    		throw new ...Exception(dlerror());
    	}
    	return handle;
    }

    With the equivalent for Windows and GetLastError (or better use DllImportAttribute.SetLastError). After that

    var handle = NativeMethods.LoadLibrary(libraryPath);
    if (handle.IsNull())
    {
    throw new FileNotFoundException($"Failed to load native core functions! Couldnt find at location {libraryPath}");
    }

    and
    var handle = NativeMethods.LoadLibrary(filePath);
    if (handle.IsNull())
    {
    throw new FileLoadException($"Failed to load native plugin: {Path.GetFileName(filePath)}");
    }

    should be changed to use the exception.

  5. FilipeSilvens commented on Jan 7, 2019

    @FilipeSilvens
    Author

    Yes, as I stated in the title, I am able to compile.

    The code you have provided does not compile due to the fact that IntPtr doesn't contain the IsNull definition.

    error CS1061: 'IntPtr' does not contain a definition for 'IsNull' and no extension method 'IsNull' accepting a first argument of type 'IntPtr' could be found

    Edit: I have fixed the code and the exception returned the following message:
    Unhandled Exception: System.Exception: dlopen exception: /home/shiruba/ReClass.NET/ReClass.NET/bin/Debug/x64/NativeCore.so: undefined symbol: _ZNKSt25__codecvt_utf8_utf16_baseIDsE6do_outER11__mbstate_tPKDsS4_RS4_PcS6_RS6_

  6. KN4CK3R commented on Jan 7, 2019

    @KN4CK3R
    Member

    Here is IsNull():

    [Pure]
    [DebuggerStepThrough]
    public static bool IsNull(this IntPtr ptr)
    {
    return ptr == IntPtr.Zero;
    }

    So now it is clear why the library can't be loaded. But why does this message occur? Shouldn't the linker detect this error at compile time?
    @stevemk14ebr: Do you have an idea?

  7. FilipeSilvens commented on Jan 7, 2019

    @FilipeSilvens
    Author

    Running the program with "sudo MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono ReClass.NET.exe" printed some more interesting information:

    https://gist.github.com/FilipeSilvens/f373e89453ecc084cf65af08e15d29ae

  8. KN4CK3R commented on Jan 7, 2019

    @KN4CK3R
    Member

    The logged exception is just the exception you have created or not?

  9. FilipeSilvens commented on Jan 7, 2019

    @FilipeSilvens
    Author

    It is. I replaced the LoadLibrary code with this:

    public IntPtr LoadLibrary(string fileName)
    {
        dlerror(); // clears any previous errors
        var handle = dlopen(fileName, RTLD_NOW | RTLD_GLOBAL);
        var errorPtr = dlerror();
        if (errorPtr != IntPtr.Zero) 
        {
            throw new Exception("dlopen exception: " + Marshal.PtrToStringAnsi(errorPtr));
        }
        return handle;
    }

    and imported dlerror, of course.

  10. stevemk14ebr commented on Jan 7, 2019

    @stevemk14ebr
    Contributor

    I never got past failing to open NativeCore.so it's always not found for me, so yea it's related to #47 . I'm also on Ubuntu 17.10 though which is not officially supported by mono it seems, im running the packages for 16.04 which yea is probably not good so don't rely on me.

    Unhandled Exception:
    System.IO.FileNotFoundException: Failed to load native core functions! Couldnt find at location /home/steve/Desktop/ReClass.NET/ReClass.NET/bin/Debug/x86/NativeCore.so
    at ReClassNET.Core.InternalCoreFunctions.Create () [0x0003e] in :0
    at ReClassNET.Core.CoreFunctionsManager..ctor () [0x00013] in :0
    at ReClassNET.Program.Main (System.String[] args) [0x00097] in :0
    [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Failed to load native core functions! Couldnt find at location /home/steve/Desktop/ReClass.NET/ReClass.NET/bin/Debug/x86/NativeCore.so
    at ReClassNET.Core.InternalCoreFunctions.Create () [0x0003e] in :0
    at ReClassNET.Core.CoreFunctionsManager..ctor () [0x00013] in :0
    at ReClassNET.Program.Main (System.String[] args) [0x00097] in :0

  11. FilipeSilvens commented on Jan 7, 2019

    @FilipeSilvens
    Author

    @stevemk14ebr can you replace the LoadLibrary function in NativeMethods.Unix.cs with the one I posted above to see if the error is the same on different ubuntu versions?

    Also don't forget to import dlerror above

    [DllImport("libdl.so")]
    private static extern IntPtr dlerror();
  12. stevemk14ebr commented on Jan 7, 2019

    @stevemk14ebr
    Contributor

    yup it is:

    Unhandled Exception:
    System.Exception: dlopen exception: /home/steve/Desktop/ReClass.NET/ReClass.NET/bin/Debug/x86/NativeCore.so: undefined symbol: ZNKSt25__codecvt_utf8_utf16_baseIDsE6do_outER11__mbstate_tPKDsS4_RS4_PcS6_RS6
    at ReClassNET.Native.NativeMethodsUnix.LoadLibrary (System.String fileName) [0x00035] in :0
    at ReClassNET.Native.NativeMethods.LoadLibrary (System.String name) [0x00001] in :0
    at ReClassNET.Core.InternalCoreFunctions.Create () [0x00021] in :0
    at ReClassNET.Core.CoreFunctionsManager..ctor () [0x00013] in :0
    at ReClassNET.Program.Main (System.String[] args) [0x00097] in :0
    [ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: dlopen exception: /home/steve/Desktop/ReClass.NET/ReClass.NET/bin/Debug/x86/NativeCore.so: undefined symbol: ZNKSt25__codecvt_utf8_utf16_baseIDsE6do_outER11__mbstate_tPKDsS4_RS4_PcS6_RS6
    at ReClassNET.Native.NativeMethodsUnix.LoadLibrary (System.String fileName) [0x00035] in :0
    at ReClassNET.Native.NativeMethods.LoadLibrary (System.String name) [0x00001] in :0
    at ReClassNET.Core.InternalCoreFunctions.Create () [0x00021] in :0
    at ReClassNET.Core.CoreFunctionsManager..ctor () [0x00013] in :0
    at ReClassNET.Program.Main (System.String[] args) [0x00097] in :0

  13. stevemk14ebr commented on Jan 7, 2019

    @stevemk14ebr
    Contributor

    the offending symbol is: std::__codecvt_utf8_utf16_base<char16_t>::do_out(__mbstate_t&, char16_t const*, char16_t const*, char16_t const*&, char*, char*, char*&) const

    but there's alot of undefined symbols, something is wrong in linking i think:

    nm NativeCore.so | grep ZNKSt25__codecvt_utf8_utf16_baseIDsE6do_outER11__mbstate_tPKDsS4_RS4_PcS6_RS6 -B 3 -A 3

    nm --demangle NativeCore.so | grep 22518 -B 3 -A 3

  14. stevemk14ebr commented on Jan 8, 2019

    @stevemk14ebr
    Contributor

    #84 will catch these at link time, still don't know why there's so many undefined though.

  15. FilipeSilvens commented on Jan 8, 2019

    @FilipeSilvens
    Author

    I have managed to fix the undefined symbols, but now I get an out of range exception when I start the program.
    https://gist.github.com/FilipeSilvens/69194e690b5a2def90a34b58e085cfdb

    The original issue which is also present in #47 can be fixed by linking -lstdc++ and -ldl in the NativeCore's Makefile.

  16. stevemk14ebr commented on Jan 8, 2019

    @stevemk14ebr
    Contributor

    Fixed in #86 and #85 may be incomplete fix for scroll bar behavior

  17. FilipeSilvens commented on Jan 8, 2019

    @FilipeSilvens
    Author

    Yup, all works good now. Thank you for helping :D

  18. KN4CK3R commented on Jan 8, 2019

    @KN4CK3R
    Member

    Thank you @stevemk14ebr for your help!

  19. stevemk14ebr commented on Jan 8, 2019

    @stevemk14ebr
    Contributor

    Welcome 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions