Robmaister / SharpFont

Cross-platform FreeType bindings for .NET - Need maintainer
Other
294 stars 107 forks source link

System.DllNotFoundException on 32-bit Linux #110

Closed PayDay1 closed 7 years ago

PayDay1 commented 7 years ago

Hello,

so I just finished putting a text renderer into OOP-context. It works fine on Windows, but when I try it on my 32-bit Linux netbook, I get a System.DllNotFoundException freetype6.dll on the first SharpFont call.

I don't understand this. I thought native libraries are in .so format. I added SharpFont.Dependencies to the project and made sure that all .so (and .dll) files are in my executable folder (bin/Debug/).

EDIT: SharpFont.dll.config is also in the output folder.

Robmaister commented 7 years ago

Just as a sanity check, you did install freetype via your package manager, correct?

Something along the lines of this, will be different based on your distro/package manager: apt-get install libfreetype6

C# handles native libraries a little weirdly. On the C# side, we specify "freetype6.dll", and for other platforms, the .dll.config file maps "freetype6.dll" to the correct .so/.dylib/whaever file is for that platform.

HinTak commented 7 years ago

Putting random stuff next to SharpFont.dll might cause look up to fail. On linux, libfreetype.so.6 should be in system location I.e. /usr/lib. It is possible however netbook has everything referring to the detailed versions (i.e. libfreetype.so.6.x.y), in which case you need to either create the symlink manually, or do apt-get install libfreetype6-dev. The important thing is, what does

ls /usr/lib*/libfreetype6*

says on your system?

PayDay1 commented 7 years ago

Just as a sanity check, you did install freetype via your package manager, correct?

Yes. Both libfreetype6 and libfreetype6-dev are installed. (I'm on xubuntu)

C# handles native libraries a little weirdly. On the C# side, we specify "freetype6.dll", and for other platforms, the .dll.config file maps "freetype6.dll" to the correct .so/.dylib/whaever file is for that platform.

So the .config file should help to find the .so file...?

ls /usr/lib*/libfreetype6* returns that this file or directory doesn't exist. I also tested it on my 64-bit PC running xubuntu, same thing.

EDIT: I can confirm that this issue is also present on my ARM machine. (ODROID-XU4)

Robmaister commented 7 years ago

Another question - are you using Mono or .NET Core? The .dll.config file only works under Mono. I don't believe .NET Core has anything set up yet for cross-platform native library bindings yet (though there has been plenty of discussion)

PayDay1 commented 7 years ago

I am using Mono.

HinTak commented 7 years ago

Sorry, ls /usr/lib*/libfreetype* without the 6.

PayDay1 commented 7 years ago

Doesn't exist either.

HinTak commented 7 years ago
ls /lib*/libfreetype*  /usr/*/lib*/libfreetype*`

Actually, try this to see how the packages are installed:

dpkg-query -L libfreetype6
dpkg-query -L libfreetype6-dev
PayDay1 commented 7 years ago

ls /lib/libfreetype /usr//lib/libfreetype*

Returns that this file or directory doesn't exist.

dpkg-query -L libfreetype6

/.
/usr
/usr/lib
/usr/lib/i386-linux-gnu
/usr/lib/i386-linux-gnu/libfreetype.so.6.12.3
/usr/share
/usr/share/doc
/usr/share/doc/libfreetype6
/usr/share/doc/libfreetype6/FTL.TXT.gz
/usr/share/doc/libfreetype6/TODO
/usr/share/doc/libfreetype6/changelog.Debian.gz
/usr/share/doc/libfreetype6/copyright
/usr/share/doc/libfreetype6/ft2faq.html
/usr/share/doc/libfreetype6/pcf
/usr/share/doc/libfreetype6/pcf/README
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libfreetype6
/usr/lib/i386-linux-gnu/libfreetype.so.6

dpkg-query -L libfreetype6-dev

/.
/usr
/usr/bin
/usr/bin/freetype-config
/usr/include
/usr/include/freetype2
/usr/include/freetype2/freetype
/usr/include/freetype2/freetype/config
/usr/include/freetype2/freetype/config/ftconfig.h
/usr/include/freetype2/freetype/config/ftheader.h
/usr/include/freetype2/freetype/config/ftmodule.h
/usr/include/freetype2/freetype/config/ftoption.h
/usr/include/freetype2/freetype/config/ftstdlib.h
/usr/include/freetype2/freetype/freetype.h
/usr/include/freetype2/freetype/ftadvanc.h
/usr/include/freetype2/freetype/ftautoh.h
/usr/include/freetype2/freetype/ftbbox.h
/usr/include/freetype2/freetype/ftbdf.h
/usr/include/freetype2/freetype/ftbitmap.h
/usr/include/freetype2/freetype/ftbzip2.h
/usr/include/freetype2/freetype/ftcache.h
/usr/include/freetype2/freetype/ftcffdrv.h
/usr/include/freetype2/freetype/ftchapters.h
/usr/include/freetype2/freetype/ftcid.h
/usr/include/freetype2/freetype/fterrdef.h
/usr/include/freetype2/freetype/fterrors.h
/usr/include/freetype2/freetype/ftfntfmt.h
/usr/include/freetype2/freetype/ftgasp.h
/usr/include/freetype2/freetype/ftglyph.h
/usr/include/freetype2/freetype/ftgxval.h
/usr/include/freetype2/freetype/ftgzip.h
/usr/include/freetype2/freetype/ftimage.h
/usr/include/freetype2/freetype/ftincrem.h
/usr/include/freetype2/freetype/ftlcdfil.h
/usr/include/freetype2/freetype/ftlist.h
/usr/include/freetype2/freetype/ftlzw.h
/usr/include/freetype2/freetype/ftmac.h
/usr/include/freetype2/freetype/ftmm.h
/usr/include/freetype2/freetype/ftmodapi.h
/usr/include/freetype2/freetype/ftmoderr.h
/usr/include/freetype2/freetype/ftotval.h
/usr/include/freetype2/freetype/ftoutln.h
/usr/include/freetype2/freetype/ftpfr.h
/usr/include/freetype2/freetype/ftrender.h
/usr/include/freetype2/freetype/ftsizes.h
/usr/include/freetype2/freetype/ftsnames.h
/usr/include/freetype2/freetype/ftstroke.h
/usr/include/freetype2/freetype/ftsynth.h
/usr/include/freetype2/freetype/ftsystem.h
/usr/include/freetype2/freetype/fttrigon.h
/usr/include/freetype2/freetype/ftttdrv.h
/usr/include/freetype2/freetype/fttypes.h
/usr/include/freetype2/freetype/ftwinfnt.h
/usr/include/freetype2/freetype/t1tables.h
/usr/include/freetype2/freetype/ttnameid.h
/usr/include/freetype2/freetype/tttables.h
/usr/include/freetype2/freetype/tttags.h
/usr/include/freetype2/freetype/ttunpat.h
/usr/include/freetype2/ft2build.h
/usr/include/i386-linux-gnu
/usr/include/i386-linux-gnu/freetype2
/usr/include/i386-linux-gnu/freetype2/freetype
/usr/include/i386-linux-gnu/freetype2/freetype/config
/usr/include/i386-linux-gnu/freetype2/freetype/config/ftconfig.h
/usr/include/i386-linux-gnu/freetype2/freetype/config/ftheader.h
/usr/include/i386-linux-gnu/freetype2/freetype/config/ftmodule.h
/usr/include/i386-linux-gnu/freetype2/freetype/config/ftoption.h
/usr/include/i386-linux-gnu/freetype2/freetype/config/ftstdlib.h
/usr/lib
/usr/lib/i386-linux-gnu
/usr/lib/i386-linux-gnu/libfreetype.a
/usr/lib/i386-linux-gnu/libfreetype.la
/usr/lib/i386-linux-gnu/pkgconfig
/usr/lib/i386-linux-gnu/pkgconfig/freetype2.pc
/usr/share
/usr/share/aclocal
/usr/share/aclocal/freetype2.m4
/usr/share/doc
/usr/share/doc/libfreetype6
/usr/share/doc/libfreetype6/CMAKE
/usr/share/doc/libfreetype6/CUSTOMIZE.gz
/usr/share/doc/libfreetype6/DEBUG.gz
/usr/share/doc/libfreetype6/MAKEPP
/usr/share/doc/libfreetype6/PROBLEMS
/usr/share/doc/libfreetype6/VERSION.DLL
/usr/share/doc/libfreetype6/css
/usr/share/doc/libfreetype6/css/freetype.css
/usr/share/doc/libfreetype6/css/freetype2.css
/usr/share/doc/libfreetype6/css/freetype2_-30.css
/usr/share/doc/libfreetype6/css/freetype2_-60.css
/usr/share/doc/libfreetype6/css/freetype2_-90.css
/usr/share/doc/libfreetype6/css/freetype2_30.css
/usr/share/doc/libfreetype6/css/freetype2_60.css
/usr/share/doc/libfreetype6/css/freetype2_90.css
/usr/share/doc/libfreetype6/design
/usr/share/doc/libfreetype6/design/basic-design.png
/usr/share/doc/libfreetype6/design/design-1.html
/usr/share/doc/libfreetype6/design/design-2.html
/usr/share/doc/libfreetype6/design/design-3.html
/usr/share/doc/libfreetype6/design/design-4.html
/usr/share/doc/libfreetype6/design/design-5.html
/usr/share/doc/libfreetype6/design/design-6.html
/usr/share/doc/libfreetype6/design/detailed-design.png
/usr/share/doc/libfreetype6/design/index.html
/usr/share/doc/libfreetype6/design/library-model.png
/usr/share/doc/libfreetype6/design/simple-model.png
/usr/share/doc/libfreetype6/documentation.html
/usr/share/doc/libfreetype6/formats.txt.gz
/usr/share/doc/libfreetype6/freetype-config.1
/usr/share/doc/libfreetype6/glyphs
/usr/share/doc/libfreetype6/glyphs/Image1.png
/usr/share/doc/libfreetype6/glyphs/Image2.png
/usr/share/doc/libfreetype6/glyphs/Image3.png
/usr/share/doc/libfreetype6/glyphs/Image4.png
/usr/share/doc/libfreetype6/glyphs/bbox1.png
/usr/share/doc/libfreetype6/glyphs/bbox2.png
/usr/share/doc/libfreetype6/glyphs/body_comparison.png
/usr/share/doc/libfreetype6/glyphs/bravo_kerned.png
/usr/share/doc/libfreetype6/glyphs/bravo_unkerned.png
/usr/share/doc/libfreetype6/glyphs/clipping.png
/usr/share/doc/libfreetype6/glyphs/down_flow.png
/usr/share/doc/libfreetype6/glyphs/glyphs-1.html
/usr/share/doc/libfreetype6/glyphs/glyphs-2.html
/usr/share/doc/libfreetype6/glyphs/glyphs-3.html
/usr/share/doc/libfreetype6/glyphs/glyphs-4.html
/usr/share/doc/libfreetype6/glyphs/glyphs-5.html
/usr/share/doc/libfreetype6/glyphs/glyphs-6.html
/usr/share/doc/libfreetype6/glyphs/glyphs-7.html
/usr/share/doc/libfreetype6/glyphs/grid_1.png
/usr/share/doc/libfreetype6/glyphs/index.html
/usr/share/doc/libfreetype6/glyphs/points_conic.png
/usr/share/doc/libfreetype6/glyphs/points_conic2.png
/usr/share/doc/libfreetype6/glyphs/points_cubic.png
/usr/share/doc/libfreetype6/glyphs/points_segment.png
/usr/share/doc/libfreetype6/glyphs/twlewis1.png
/usr/share/doc/libfreetype6/glyphs/twlewis2.png
/usr/share/doc/libfreetype6/glyphs/up_flow.png
/usr/share/doc/libfreetype6/image
/usr/share/doc/libfreetype6/image/BlendingExamples-thumbnail.jpg
/usr/share/doc/libfreetype6/image/BlendingExamples.png
/usr/share/doc/libfreetype6/image/favicon.ico
/usr/share/doc/libfreetype6/image/favicon_-30.ico
/usr/share/doc/libfreetype6/image/favicon_-60.ico
/usr/share/doc/libfreetype6/image/favicon_-90.ico
/usr/share/doc/libfreetype6/image/favicon_30.ico
/usr/share/doc/libfreetype6/image/favicon_60.ico
/usr/share/doc/libfreetype6/image/favicon_90.ico
/usr/share/doc/libfreetype6/image/fond2-small.png
/usr/share/doc/libfreetype6/image/fond2.png
/usr/share/doc/libfreetype6/image/fond3.jpg
/usr/share/doc/libfreetype6/image/fond3.png
/usr/share/doc/libfreetype6/image/fond3_-30.png
/usr/share/doc/libfreetype6/image/fond3_-60.png
/usr/share/doc/libfreetype6/image/fond3_-90.png
/usr/share/doc/libfreetype6/image/fond3_30.png
/usr/share/doc/libfreetype6/image/fond3_60.png
/usr/share/doc/libfreetype6/image/fond3_90.png
/usr/share/doc/libfreetype6/image/freetype-262-autohinter-stem-darkening-demo1-thumbnail.jpg
/usr/share/doc/libfreetype6/image/freetype-262-autohinter-stem-darkening-demo1.png
/usr/share/doc/libfreetype6/image/freetype-262-autohinter-stem-darkening-demo2-thumbnail.jpg
/usr/share/doc/libfreetype6/image/freetype-262-autohinter-stem-darkening-demo2.png
/usr/share/doc/libfreetype6/image/freetype-262-new-old-filter-thumbnail.jpg
/usr/share/doc/libfreetype6/image/freetype-262-new-old-filter.png
/usr/share/doc/libfreetype6/image/freetype.jpg
/usr/share/doc/libfreetype6/image/top.gif
/usr/share/doc/libfreetype6/index.html
/usr/share/doc/libfreetype6/js
/usr/share/doc/libfreetype6/js/freetype2.js
/usr/share/doc/libfreetype6/js/jquery-1.11.0.min.js
/usr/share/doc/libfreetype6/js/jquery.ba-resize.min.js
/usr/share/doc/libfreetype6/raster.txt.gz
/usr/share/doc/libfreetype6/reference
/usr/share/doc/libfreetype6/reference/ft2-auto_hinter.html
/usr/share/doc/libfreetype6/reference/ft2-base_interface.html
/usr/share/doc/libfreetype6/reference/ft2-basic_types.html
/usr/share/doc/libfreetype6/reference/ft2-bdf_fonts.html
/usr/share/doc/libfreetype6/reference/ft2-bitmap_handling.html
/usr/share/doc/libfreetype6/reference/ft2-bzip2.html
/usr/share/doc/libfreetype6/reference/ft2-cache_subsystem.html
/usr/share/doc/libfreetype6/reference/ft2-cff_driver.html
/usr/share/doc/libfreetype6/reference/ft2-cid_fonts.html
/usr/share/doc/libfreetype6/reference/ft2-computations.html
/usr/share/doc/libfreetype6/reference/ft2-error_code_values.html
/usr/share/doc/libfreetype6/reference/ft2-error_enumerations.html
/usr/share/doc/libfreetype6/reference/ft2-font_formats.html
/usr/share/doc/libfreetype6/reference/ft2-gasp_table.html
/usr/share/doc/libfreetype6/reference/ft2-glyph_management.html
/usr/share/doc/libfreetype6/reference/ft2-glyph_stroker.html
/usr/share/doc/libfreetype6/reference/ft2-glyph_variants.html
/usr/share/doc/libfreetype6/reference/ft2-gx_validation.html
/usr/share/doc/libfreetype6/reference/ft2-gzip.html
/usr/share/doc/libfreetype6/reference/ft2-header_file_macros.html
/usr/share/doc/libfreetype6/reference/ft2-header_inclusion.html
/usr/share/doc/libfreetype6/reference/ft2-incremental.html
/usr/share/doc/libfreetype6/reference/ft2-index.html
/usr/share/doc/libfreetype6/reference/ft2-lcd_filtering.html
/usr/share/doc/libfreetype6/reference/ft2-list_processing.html
/usr/share/doc/libfreetype6/reference/ft2-lzw.html
/usr/share/doc/libfreetype6/reference/ft2-mac_specific.html
/usr/share/doc/libfreetype6/reference/ft2-module_management.html
/usr/share/doc/libfreetype6/reference/ft2-multiple_masters.html
/usr/share/doc/libfreetype6/reference/ft2-ot_validation.html
/usr/share/doc/libfreetype6/reference/ft2-outline_processing.html
/usr/share/doc/libfreetype6/reference/ft2-pfr_fonts.html
/usr/share/doc/libfreetype6/reference/ft2-quick_advance.html
/usr/share/doc/libfreetype6/reference/ft2-raster.html
/usr/share/doc/libfreetype6/reference/ft2-sfnt_names.html
/usr/share/doc/libfreetype6/reference/ft2-sizes_management.html
/usr/share/doc/libfreetype6/reference/ft2-system_interface.html
/usr/share/doc/libfreetype6/reference/ft2-toc.html
/usr/share/doc/libfreetype6/reference/ft2-truetype_engine.html
/usr/share/doc/libfreetype6/reference/ft2-truetype_tables.html
/usr/share/doc/libfreetype6/reference/ft2-tt_driver.html
/usr/share/doc/libfreetype6/reference/ft2-type1_tables.html
/usr/share/doc/libfreetype6/reference/ft2-user_allocation.html
/usr/share/doc/libfreetype6/reference/ft2-version.html
/usr/share/doc/libfreetype6/reference/ft2-winfnt_fonts.html
/usr/share/doc/libfreetype6/release.gz
/usr/share/doc/libfreetype6/tutorial
/usr/share/doc/libfreetype6/tutorial/example1.c
/usr/share/doc/libfreetype6/tutorial/example2.cpp.gz
/usr/share/doc/libfreetype6/tutorial/example3.cpp.gz
/usr/share/doc/libfreetype6/tutorial/example4.cpp.gz
/usr/share/doc/libfreetype6/tutorial/example4.pro
/usr/share/doc/libfreetype6/tutorial/index.html
/usr/share/doc/libfreetype6/tutorial/metrics.png
/usr/share/doc/libfreetype6/tutorial/metrics2.png
/usr/share/doc/libfreetype6/tutorial/step1.html
/usr/share/doc/libfreetype6/tutorial/step2.html
/usr/share/doc/libfreetype6/tutorial/step3.html
/usr/share/doc-base
/usr/share/doc-base/libfreetype6-dev
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/freetype-config.1.gz
/usr/lib/i386-linux-gnu/libfreetype.so
/usr/share/doc/libfreetype6-dev
HinTak commented 7 years ago

Oh, 32-bit debian derived systems are so broken... Run this before your mono command, and you should be fine.

export LD_LIBRARY_PATH=/usr/lib/i386-linux-gnu:${LD_LIBRARY_PATH}

Your system looks like a biarch (64-bit and 32-bit) system without the default 64-bit arch!

PayDay1 commented 7 years ago

Thanks for the help. Unfortunately that didn't fix it. The thing is that in doesn't run on any of my Linux machines. Tested with i386, amd64 and arm.

HinTak commented 7 years ago

You will have to show the content of your SharpFont.dll.config . Also a few details - it must match your dll's name - if you choose to bundle the whole of SharpFont's source code in your program, you must rename the file as 'yourprogram.exe.config' .

You could also try to do this before you run your program, if your program does wierd windows-ish things:

export MONO_IOMAP=all

Lastly, this is barbaric,

MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono yourprogram.exe

should tell you what mono tries to do to find freetype. It will spill out a lot of debug info. Read the mono man page for details.

If none of your previous work had run on linux before, I really think your problem is more a general lack of familiarity with mono and linux, and maybe stackoverflow or some linux support forum is more appropriate.

HinTak commented 7 years ago

It is highly unusual that it does not work on any of your systems. mono's implementaton of winforms depends on cairo which depends on freetype. so if you run any GUI program with mono successfully it must mean mono can find freetype.

Have you tried the winform 'hello world' first? http://www.mono-project.com/docs/gui/winforms/getting-started-guide/ http://www.mono-project.com/docs/getting-started/mono-basics/

PayDay1 commented 7 years ago

it must match your dll's name - if you choose to bundle the whole of SharpFont's source code in your program, you must rename the file as 'yourprogram.exe.config' .

Didn't know that, renamed the config.

MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono yourprogram.exe

This told me that there is an invalid ELF-Header in libfreetype6.so (libfreetype6.dll).

If none of your previous work had run on linux before, I really think your problem is more a general lack of familiarity with mono and linux, and maybe stackoverflow or some linux support forum is more appropriate.

I am successfully using BASS.NET and OpenTK for this project. Never had any problems.

It is highly unusual that it does not work on any of your systems. mono's implementaton of winforms depends on cairo which depends on freetype. so if you run any GUI program with mono successfully it must mean mono can find freetype.

I'm not using WinForms or any other GUI. Just OpenGL (OpenTK).

HinTak commented 7 years ago

"This told me that there is an invalid ELF-Header in libfreetype6.so (libfreetype6.dll)."

This seems to suggest it find a wrong libfreetype first. Did it continue looking elsewhere after that?

If it does not, you probably should look at your directory layout and remove anything that would confuse it.

I'll still suggest you give the winforms hello world example a try, to make sure that your mono is built and installed correctly. It is rare but some linux distros occasionally ships software which is subtly broken on arrival.

And the content of your exe.config? So you did bundle the whole of SharpFont inside your own app (instead of it staying as a separate dll)? That's a whole area for which you are on your own. I guess your app is not open-source either...

PayDay1 commented 7 years ago

Fixed it by copying the .so from /usr/lib/i386-linux-gnu/ to the executable and renaming it to libfreetype6.dll.so.

But Face.Glyph.RenderGlyph() doesn't seem to render the glyph into the bitmap like on Windows. I will try some things to get it working.

Thank you guys for the help.

EDIT:

And the content of your exe.config?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <dllmap dll="freetype6" os="linux" target="libfreetype.so.6" />
    <dllmap dll="freetype6" os="osx" target="/Library/Frameworks/Mono.framework/Libraries/libfreetype.6.dylib" />
    <dllmap dll="freetype6" os="freebsd" target="libfreetype.so.6" />
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

So you did bundle the whole of SharpFont inside your own app (instead of it staying as a separate dll)?

Oh, I didn't do that. I misunderstood you there then. I am just referencing SharpFont.dll.

Hmm, there were some mono drawing problem in the example a while ago to do with render to bitmap. You might want to look at that.

Thank you.

HinTak commented 7 years ago

Hmm, there were some mono drawing problem in the example a while ago to do with render to bitmap. You might want to look at that.

HinTak commented 7 years ago

See https://github.com/Robmaister/SharpFont/issues/55 for some rendering issue with mono.