ScintillaNET on Linux

Topics: Developer Forum
Oct 18, 2012 at 8:11 AM

Hi,

I know that this sounds crazy but I heavily use .NET so I am currently playing around with porting a Windows .NET project to Linux using Mono (Linux implementation of .NET).  So far everything has ported beautifully except for the Scintilla control.  I have successfully recompiled ScintillaNET but I need to get the actual Scintilla library/control to be loaded.  Does anyone have any experience of doing this?

I don't seem to be able to download a ready built Scintilla library for Linux, and I am having trouble compiling it.  But even then, it seems all implementations on Linux expect it to be compiled straight into the application and not be loadable library.  But I need it to be a loadable library.

Any clues, hints, or tips?

Thanks,
Adam Bent

Developer
Oct 18, 2012 at 7:42 PM
Edited Oct 18, 2012 at 7:42 PM

I should be easily possible to hook into the dynamic linker and have it load the .so file, I'm not sure what call convention Scintilla compiles with on Linux though... Once you find the right call to load the library, it can be loaded in the same way that the windows version is. (provided the library load call is the only PInvoke method we use?)

Oct 19, 2012 at 7:09 AM

Thanks for your reply.

I would imagine it would be fairly easy to get the library loaded.  The way in which ScintillaNET communicates with the library may need rewriting if it is using PInvoke, but I haven't got there far yet.

At the moment I need a built Scintilla library for Linux (.so) as I am having trouble building it.  Then, does it need to reside in the same folder as ScintillaNET and my app?

Developer
Oct 20, 2012 at 5:17 PM

PInvoke works just fine on Mono, you should just have to tell the call to the dynamic linker to load the .so file from wherever you put it, but yes, the directory your app and ScintillaNET are in is probably the best place to have it.

Oct 22, 2012 at 2:58 PM

Thanks for your help.

I have now managed to get the shared library built from the Scintilla source, as I was having some issues building it.  I have also had to change some of the "native methods" in ScintillaNET as they were specifically trying to load Windows DLL's and invoking functions.  One of them was "LoadLibrary" which I have replaced with with "dlopen".  All is fine so far.

My next problem is that ScintillaNET fails to load the Scintilla shared library.  Every some playing around I have managed to get an error from dlopen stating "undefined symbol ZdlPv".  So my reckoning is that I need to load another library first.  Anyone any idea what this undefined symbol might be?

Developer
Oct 22, 2012 at 7:58 PM

I'm going to take a wild guess and say that you compiled the shared library with LLVM? (Either that or GCC decided to emit the operator without the leading underscore) In either of these cases, the symbol would be defined in libstdc++.a, (most likely at /usr/lib/libstdc++.a). There is also the possibility that you compiled the scintilla library with LLVM, but are trying to run it on a computer which only has GCC installed, and thus it is trying to use GCC's standard C++ library, which isn't compatible with the LLVM implementation. (they are compatible from a source-code perspective, but not from a binary perspective)

Oct 23, 2012 at 7:48 AM

Well, I updated the makefile in the gtk folder of the Scintilla source so that it generated a shared library as well as a static one.  Here are the changes:

SHAREDLIB=../bin/SciLexer.so

.....

$(SHAREDLIB): Accessor.o CharacterSet.o LexerBase.o LexerModule.o LexerSimple.o StyleContext.o WordList.o \
    CharClassify.o Decoration.o Document.o PerLine.o Catalogue.o CallTip.o \
    ScintillaBase.o ContractionState.o Editor.o ExternalLexer.o PropSetSimple.o PlatGTK.o \
    KeyMap.o LineMarker.o PositionCache.o ScintillaGTK.o CellBuffer.o ViewStyle.o \
    RESearch.o RunStyles.o Selection.o Style.o Indicator.o AutoComplete.o UniConversion.o XPM.o \
    $(MARSHALLER) $(LEXOBJS)
    $(CCOMP) -o $@ -shared $^

Does this look correct to you?

$(CCOMP) is gcc, so it uses gcc to create the shared library.  I have no idea what LLVM is.

I thought that as I built the gtk version of Scintilla I would need to also need to load the gtk library(ies).  But as you have indicated this external symbol resides in libstdc++.a should I try to link this into the shared library?

Developer
Oct 24, 2012 at 1:02 AM
Edited Oct 26, 2012 at 2:22 AM

The other libraries that the native library is dependent on are linked to it dynamically, and it tries to do the same with libstdc++, however, it's the wrong libstdc++, thus causing a linker error... Lets see if I can manage to build Scintilla and get ScintillaNET working against it. (I'll be trying this on Debian 6 64-bit so we'll see)

Update:
Library built, working on getting ScintillaNET working now.

Another Update:
Maybe I should have tried on a platform which actually has .net 4.0 available :P (Trying in Ubuntu 12.04 now :P)

Another:
Got it built and no more undefined symbols, just working on getting ScintillaNET to behave now.

And Again:
ScintillaNET is behaving now, just have to figure out how do disable the drag & drop on the widget (if I could figure out how to get that widget it would be much easier)

Oct 25, 2012 at 7:44 AM
Edited Oct 25, 2012 at 7:46 AM

That is great news and thank you.  Could you possibly send me over your built library or upload it somewhere so I can have a play with it?

Nov 5, 2012 at 11:46 AM

Hi,

I have only just checked back as I have not received any email updates.  But I have seen you have updated your last comment.

Did you manage to get ScintillaNET to load the so file and create the edit window or is it failing to do that whilst you have the drag & drop issue?

Many thanks.

Developer
Nov 5, 2012 at 8:09 PM

I was able to get it to load the shared library, however Scintilla doesn't appear to be receiving the messages I send, meaning that I never am able to get the direct pointer to the control. (also means I can't really do anything at all with the library) I'm not entirely sure why this occurs though.

Nov 6, 2012 at 11:51 AM

Could you possibly outline the steps you made to get to the stage you are at now, i.e. how did you manage to build Scintilla as a shared library (.so) and what changes you made to ScintillaNET to get it to load, as well as how to resolve any of linker issues?

Many thanks.