Friday, March 23, 2012

Mono on Synology NAS DS 211

Updated 2014-01-21: 
There is a repository with pre-built synology packages (including Mono), which might save you some hassle.

There used to be a Mono package for Synology, using the ipkg system. But it was old (Mono 2.4), and it seems to have disappeared. I have a lot of Mono/.Netstuff that I want to run on my NAS box, especially Duplicati for backups.

If you download the source and build the latest Mono, you get strange errors. Hopefully this guide will help you building Mono on your Synology DS. I have tested with DSM 3.1 and DSM 4.0 and both build fine and appear to run as expected.

First of, you need the Synology ipkg system set up. Once this is installed, you can pull some tools to build it. You will need at least make, automake, autoconf, bison, glib, libc-dev, libstdc++, m4, gcc, gawk, textutils, gettext, zlib. You need gawk and textutils to run the configure script. I use wget to download the Mono sources, and nano to edit the makefiles, so install those too.

Type this to get all the packages:
sudo ipkg install wget nano make automake autoconf bison \
glib libc-dev libstdc++ m4 gcc gawk textutils gettext zlib

Then download Mono sources:

wget "http://download.mono-project.com/sources/mono/mono-2.11.0.tar.bz2"

And extract:

tar -xf mono-2.11.0.tar.bz2

Then configure:

cd mono-2.11
./configure --prefix=/opt/mono-2.11
The --prefix will setup the build to put stuff into /opt/mono-2.11 rather than /usr. If you use just /opt, you will have a hard time uninstalling Mono later should you want to.

Now you should be ready to build it, but there is some weirdness with default includes, so edit the following files:

mono/metadata/Makefile
mono/mini/Makefile
mono/profiler/Makefile

In all files, look for the line:

LDFLAGS =

Add the -lrt flags so the line becomes:

LDFLAGS = -lrt 

If you already have flags on that line, just add the -lrt option to the end, and keep all the other stuff. This fixes problems with "undefined reference to clock_gettime" and also includes the pthreads library.

Now the pthreads library provided by ipkg is a bit broken, so you need to use the normal pthreads library for the build. Simply do this:
mkdir /opt/arm-none-linux-gnueabi/lib_disabled
mv /opt/arm-none-linux-gnueabi/lib/libpthread* /opt/arm-none-linux-gnueabi/lib_disabled
cp /lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/
ln -s /opt/arm-none-linux-gnueabi/lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/libpthread.so
ln -s /opt/arm-none-linux-gnueabi/lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/libpthread-2.5.so

And that is it, now run:

make

This will take a few hours probably, so sit back and wait. I usually run this in a screen so network issues do not stop the build.

After the build has completed, you can install it into /opt/mono-2.11:

make install

To make life a little easier, add some symlinks:

ln -s /opt/mono-2.11/bin/mono /opt/bin/mono
ln -s /opt/mono-2.11/bin/mcs /opt/bin/mcs
ln -s /opt/mono-2.11/bin/gmcs /opt/bin/gmcs

And finally test it:

mono --version


Mono JIT compiler version 2.11 (tarball Fri Mar 23 15:12:18 CET 2012)
Copyright (C) 2002-2011 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,soft-float
Disabled:      none
Misc:          softdebug
LLVM:          supported, not enabled.
GC:            Included Boehm (with typed GC and Parallel Mark)

I have uploaded a complete build, so you can just use it without doing the long and boring build process.


27 comments:

key said...

Hi Kenneth,

this is a great How-To install Mono on the DS.

I'm trying to do the same on my DS209+ II (PPC) and 1511+ (Intel Atom), followed all the instructions (but without the stuff regarding the pthreads - this seems to be an issue only on ARM) and so far I have some issues on the Atom - make is still running on the PPC.

make install gives me errors.
If you want I can send you them.

And so, Mono isn't installed...

Can you give me a hint?

Thanks in advance!
Yasmin

key said...

Hi Kenneth,

first of all, thanks for the How-To here, it's great!

I was trying to do the same on my DS209+ II (PPC) and on the 1511+ (Intel Atom) but I have some issues (make is still running at the moment on the PPC).

I've installed all the ipkg packages, made the modifications but "make install" gave me errors and so Mono wasn't installed on the 1511+

If you want I can send you the output.

