Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FilipeSilvens opened this issue Jan 7, 2019 · 18 comments
Closed

Comments

@FilipeSilvens
Copy link

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

@FilipeSilvens FilipeSilvens 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 Jan 7, 2019
@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 7, 2019

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?

@FilipeSilvens
Copy link
Author

FilipeSilvens commented Jan 7, 2019

Does it successfully import libdl.so?

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

@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 7, 2019

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.

@FilipeSilvens
Copy link
Author

FilipeSilvens commented Jan 7, 2019

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_

@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 7, 2019

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?

@FilipeSilvens
Copy link
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

@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 7, 2019

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

@FilipeSilvens
Copy link
Author

FilipeSilvens commented Jan 7, 2019

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.

@stevemk14ebr
Copy link
Contributor

stevemk14ebr commented Jan 7, 2019

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

@FilipeSilvens
Copy link
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();

@stevemk14ebr
Copy link
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

@stevemk14ebr
Copy link
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

@stevemk14ebr
Copy link
Contributor

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

@FilipeSilvens
Copy link
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.

@stevemk14ebr
Copy link
Contributor

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

@FilipeSilvens
Copy link
Author

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

@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 8, 2019

Thank you @stevemk14ebr for your help!

@stevemk14ebr
Copy link
Contributor

Welcome 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants