Mono
The state of Mono 2.6 on FreeBSD
Long time no post... Well, I an writing a serie of articles about NFC and it takes me a lot of time, not mentioning I still do many other things in parallel. If you are interested in this area, stay tuned ;-)
So apart NFC, what's new with Mono on FreeBSD? First, you wight have seen that mono 2.6 has been released for a while and is still not available in FreeBSD ports. The main reasons are:
- Romain Tartière's blog
- Login to post comments
- Read more
Unbreaking Mono on FreeBSD 6.4
A few days ago ports/140916: lang/mono (2.4.2.3) installation fails was opened. The reported problem had already been reported a few time but with insufficient feedback so far and I was not able to diagnose the problem, not mentioning providing a fix. But this time, the reporter could spot that the problem was happening for him only with FreeBSD-6.4. I did the test on a fresh FreeBSD-6.4 install and could trigger the error:
arthur# portsnap fetch [...] arthur# portsnap extract [...] arthur# cd /usr/ports/lang/mono arthur# make -V PKGNAME mono-2.4.2.3_1 arthur# make [...] if test -w ../mcs; then :; else chmod -R +w ../mcs; fi cd ../mcs && gmake NO_DIR_CHECK=1 PROFILES='net_1_1 net_2_0 net_3_5 net_2_1' CC='cc' all-profiles gmake[3]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake profile-do--net_1_1--all profile-do--net_2_0--all profile-do--net_3_5--all profile-do--net_2_1--all gmake[4]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake PROFILE=basic all gmake[5]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[6]: *** [build/deps/basic-profile-check.exe] Error 1 gmake[6]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' *** The compiler 'false' doesn't appear to be usable. *** Trying the 'monolite' directory. gmake[7]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[8]: *** [build/deps/basic-profile-check.exe] Error 138 gmake[8]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' *** The contents of your 'monolite' directory may be out-of-date *** You may want to try 'make get-monolite-latest' gmake[8]: *** [do-profile-check-monolite] Error 1 gmake[8]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[7]: *** [do-profile-check] Error 2 gmake[7]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[6]: *** [do-profile-check-monolite] Error 2 gmake[6]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[5]: *** [do-profile-check] Error 2 gmake[5]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[4]: *** [profile-do--basic--all] Error 2 gmake[4]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[3]: *** [profiles-do--all] Error 2 gmake[3]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs' gmake[2]: *** [all-local] Error 2 gmake[2]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/runtime' gmake[1]: *** [all-recursive] Error 1 gmake[1]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3' gmake: *** [all] Error 2 *** Error code 1 Stop in /usr/ports/lang/mono. *** Error code 1 Stop in /usr/ports/lang/mono.
- Romain Tartière's blog
- Login to post comments
- Read more
Banshee: Like Frankenstein! It rips!
A while ago (I mean when it landed in the FreeBSD ports tree), Banshee reacted when a music CD-ROM was in a CD-Drive: it crashed. Well, not so cool in fact, you had to double-check it was empty before launching the player...
More recently, I was happy to find out that it was not the case anymore: Banshee was simply unable to detect the CD-ROM anymore. Still not so cool: you were still unable to listen to an audio CD, not mentioning ripping it.
For some reason I cannot really figure out (I have spent quite some time in fixing Banshee for FreeBSD and giving it some love), I took a look at this problem.
Obviously, the first rusty part of the chain of tools involved with audio CD was MusicBrainz and more precisely musicbrainz-sharp (a client library for .NET / Mono). FreeBSD having it's own ioctls for managing CD drives, and musicbrainz-sharp having 3 concrete classes for managing such devices called DiscLinux, DiscWin32 and DiscWin32NT, a piece was definitively missing. With a great deal of inspiration, it was called DiscFreeBSD and provides bindings for almost everything referenced in sys/cdio.h. When instanced, this class reads the CD in the drive and computes an ID used to fetch information about the audio CD from the Internet.
Unfortunately, I could not test the library on a system one which it is supposed to work (read GNU/Linux) so I asked a friend of mine, Baptiste (Yes! It works!) [edit: 2009-11-10:12:04 he just told me he has a a-bit-better website where he is playing now...], to tell me how it goes and to help me make the library behave the same on GNU/Linux and FreeBSD. We quickly had some good results:
![]()
Yay! Tracks from Sopor Aeternus' album Les fleurs du Mal are being listed!
Unfortunately, it was not possible to listen to the CD nor rip it... Not so cool once more.
And here takes place the magic of GStreamer!
cd /usr/ports/audio/gstreamer-plugins-cdparanoia && make install
Now, Banshee can play and RIP audio CDs with a single mouse clic!
![]()
Playing Cinema Strange's The Astonished Eyes Of Evening...
![]()
And ripping it (progress in the bottom left corner)...
All this will be soon in your ports tree!
For those who can't wait, patches for musicbrainz-shap are in the project's trac: Add support for FreeBSD in MusicBrainzSharp.
- Romain Tartière's blog
- Login to post comments
Packing structures with Mono or how to fix alignment problems for P/Invoke
This is basically a[nother] note for myself.
I have just spent a while wondering why the size of some data structures in C# was wrong while writing bindings to the CD-ROM control features of the FreeBSD libc.
Considering the following code snippet:
struct msf {
public byte unused;
public byte minute;
public byte second;
public byte frame;
};
[StructLayout (LayoutKind.Explicit)]
struct msf_lba {
[FieldOffset (0)] public msf msf;
[FieldOffset (0)] public int lba;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
[FieldOffset (0)] public byte [] addr;
};
struct cd_toc_entry {
byte unused1;
public byte control_addr_type;
public byte track;
byte unused2;
public msf_lba addr;
};
struct cd_sub_channel_media_catalog {
public byte data_format;
public int mc_valid;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 15)]
public byte [] mc_number;
};
We can compute the size of each structure (MSDN page about types size):
- msf
- A msf structure contains 4 members each of 1 byte long so the whole structure is 4 bytes;
- msf_lba
- This is not more than the union of a msf structure (4 bytes), an int (4 bytes) and an array of 4 byte (4 bytes), so it's 4 bytes long too;
- cd_toc_entry
- A cd_toc_entry structure is composed of an unused byte (1 byte), 2 data byte (1 byte + 1 byte), another unused byte (1 byte) and a msf_lba structure (4 bytes) so it is 1 + 1 + 1 + 1 + 4 = 8 bytes long;
- cd_sub_channel_media_catalog
- A cd_sub_channel_media_catalog structure starts with 1 byte (1 byte), followed by an int (4 bytes), and an array of 15 byte (15 bytes). The whole structure is therefore 1 + 4 + 15 = 20 bytes long.
These results can be checked using Marshal.SizeOf:
Marshal.SizeOf (typeof (msf)) = 4 Marshal.SizeOf (typeof (msf_lba)) = 4 Marshal.SizeOf (typeof (cd_toc_entry)) = 8 Marshal.SizeOf (typeof (cd_sub_channel_media_catalog)) = 24
So the cd_sub_channel_media_catalog structure it 4 bytes long more that expected. This really sounds like alignment problems in C. A quick search on the Interop with Native Libraries page on Novell's wiki does not give any info about such a problem. Switching the two first fields order fix the size (but of course breaks the workability) so it is definitively an alignment problem that takes place here.
After some search, I could find the StructLayoutAttribute.Pack Field (actually I could not find this piece of information using the MSDN search engine, I had to search on the web similar problems and find this one with a reference to « Pack » to find this page in the Microsoft .NET documentation).
Finally, the solution is to write this:
[StructLayout (LayoutKind.Sequential, Pack = 1)]
struct cd_sub_channel_media_catalog {
public byte data_format;
public int mc_valid;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 15)]
public byte [] mc_number;
};
The MusicBrainzSharp port to FreeBSD can go on!
- Romain Tartière's blog
- Login to post comments
LINQ, PostgreSQL and Mono
LINQ to DB is planned for mono-2.6, however I wanted to access data from a PostgreSQL database, without spending much time playing with Npgsql, and using the stable version of mono: 2.4.2.3.
Here comes DbLinq, which aims to provide linq to SQL
for many DataBase systems. While this project is still considered experimental to some extends by its developers, I wanted to give it a try. Since it way quite a PITA, here are the details for building using DbLinq with mono.
Get DbLinq from the Subversion repository
The latest stable release is quite old, and the project page warns we recommend using the latest SVN HEAD, so checkout the code from the google code repository:
svn checkout http://dblinq2007.googlecode.com/svn/trunk/ dblinq2007
Open the solution in MonoDevelop (or your favourite editor) and edit each project options so that assemblies are signed with the DbLinq.snk key.
You can then compile all needed assemblies and the DbMetal utility.
Get the System.Data.Linq.dll assembly
This assembly is not yet in the stable mono releases. You can compile it from the mono trunk:
svn checkout http://anonsvn.mono-project.com/source/trunk/mcs cd mcs && ./configure && gmake
The assembly for the 2.0 profile is then available as class/lib/net_2_0/System.Data.Linq.dll.
Start you project
Create a new project as usual and add any required references. For example, my project use PostgreSQL so I added the following assemblies:
- DbLinq.dll
- DbLinq.PostgreSQL.dll
- Npgsql.dll
- System.Data.dll
- System.Data.Linq.dll
Generate classes to access your DataBase
The DbMetal utility generate classes from a DataBase schema. Before using it, ensure that DbMetal.exe.config exists in the DbMetal.exe directory and if not, copy it from DbMetal/App.config. You can then use the utility to generate your code:
mono DbMetal.exe /conn:"server=localhost;user id=user;\ password=password; database=db" /provider=PostgreSQL \ /code:db.cs /pluralize
Add the generated db.cs to your project and start coding:
using System;
using Npgsql;
class MainClass
{
public static void Main(string[] args)
{
string connStr = "server=localhost;user id=user; password=password; database=db";
NpgsqlConnection conn = new NpgsqlConnection(connStr);
using (Db db = new Db(conn))
{
foreach (Employees e in db.Employees)
Console.WriteLine(e.Name);
}
}
}
- Romain Tartière's blog
- Login to post comments
Mono on FreeBSD
Mono 2.4.2 has just been committed to the FreeBSD ports tree, after being available for a few days in the BSD# repository.
The lang/mono port still has many patches to make mono build and run on FreeBSD, but still should change with mono-2.6: the mono trunk can now be build vanilla on FreeBSD.
So, what's coming next? Well, I have been working on splitting the deskutils/gnome-do-plugins in order to cut down a bit the *HUGE* amount of dependencies for building and running all plugins. Working on this proved that devel/monodevelop is somewhat ready to be committed in the FreeBSD ports tree, so expect at least these two packages to be available in the ports collection soon!
To finish, I want to thanks Florent Thoumie (flz@) for taking care of my Mono PR.
- Romain Tartière's blog
- Login to post comments
Meta-note-taking with Tomboy
Just wrote a Tomboy add-in allowing the user to keep notes in Tomboy notes. The idea? If just like me you rely a lot on short tags such as TODO or FIXME, you find it convenient to have the editor highlight them. It is exactly what the add-in has been designed for.
Mandatory screenshot:

Editing notes with FIXMEs and TODOs.
For more info and downloads, have a look to the Tomboy-Todo project's page.
- Romain Tartière's blog
- Login to post comments
Writing Free Software
A quick post to mention the beginning of a serie of mini-howtos on
C.J. Adams-Collier's weblog entitled Writing Free Software
.
- Romain Tartière's blog
- Login to post comments
- Read more
BSD#: Mono on FreeBSD
A few weeks ago, I joined the BSD# project which aim to maintain Mono (an open source implementation of the Microsoft .NET framework) on FreeBSD. It was the occasion for giving svk a try.
- Romain Tartière's blog
- Login to post comments
- Read more