1 /* mlib.c -- mlib library
3 Copyright (C) 2002, 2006 Free Software Foundation, Inc.
4 Written by Greg Eisenhauer, 2002
7 This file is part of GNU Libtool.
9 GNU Libtool is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of
12 the License, or (at your option) any later version.
14 GNU Libtool is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Libtool; see the file COPYING. If not, a copy
21 can be downloaded from http://www.gnu.org/licenses/gpl.html,
22 or obtained by writing to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 test_dl (char *filename)
34 const lt_dlinfo *info;
41 handle = lt_dlopen(filename);
43 fprintf (stderr, "can't open the module %s!\n", filename);
44 fprintf (stderr, "error was: %s\n", lt_dlerror());
48 info = lt_dlgetinfo(handle);
50 fprintf (stderr, "can't get module info: %s\n", lt_dlerror());
54 printf ("module name: %s\n", info->name);
56 printf ("module is not a libtool module\n");
58 printf ("module filename: %s\n", info->filename);
59 printf ("module reference count: %i\n", info->ref_count);
61 phello = (int(*)())lt_dlsym(handle, "hello");
64 int value = (*phello) ();
66 printf ("hello returned: %i\n", value);
67 if (value == HELLO_RET)
68 printf("hello is ok!\n");
72 fprintf (stderr, "did not find the `hello' function\n");
73 fprintf (stderr, "error was: %s\n", lt_dlerror());
77 pnothing = (int*)lt_dlsym(handle, "nothing");
78 /* Try assigning to the nothing variable. */
83 fprintf (stderr, "did not find the `nothing' variable\n");
84 fprintf (stderr, "error was: %s\n", lt_dlerror());
88 pfoo1 = (int(*)())lt_dlsym(handle, "foo1");
89 /* Just call the functions and check return values. */
92 if ((*pfoo1) () == FOO_RET)
93 printf("foo1 is ok!\n");
98 pfoo2 = (int(*)())lt_dlsym(handle, "foo2");
101 if ((*pfoo2) () == FOO_RET)
102 printf("foo2 is ok!\n");
107 fprintf (stderr, "did not find any of the `foo' functions\n");
108 fprintf (stderr, "error was: %s\n", lt_dlerror());
117 mlib_func (int argc, char **argv)
122 * Would be nice if this somehow worked for libraries, not just executables.
123 * LTDL_SET_PRELOADED_SYMBOLS();
125 if (lt_dlinit() != 0) {
126 fprintf (stderr, "error during initialization: %s\n", lt_dlerror());
130 for (i = 1; i < argc; i++)
131 if (test_dl(argv[i]))