GPL v2.
[metaproxy-moved-to-github.git] / src / tstdl.cpp
1 /* $Id: tstdl.cpp,v 1.6 2007-05-09 21:23:09 adam Exp $
2    Copyright (c) 2005-2007, Index Data.
3
4 This file is part of Metaproxy.
5
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include "config.hpp"
23
24 #include <stdlib.h>
25 #include <iostream>
26 #if HAVE_DLFCN_H
27 #include <dlfcn.h>
28 #endif
29
30 using namespace std;
31
32 int main(int argc, char **argv)
33 {
34 #if HAVE_DLFCN_H
35     if (argc != 3)
36     {
37         cerr << "bad args" << endl << "Usage: tstdl filename symbol" << endl;
38         exit(1);
39     }
40     void *mod = dlopen(argv[1][0] ? argv[1] : 0, RTLD_NOW|RTLD_LOCAL);
41     if (!mod)
42     {
43         cerr << "dlopen failed for file '" << argv[1] << "'\n" <<
44             "dlerror=" << dlerror() << endl;
45         exit(1);
46     }
47     void *sym = dlsym(mod, argv[2]);
48     printf("sym=%p\n", sym);
49     dlclose(mod);
50     exit(0);
51 #else
52     cerr << "dl lib not enabled or not supported" << endl;
53     exit(1);
54 #endif
55
56 }
57 /*
58  * Local variables:
59  * c-basic-offset: 4
60  * indent-tabs-mode: nil
61  * c-file-style: "stroustrup"
62  * End:
63  * vim: shiftwidth=4 tabstop=8 expandtab
64  */