Can you give me please a hint or help somehow?

Thanks in advance,
Yasmin

Kenneth said...

Sure, just post your error messages, I'll take a guess at what goes wrong.

key said...

Hi Kenneth,

thanks for the replay.

Because the output is really long, I will post only the last lines.

Hope you can help!

Thanks in advance,
Yasmin

---cut here---
...
Making install in mini
make[2]: Entering directory `/volume1/public/mono-2.11/mono/mini'
make install-am
make[3]: Entering directory `/volume1/public/mono-2.11/mono/mini'
CC libmono_2_0_la-mini-exceptions.lo
mini-exceptions.c: In function 'mono_walk_stack_with_ctx':
mini-exceptions.c:693: warning: cast from pointer to integer of different size
mini-exceptions.c: In function 'ves_icall_get_frame_info':
mini-exceptions.c:838: warning: cast from pointer to integer of different size
mini-exceptions.c: In function 'mono_handle_exception_internal_first_pass':
mini-exceptions.c:1362: error: 'MonoContext' has no member named 'rax'
mini-exceptions.c: In function 'mono_handle_exception_internal':
mini-exceptions.c:1641: error: 'MonoContext' has no member named 'rax'
mini-exceptions.c: In function 'mono_print_thread_dump_internal':
mini-exceptions.c:2332: warning: cast from pointer to integer of different size
mini-exceptions.c: In function 'mono_thread_state_init_from_current':
mini-exceptions.c:2587: warning: cast from pointer to integer of different size
make[3]: *** [libmono_2_0_la-mini-exceptions.lo] Error 1
make[3]: Leaving directory `/volume1/public/mono-2.11/mono/mini'
make[2]: *** [install] Error 2
make[2]: Leaving directory `/volume1/public/mono-2.11/mono/mini'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/volume1/public/mono-2.11/mono'
make: *** [install-recursive] Error 1
---cut here---

Kenneth said...

I think the error message is related to some mixup with LLVM being enabled in some places, and not in others.

Can you try running ./configure with "--enable-llvm=yes", then run "make"?

And if that fails, repeat, but with "--enable-llvm=no" ?

key said...

Hi Kenneth,

thanks a lot for your message.
I will try it today.

But, should I also use the option "--prefix=/opt/mono-2.11" as stated in your post or just "--enable-llvm=..."?

Yasmin

Kenneth said...

Yes, you should also include the --prefix, otherwise it will try to install in /usr and mess up your DSM installation.

key said...

Kenneth, it didn't worked on both machines.

If you want and you have the time I could send you the output - but it's long, can't post it here.

Yasmin

Andrew said...

That's a really good write up.. Enjoyed reading it. If your interested there are some good write up's on the latest Synology enclosures over at www.andrewsreviews.co.uk

Kenneth said...

You can post the log at pastebin.com, but otherwise, drop me a mail, kenneth@hexad.dk

Agner said...

Hi

Very nice tutorial, but it isn't working for me. I can't run configure without error. I get

