Bug 60454 - Bug since embedding native libraries ( from GtkSharp/2.12/bin*.dll into bundled app
Summary: Bug since embedding native libraries ( from GtkSharp/2.12/bin*.dll into bundl...
Status: RESOLVED FIXED
Alias: None
Product: Gtk#
Classification: Mono
Component: gtk-sharp ()
Version: 2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-31 15:26 UTC by Jens Eckervogt
Modified: 2017-11-01 14:35 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jens Eckervogt 2017-10-31 15:26:25 UTC
Hello everyone, 

I have bug because I already tried Windows Command and Cygwin's terminal throws if my bundled application can not load GtkSharp 2.12.x libraries:

D:\cygwin64\home\Jens\test>OutApp.exe
Mono: Loading Gtk Application!

Unhandled Exception:
System.DllNotFoundException: libglib-2.0-0.dll
  at (wrapper managed-to-native) GLib.Marshaller.g_malloc(uintptr)
  at GLib.Marshaller.StringToPtrGStrdup (System.String str) [0x0002a] in <7fabccec8b944d08a73d2c44188cf7f9>:0
  at GLib.Global.set_ProgramName (System.String value) [0x00001] in <7fabccec8b944d08a73d2c44188cf7f9>:0
  at Gtk.Application.SetPrgname () [0x0000d] in <64bd07ca456641de939ae0132964184c>:0
  at Gtk.Application.Init () [0x00001] in <64bd07ca456641de939ae0132964184c>:0
  at TestApp.MainClass.Main (System.String[] args) [0x0001c] in <6a68d7a11ae848f69ba08ecb3bca61b4>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libglib-2.0-0.dll
  at (wrapper managed-to-native) GLib.Marshaller.g_malloc(uintptr)
  at GLib.Marshaller.StringToPtrGStrdup (System.String str) [0x0002a] in <7fabccec8b944d08a73d2c44188cf7f9>:0
  at GLib.Global.set_ProgramName (System.String value) [0x00001] in <7fabccec8b944d08a73d2c44188cf7f9>:0
  at Gtk.Application.SetPrgname () [0x0000d] in <64bd07ca456641de939ae0132964184c>:0
  at Gtk.Application.Init () [0x00001] in <64bd07ca456641de939ae0132964184c>:0
  at TestApp.MainClass.Main (System.String[] args) [0x0001c] in <6a68d7a11ae848f69ba08ecb3bca61b4>:0

You know I have checked with Console.WriteLine("Test, test, test, ..."); <- It works fine 100 % yay.
But it can't load graphic mode like Unity's Editor or any embedded bundled mono-apps?
I am nervous because GtkSharp can load before like 4.8.1 no problem. Now Mono 5.9.x has still bugs

Please fix dllexport or dllimport from libmono-static-sgen.lib
Or I wish to have new method -resources="library1.dll, library2.dll" embedding unmanaged libraries if you managed own bundled app with important dll files from C/C++

Thanks! It's really sad because we can't do with embedded GUI surfaces like WInForms, Xwt, Eto:Forms or Gtk# or QtSharp and any frameworks for graphic mode.
OpenTK 2.0? I will check But I don't have to test OpenTK. I will try.

Bestr egards
Comment 1 Jens Eckervogt 2017-10-31 15:29:58 UTC
And I have checked tried GtkSharp library ( PS I already copied libraries to my bundled application directory. And it doesn't load. It can't work with loading dllexport or dllimport libraries.

Thanks!
Comment 2 johan.lorensson 2017-11-01 08:20:04 UTC
Hi Jens,

Verify the following things around the native library that fails to load.

1) Make sure failing library is visible for the loading process, part of its search paths.

2) Make sure you have a matching architecture of your native library and mono runtime, AFAIK, gtk runtime is only shipped as 32-bit libraries together with 32-bit Mono. If you try to load a 32-bit library into a 64-bit mono runtime, the LoadLibrary call will fail. A quick note on this. If you embedded using latest mono version build from source, mkbundle will now pick the architecture of the .NET runtime executing it (since it now supports both 32/64 bit builds). So, if you run mkbundle using a 64-bit runtime, it will create a 64-bit bundle and if you run mkbudle using a 32-bit runtime, you will get a 32-bit bundle. So, if gtk only ships with 32-bit libraries, you need to build a 32-bit bundle. Look at the OutputApp.exe and validate that it has been build using the right architecture, in your case it should be a 32-bit bundle to match shipped gtk libraries. This is a change in latest mono master build from source. In the past mkbundle was only capable of generating 32-bit bundles.

3) Check that all dependencies of the native library are available. Failing to load a dependency will also fail to load the library. A quick look at libglib-2.0-0.dll shows that it imports MSVCR120.dll, so make sure that c-runtime version is available on your system (I have seen cases on machines with only VS2017 not having older c-runtimes installed). If not, you need to install the redist to get hold of needed c-runtime version.

