[Mono-list] need help getting started creating my own libraries

Charlie Poole charlie at nunit.com
Thu Dec 8 16:15:58 EST 2011


Hi Fulko,

On Thu, Dec 8, 2011 at 12:48 PM, Fulko Hew <fulko.hew at gmail.com> wrote:
> I know I'm probably not using the right terms for C# developers,
> but I'm having troubles getting past the basics of C# naming, hierarchies
> and directory and compiler usage.  I'm new to C#/mono, but decades
> in other stuff.
>
> What I am trying to do is port a library I wrote in both Perl and Java
> into C# so C# developers have a 'native' port.
>
> Lets say my library ('mylib') consists of only two things right now:
> myTypeA and myTypeB (that belong to my company 'xyz'.
> And to use/test these library components I have a main app called 'tester'.
>
> So what I was expecting to do was to create the following directory
> structure:
>
> ./com.xyz.mylib/
>                 myTypeA.cs
>                 myTypeb.cs
> ./com.xyz.tester/tester.cs
>
> a) is this a valid structure?

Sure, although the backwards naming of components something that is
part of the Java culture and a little foreign to most C# folks. That's OK.

> b) what compiler directives do I use to build my libraries?

What is missing in your example is a reference to the library when
building the tester component.

> d) what do I need inside 'tester.cs' to reference/load/import my library
> components?
> d) what compiler directives do I use to build my executable (linking in the
> libraries)?
>
> (I've been googling, but I find either the trivial 'hello world' example, or
> abstract discussions.  But I haven't found a simple tutorial for what I
> need.)
>
> I would expect to compile myTypeA and myTypeB into 'something'
> ie. something like:  gmcs -t:library myTypeA.cs

gmcs -t:library -out:mylib.dll myTypeA.cs myTypeB.cs
gmcs -t:exe -out:tester -r:mylib.dll tester.cs

> And then inside tester.cs have something like:
>
> using com.xyz.mylib.myTypeA;
> class tester {
>     static void Main() {
>         myTypeA x = new myTypeA();
>         ... do stuff ...
>     }
> }

First line should be
  using com.xyz.mylib;
i.e., just the namespace name.

>
> The primary error I get now is:
>
> testSnmpInteger.cs(2,7): error CS0246: The type or namespace name `com'
> could not be found. Are you missing a using directive or an assembly
> reference?
> testSnmpInteger.cs(2,1): error CS0246: The type or namespace name
> `mylib.myTypeA' could not be found. Are you missing a using directive or an
> assembly reference?
>
> But I haven't found/figured out how to structure the directories correctly,
> and/or build the files correctly.  I suspect there is a simple
> answer... I just haven't found it yet.  Any help would be
> appreciated.

This would all be much easier if you were using MonoDevelop rather
than working at the command line, but I suppose you're like me and
want to do it the hard way first. :-)

Charlie

> Fulko
>
>
>
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>


More information about the Mono-list mailing list