checking whether we are cross compiling... configure: error: in `/volume1/developement/mono-2.11':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

And in the config.log i get

configure:4766: gcc -o conftest -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP -DUSE_MUNMAP conftest.c >&5
In file included from /opt/include/_G_config.h:44,
from /opt/include/libio.h:32,
from /opt/include/stdio.h:72,
from conftest.c:11:
/opt/include/gconv.h:72: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/gconv.h:88: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/gconv.h:97: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/gconv.h:174: error: expected specifier-qualifier-list before 'size_t'

If you have som idea of what is wrong, please share :)

Thanks in advance
Agner

Kenneth said...

Hi Agner.

Are you running this on the box?
The "cross compile" error seems to indicate that you are somehow building for another machine than the one you are running the build on?

The "size_t" is usually found in "limits.h" or "stdlib.h" if that helps you.

Agner said...

Hi

Thanks for replying. I building on the box. Or trying to.

I found that you already shared a build version which i gonna use.

Another question: have you gotten MONO to work with Apache (*.aspx)?

Kenneth said...

No, I have not tried any aspx stuff, I just want to use it for running commandline programs. You probably need some Apache module as well for .aspx to work.

Morten said...

I have looked around, and it seems that to run it on apache, you have to install mod_mono for apache webserver. However I have only managed to find it for sparc and x86 processors, so I don't know if there is a package build for ARM processors.

Anonymous said...

Hey!
Thank you for the description. I tried to install it on my DS411+ (Intel Atom CPU) but got the same error like key:
mini-exceptions.c:1641: error: 'MonoContext' has no member named 'rax'
Did you two find a solution for this?

THX Seb!

Kenneth said...

Hi Seb.

No, I only have the 211+ so I cannot reproduce/debug that problem.

You have to write the Mono project and ask them.

Javier Morata said...

Hi,
I have an error making install on my ds211+.

Can you help me or give me binaries ?

thx

-- cut here --


Making install in mini
make[2]: Entering directory `/volume1/public/mono/mono-2.11/mono/mini'
make install-am
make[3]: Entering directory `/volume1/public/mono/mono-2.11/mono/mini'
LD libmonosgen-2.0.la
../../mono/metadata/.libs/libmonoruntimesgen.a(libmonoruntimesgen_la-sgen-gc.o): In function `stop_world':
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:3749: undefined reference to `mono_sgen_thread_handshake'
../../mono/metadata/.libs/libmonoruntimesgen.a(libmonoruntimesgen_la-sgen-gc.o): In function `restart_threads_until_none_in_managed_allocator':
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:3657: undefined reference to `mono_sgen_resume_thread'
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:3678: undefined reference to `mono_sgen_wait_for_suspend_ack'
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:3697: undefined reference to `mono_sgen_suspend_thread'
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:3709: undefined reference to `mono_sgen_wait_for_suspend_ack'
../../mono/metadata/.libs/libmonoruntimesgen.a(libmonoruntimesgen_la-sgen-gc.o): In function `restart_world':
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:3791: undefined reference to `mono_sgen_thread_handshake'
../../mono/metadata/.libs/libmonoruntimesgen.a(libmonoruntimesgen_la-sgen-gc.o): In function `mono_gc_base_init':
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:4742: undefined reference to `mono_sgen_os_init'
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:4742: undefined reference to `mono_sgen_os_init'
/volume1/public/mono/mono-2.11/mono/metadata/sgen-gc.c:4742: undefined reference to `mono_sgen_os_init'
/opt/lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/bin/ld: .libs/libmonosgen-2.0.so.0.0.0: hidden symbol `mono_sgen_resume_thread' isn't defined
/opt/lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[3]: *** [libmonosgen-2.0.la] Error 1
make[3]: Leaving directory `/volume1/public/mono/mono-2.11/mono/mini'
make[2]: *** [install] Error 2
make[2]: Leaving directory `/volume1/public/mono/mono-2.11/mono/mini'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/volume1/public/mono/mono-2.11/mono'
make: *** [install-recursive] Error 1

Kenneth said...

Mono 2.11 build: http://www.2shared.com/file/cV74LDez/mono-synology-ds211-211tar.html

Agner said...

Hi

I'm still trying to compile mono on my own DS211. Hope you have som advice. I still have the problem that i can't run configure so i tried to build a small "helloWorld" program, with the same error.

hello.c

#include

int main(void)
{
printf("Hello World\n");
}


I get the errors (gcc hello.c)

In file included from /opt/include/_G_config.h:44,
from /opt/include/libio.h:32,
from /opt/include/stdio.h:72,
from hello.c:1:
/opt/include/gconv.h:72: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/gconv.h:88: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/gconv.h:97: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/gconv.h:174: error: expected specifier-qualifier-list before 'size_t'
In file included from /opt/include/stdio.h:72,
from hello.c:1:
/opt/include/libio.h:329: error: expected specifier-qualifier-list before 'size_t'
/opt/include/libio.h:361: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/libio.h:370: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/libio.h:486: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_IO_sgetn'
In file included from hello.c:1:
/opt/include/stdio.h:306: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/stdio.h:313: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/stdio.h:355: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/stdio.h:357: error: format string argument not a string type
/opt/include/stdio.h:359: error: expected declaration specifiers or '...' before 'size_t'
/opt/include/stdio.h:361: error: format string argument not a string type
/opt/include/stdio.h:608: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread'
/opt/include/stdio.h:614: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite'
/opt/include/stdio.h:636: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread_unlocked'
/opt/include/stdio.h:638: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite_unlocked'


I've reinstalled Optware and installed GCC with ipkg. Nothing works.

ipkg list_installed

binutils - 2.19.1-1
e2fslibs - 1.41.14-1
gcc - 4.2.3-1
glib - 2.20.4-1
ice - 6.3.5cvs20050130-2
libc-dev - 2.5-5
libnsl - 2.5-4
libpar2 - 0.2-5
libsigc++ - 2.2.3-1
libstdc++ - 6.0.9-6 -
mc - 4.7.5.5-1
ncurses - 5.7-1
openssl - 0.9.8v-2
slang - 2.2.3-2
sm - 6.0.4+cvs20050207-2
termcap - 1.3.1-2
wget - 1.12-2
x11 - 6.2.1+cvs20050209-3
xau - 0.1.1+cvs20050130-2
xaw - 7.0.1+cvs20050130-2
xdmcp - 0.1.3+cvs20050130-2
xext - 6.4.3+cvs20050130-2
xmu - 6.2.3+cvs20050130-2
xpm - 3.5.2+cvs20050130-2
xt - 0.1.5+cvs20050130-2
xterm - 225-1


Do you have any idea what i'm doing wrong or what i'm missing ?

Kenneth said...

I have not seen that error before, but googling it gives this: http://old.nabble.com/Hello-world-not-compiling-td21761324.html

It says you are "missing stddef.h". Others report the same and say that this is in some kernel headers.

Hope that helps :)

Anonymous said...

./configure --prefix=/opt/mono-2.11 --enable-llvm=no
worked fine for me. Thanks!

Donj said...

Hey,

First of all thanks for this topic!

I tried to run the make command from the command line. During the make command I get the follwoing error:

Making all in io-layer
make[3]: Entering directory `/volume1/public/mono-2.11/mono/io-layer'
CC atomic.lo
CC collection.lo
CC context.lo
CC critical-sections.lo
CC error.lo
CC events.lo
CC handles.lo
CC io.lo
In file included from /opt/powerpc/powerpc-603e-linux/sys-include/linux/fs.h:9,
from io.c:36:
/opt/powerpc/powerpc-603e-linux/sys-include/linux/config.h:4:28: linux/autoconf.h: No such file or directory
In file included from /opt/powerpc/powerpc-603e-linux/sys-include/linux/vfs.h:4,
from /opt/powerpc/powerpc-603e-linux/sys-include/linux/fs.h:14,
from io.c:36:
/opt/powerpc/powerpc-603e-linux/sys-include/asm/statfs.h:12: error: redefinition of `struct statfs'
io.c: In function `file_getfilesize':
io.c:776: error: `u64' undeclared (first use in this function)
io.c:776: error: (Each undeclared identifier is reported only once
io.c:776: error: for each function it appears in.)
make[3]: *** [io.lo] Error 1
make[3]: Leaving directory `/volume1/public/mono-2.11/mono/io-layer'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/volume1/public/mono-2.11/mono'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/volume1/public/mono-2.11'
make: *** [all] Error 2

Could you please help me out or give some detailed information?

P.S. The system i'm working on is an old DS109j with a Freescale MPC8421 PPC.

Thanks in advance,
Jered

Kenneth said...

Sorry, cannot help you there, I have not tried a Synology PPC.

But can't you just use the Mono version from the package manager?

Johan said...

Hello Kenneth,

I was trying to follow you r instructions but i got stuck on the line

./configure --prefix=/opt/mono-2.11

Where i get the following error:

checking build system type... powerpc-unknown-linux-gnu
checking host system type... powerpc-unknown-linux-gnu
checking target system type... powerpc-unknown-linux-gnu
checking for a BSD-compatible install... ./install-sh -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... no
checking how to create a ustar tar archive... plaintar
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether ln -s works... yes
checking host platform characteristics... ok
checking for gcc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/root/mono-2.11':
configure: error: C compiler cannot create executables
See `config.log' for more details


Kenneth said...

You have something broken with your compiler, I do not have the PowerPC version so I have not had that error.

Anonymous said...

If it still helps someone:

Several prebuilt Mono packages are available here:

http://ukdl.synology.com/ftp/packages

On my DS412+ (Intel Atom), the package Mono-cedarview-2.11.1-0004.spk works.