Also, will your gtk application load and run using regular mono command (not as a bundled application)?
Comment 3 Jens Eckervogt 2017-11-01 08:28:20 UTC
Thanks I forgot to resolve here. because I write end of post in github https://github.com/mono/mono/pull/5664#issuecomment-340729172

Yeah I know - since I found Xamarin Forum about any users have problem with MonoDevelop and detected architecture x64 and x86.

Thanks for explanation. I don't see because GtkSharp 2 and 3 support only 32 Bit. I am sorry about bad arguing. Please believe me! I am not stupid because I don't recognize about architectures. I am very inconsolably. Thanks

It is resolved!
Comment 4 Jens Eckervogt 2017-11-01 09:31:43 UTC
And but clang is really stupid to x64. Why does clang not use x86 if I am using Mono x86

I am surprised why does my Visual Studio 2017 Community not work for x86. I already installed fresh my WIndows 10. Why does clang get stupid if I want generate to x86-object:

Throw errors:
D:\cygwin\home\Jens\test>cl /MD /I "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include" /I "C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt" /I "C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um" /I "C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared" /I "C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\winrt" /I "include\mono-2.0" /I "." "temp.c" "temp.s.obj" /link /SUBSYSTEM:console /ENTRY:mainCRTStartup libmono-static-sgen.lib kernel32.lib version.lib ws2_32.lib mswsock.lib psapi.lib shell32.lib oleaut32.lib ole32.lib winmm.lib user32.lib advapi32.lib ucrt.lib vcruntime.lib msvcrt.lib oldnames.lib /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\lib\x86" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.16299.0\ucrt\x86" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.16299.0\um\x86" /LIBPATH:"lib" /LIBPATH:"." /OUT:"OutApp_x86.exe"
Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

temp.c
Microsoft (R) Incremental Linker Version 14.11.25547.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:temp.exe
/SUBSYSTEM:console
/ENTRY:mainCRTStartup
libmono-static-sgen.lib
kernel32.lib
version.lib
ws2_32.lib
mswsock.lib
psapi.lib
shell32.lib
oleaut32.lib
ole32.lib
winmm.lib
user32.lib
advapi32.lib
ucrt.lib
vcruntime.lib
msvcrt.lib
oldnames.lib
"/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\lib\x86"
"/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.16299.0\ucrt\x86"
"/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.16299.0\um\x86"
/LIBPATH:lib
/LIBPATH:.
/OUT:OutApp_x86.exe
temp.obj
temp.s.obj
temp.obj : error LNK2001: unresolved external symbol _assembly_data_TestApp_exe
temp.obj : error LNK2001: unresolved external symbol _assembly_data_mscorlib_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_gtk_sharp_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_glib_sharp_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_Mono_Security_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Configuration_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Xml_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Security_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Core_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_Mono_Posix_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_atk_sharp_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_gdk_sharp_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_pango_sharp_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_Mono_Cairo_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Windows_Forms_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Drawing_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Runtime_Serialization_Formatters_Soap_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_Accessibility_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_Mono_WebBrowser_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Data_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Numerics_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_EnterpriseServices_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_System_Transactions_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_I18N_West_dll
temp.obj : error LNK2001: unresolved external symbol _assembly_data_I18N_dll
OutApp_x86.exe : fatal error LNK1120: 26 unresolved externals

D:\cygwin\home\Jens\test>
Comment 5 johan.lorensson 2017-11-01 12:36:38 UTC
Hi Jens,

Please make sure you run mkbundle under 32-bit runtime since that is crucial for it to generate correct symbol mangling in temp.s and also picking the right version of assembler and compiler/linker matching the targeted architecture.

By default (not setting an assembler using AS environment variable) I get the following verbose output when running the assembling stage in mkbundle:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\ClangC2\14.10.25903\bin\HostX86\clang.exe" -c -x assembler -o temp.s.obj temp.s

so it picks up the x86 version of installed clang.exe. It then continues picking up the x86 version of cl.exe and x86 versions of libraries as well, creating a x86 binary.

Looks like you manually run the compile/link stage above, so it doesn't show how you generated temp.s.obj that should include the symbols it currently get as unresolved. Please validate the assembling step producing temp.s.obj. If you keep temps files and have a look in temp.s file you should find the unresolved symbols above and for x86 they should include a _ at the beginning of the symbol name (the x64 version doesn't).
Comment 6 Jens Eckervogt 2017-11-01 14:35:55 UTC
Hey Johan thanks!

I resolve that So sad notepad++ and notepad can't because it won't search over than ~5000 lines.

Wow penguin is like hero because unix/linux is very higher than Windows's text editors. Just Gedit for Windows and it can search next "assembly" than I write "_"
Or Replacement "assembly"XXXXXXX to "_assembly"XXXXXXX

Now it works fine wow. GtkSharp 2 embeds into Mono x86.

Thanks for help and you have to wake my dream as truth.
Now resolved - If I have to release finish application than you will get free because I see you helped me much. I never hide for you. I am busy for my own application - let surprise! Don't worry me! ;-)