150472Speter/* This testcase is part of GDB, the GNU debugger. 233975Sjdp 333975Sjdp Copyright 2004, 2007, 2009, 2010, 2011 Free Software Foundation, Inc. 433975Sjdp 533975Sjdp This program is free software; you can redistribute it and/or modify 633975Sjdp it under the terms of the GNU General Public License as published by 7130575Sobrien the Free Software Foundation; either version 3 of the License, or 884947Sobrien (at your option) any later version. 9215082Simp 10215082Simp This program is distributed in the hope that it will be useful, 11130575Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 12215082Simp MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13130575Sobrien GNU General Public License for more details. 14215082Simp 15215082Simp You should have received a copy of the GNU General Public License 16130575Sobrien along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17215082Simp 18215082Simp#include <stdio.h> 19215082Simp#include <stdlib.h> 2044360Simp 2133975Sjdp#ifdef __WIN32__ 2233975Sjdp#include <windows.h> 2333975Sjdp#define dlopen(name, mode) LoadLibrary (TEXT (name)) 2484902Sobrien#ifdef _WIN32_WCE 2533975Sjdp# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) 2684902Sobrien#else 2784902Sobrien# define dlsym(handle, func) GetProcAddress (handle, func) 2833975Sjdp#endif 29215082Simp#define dlclose(handle) FreeLibrary (handle) 30215082Simp#else 31215082Simp#include <dlfcn.h> 32215082Simp#endif 33166638Smarcel 34166638Smarcel 35166638Smarcelvoid open_shlib () 36166638Smarcel{ 37166638Smarcel void *handle; 3890353Sobrien void (*foo) (int); 39215082Simp 40215082Simp handle = dlopen (SHLIB_NAME, RTLD_LAZY); 4134495Sjdp 4284902Sobrien if (!handle) 43131832Sobrien { 44130575Sobrien#ifdef __WIN32__ 4584902Sobrien fprintf (stderr, "error %d occurred\n", GetLastError ()); 4634495Sjdp#else 47215082Simp fprintf (stderr, "%s\n", dlerror ()); 48215082Simp#endif 4934495Sjdp exit (1); 5034495Sjdp } 51215082Simp 5235709Sjb foo = (void (*)(int))dlsym (handle, "foo"); 5352927Sjb 5452927Sjb if (!foo) 5584902Sobrien { 5652927Sjb fprintf (stderr, "%s\n", dlerror ()); 5752927Sjb exit (1); 5852927Sjb } 5935709Sjb 6035709Sjb foo (1); // call to foo 6135709Sjb foo (2); 6234495Sjdp 6335709Sjb dlclose (handle); 64} 65 66 67int main() 68{ 69 open_shlib (); 70 return 0; 71} 72