2 .\" mono-shlib-cop manual page.
3 .\" (C) 2005-2006 Jonathan Pryor
5 .\" Jonathan Pryor (jonpryor@vt.edu)
7 .de Sp \" Vertical space (when we can't use .PP)
11 .TH "mono-shlib-cop" 1
13 mono-shlib-cop \- Shared Library Usage Checker
16 [OPTIONS]* [ASSEMBLY-FILE-NAME]*
19 .I \-p, --prefixes=PREFIX
20 Mono installation prefixes. This is to find $prefix/etc/mono/config.
21 The default is based upon the location of mscorlib.dll, and is normally
26 is a tool that inspects a managed assembly looking for
27 erroneous or suspecious usage of shared libraries.
29 The tool takes one or more assembly filenames, and inspects each assembly
32 The errors checked for include:
35 Does the shared library exist?
38 Does the requested symbol exist within the shared library?
40 The warnings checked for include:
43 Is the target shared library a versioned library? (Relevant only on Unix
44 systems, not Mac OS X or Windows.)
46 In general, only versioned libraries such as
49 user's machine, and efforts to load
52 .B System.DllNotFoundException.
53 There are three solutions to this:
56 Require that the user install any
58 packages which provide the
59 unversioned library. This usually requires that the user install a large
60 number of additional packages, complicating the installation process.
63 Use a fully versioned name in your
65 statements. This requires
66 editing your source code and recompiling whenever you need to target a
67 different version of the shared library.
72 file which contains <dllmap/> elements to remap
73 the shared library name used by your assembly to the actual versioned shared
74 library present on the users system. Mono provides a number of pre-existing
75 <dllmap/> entries, including ones for
80 The following code contains examples of the above errors and warnings:
82 using System.Runtime.InteropServices; // for DllImport
84 [DllImport ("bad-library-name")]
85 private static extern void BadLibraryName ();
87 [DllImport ("libc.so")]
88 private static extern void BadSymbolName ();
90 [DllImport ("libcap.so")]
91 private static extern int cap_clear (IntPtr cap_p);
96 Assuming that the library
98 doesn't exist on your machine,
99 .I Demo.BadLibraryName
100 will generate an error, as
101 it requires a shared library which cannot be loaded.
102 This may be ignorable; see
107 .I Demo.BadSymbolName
108 will generate an error, as
113 .I $prefix/etc/mono/config
114 file) doesn't contain the function
118 Unversioned library dependency
119 Assuming you have the file
124 warning because, while
129 the users machine (on FC2,
133 , and you can't assume that end users will have any
137 The fix depends on the warning or error:
140 Use a valid library name in the
142 attribute, or provide a <dllmap/>
143 entry to map your existing library name to a valid library name.
146 Reference a symbol that actually exists in the target library.
148 Unversioned library dependency
149 Provide a <dllmap/> entry to reference a properly versioned library, or ignore
156 \.config file for each assembly loaded, and reads this file to find Dll
157 mapping information. For example, with
164 .I Mono.Posix.dll.config
169 file is an XML document containing a top-level <configuration/>
170 section with nested <dllmap/> entries, which contains
174 attributes. The dll attribute should contain the same string used in your
176 attribute value, and the target attribute specifies which shared
181 A sample .config file is:
184 <dllmap dll="gtkembedmoz" target="libgtkembedmoz.so" />
192 entries are checked; the surrounding IL is ignored. Consequently, if a runtime
193 check is performed to choose which shared library to invoke, an error will be
194 reported even though the specified library is never used. Consider this code:
196 using System.Runtime.InteropServices; // for DllImport
198 [DllImport ("kernel32.dll")]
199 private static extern int Beep (int dwFreq, int dwDuration);
201 [DllImport ("libcurses.so")]
202 private static extern int beep ();
204 public static void Beep ()
206 if (System.IO.Path.DirectorySeparatorChar == '\\\\') {
217 is run on this assembly, an error will be reported for using
221 will never be used on Unix platforms.
225 currently only examines the shared library file extension to determine if a
226 warning should be generated. A
228 extension will always generate a warning, even if the
233 package, and there is no versioned shared library
234 (possible examples including
235 .I /usr/lib/libtcl8.4.so,
236 .I /usr/lib/libubsec.so,
239 Consequently, warnings for any such libraries are useless, and incorrect.
241 Windows and Mac OS X will never generate warnings, as these
242 platforms use different shared library extensions.
244 Visit http://lists.ximian.com/mailman/listinfo/mono-devel-list for details.
246 Visit http://www.mono-project.com for details