1 /*=========================================================================
4 Module: $RCSfile: loadmodule.cxx,v $
6 Date: $Date: 2008/09/15 15:49:21 $
7 Version: $Revision: 1.4 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 /* For some bizarre reason global symbol, mainly std::string
19 * are creating seg fault when loading a shared lib, build on top
20 * of a static gdcm lib */
25 int main(int, char* [])
27 //typedef itk::DynamicLoader dl;
30 // the type of function stored in the dynamic lib
31 typedef void (*fnptr)(void);
33 //This function gives a segmentation fault.
34 //std::cerr << "Last error before opening: " << dl::LastError() << std::endl;
36 //Fill in here <path_to_lib>/libadll.so"
37 std::string libname = GDCM_LIBRARY_OUTPUT_PATH "/libdynmodule.so";
39 //open the dynamic lib
40 //lh handle = dl::OpenLibrary( libname.c_str() );
41 lh handle = dlopen(libname.c_str(), RTLD_LAZY);
42 std::cerr << "address of handle: " << handle << std::endl;
45 std::cerr << "Ooops cannot open lib:" << libname << std::endl;
49 //std::cerr << "Error after opening: " << dl::LastError() << std::endl;
52 std::cerr << "Getting function address from lib" << std::endl;
53 void * aptr = dlsym(handle, "afunc");
57 std::cerr << "error in finding function" << std::endl;
58 //const char *er = dlerror();
59 //std::cerr << "dl says: " << dl::LastError() << std::endl;
61 std::cerr << "Closing libs" << std::endl;
62 //dl::CloseLibrary(handle);
64 //std::cerr << "dl says: " << dl::LastError() << std::endl;
66 std::cerr << "Exiting" << std::endl;
71 std::cerr << "Casting function address from lib" << std::endl;
72 fnptr afuncptr = (fnptr)(aptr);
74 std::cerr << "Calling function from lib" << std::endl;
77 // Create an instance of the GDCMImageIO class. This makes sure
78 // that the problematic gdcm-library is linked.
79 //itk::GDCMImageIO::Pointer gdcmio = itk::GDCMImageIO::New();
80 GDCM_NAME_SPACE::File *file = GDCM_NAME_SPACE::File::New();
81 file->Print(); // to avoid warning
83 std::cerr << "Closing libs" << std::endl;
84 //dl::CloseLibrary(handle);
87 //std::cerr << "dl says: " << dl::LastError() << std::endl;
89 std::cerr << "Exiting" << std::endl;