3 mono-shlib-cop \- Shared Library Usage Checker
6 [OPTIONS]* [ASSEMBLY-FILE-NAME]*
9 .I \-p, --prefixes=PREFIX
10 Mono installation prefixes. This is to find $prefix/etc/mono/config.
11 The default is based upon the location of mscorlib.dll, and is normally
16 is a tool that inspects a managed assembly looking for
17 erroneous or suspecious behavior of shared libraries.
19 The tool takes one or more assembly filenames, and inspects each assembly
22 The errors checked for include:
25 Does the shared library exist?
28 Does the requested symbol exist within the shared library?
30 The warnings checked for include:
33 Is the target shared library a versioned library? (Relevant only on Unix
34 systems, not Mac OS X or Windows.)
36 In general, only versioned libraries such as libc.so.6 are present on the
37 user's machine, and efforts to load libc.so will result in a
38 System.DllNotFoundException. There are three solutions to this:
41 Require that the user install any -devel packages which provide the
42 unversioned library. This usually requires that the user install a large
43 number of additional packages, complicating the installation process.
46 Use a fully versioned name in your DllImport statements. This requires
47 editing your source code and recompiling whenever you need to target a
48 different version of the shared library.
51 Provide an assembly.config file which contains <dllmap/> elements to remap
52 the shared library name used by your assembly to the actual versioned shared
53 library present on the users system. Mono provides a number of pre-existing
54 <dllmap/> entries, including libc.so and libX11.so.
56 The following code contains examples of the above errors and warnings:
58 using System.Runtime.InteropServices; // for DllImport
60 [DllImport ("bad-library-name")]
61 private static extern void BadLibraryName ();
63 [DllImport ("libc.so")]
64 private static extern void BadSymbolName ();
66 [DllImport ("libcap.so")]
67 private static extern int cap_clear (IntPtr cap_p);
72 Assuming that the library
74 doesn't exist on your machine, Demo.BadLibraryName will generate an error, as
75 it requires a shared library which doesn't exist.
78 Demo.BadSymbolName will generate an error, as libc.so (remapped to libc.so.6
79 by mono's $prefix/etc/mono/config file) doesn't contain the function
82 Unversioned library dependency
83 Assuming you have the file libcap.so, Demo.cap_clear will generate a
84 warning because, while libcap.so could be loaded, libcap.so might not exist on
85 the users machine (on FC2, /lib/libcap.so is provided by
87 , and you can't assume that end users will have any -devel packages installed).
89 The fix depends on the warning or error:
92 Use a valid library name in the DllImport attribute, or provide a <dllmap/>
93 entry to map your existing library name to a valid library name.
96 Reference a symbol that actually exists in the target library.
98 Unversioned library dependency
99 Provide a <dllmap/> entry to reference a properly versioned library, or ignore
106 \.config file for each assembly loaded, and reads this file to find Dll
107 mapping information. For example, with
114 .I Mono.Posix.dll.config
117 The .config file is an XML document containing a top-level <configuration/>
118 section with nested <dllmap/> entries, which contains
122 attributes. The dll attribute should contain the same string used in your
123 DllImport attribute value, and the target attribute specifies which shared
128 A sample .config file is:
131 <dllmap dll="gtkembedmoz" target="libgtkembedmoz.so" />
136 currently only examines the shared library file extension to determine if a
137 warning should be generated. A
139 extension will always generate a warning, even if the .so is not a symlink,
140 isn't provided in a -devel package, and there is no versioned shared library
141 (possible examples including /usr/lib/libtcl8.4.so, /usr/lib/libubsec.so,
144 Consequently, warnings for any such libraries are useless, and incorrect.
146 Windows and Mac OS X will never generate warnings, as these
147 platforms use different shared library extensions.
149 Visit http://lists.ximian.com/mailman/listinfo/mono-devel-list for details.
151 Visit http://www.mono-project.com for details