[Cmake] Problem with -fPIC, dlopen and exception handling.

Bill Hoffman bill.hoffman at kitware.com
Thu Apr 24 13:39:33 EDT 2003


Please specify what OS/version you are running on.

-Bill


At 01:15 PM 4/24/2003, Marc Traina wrote:
>Hi,
>
>The 5 files attached with this mail demonstrate with a minimum of code the following problem :
>  - exceptions are no more handled after a dynamic loading of a shared library
>     compiled with the -fPIC flag that include two times the <string> declaration file....
>
>Few google searches show that I am not the only one to have this kind of problem with -fPIC, dlopen and exception handling.
>
>The only work around solution I have found is to not use the -fPIC compilation flag.
>
>1) How to ask cmake to compile shared libraries and associated ".o" files without the -fPIC flag ?
>
>2) Have you got an explanation of that problem ?
>
>
>Thanks
>
>Marc
>
>
>PROJECT(FOO)
>
>ADD_LIBRARY(bar SHARED
> bar1.cxx 
> bar2.cxx
>)
>
>ADD_EXECUTABLE(foo foo.cxx)
>
>TARGET_LINK_LIBRARIES(foo dl)
>#ifndef BAR_H
>#define BAR_H
>
>#include <string>
>
>class barBase  {
>  string m_what;
>  barBase() {}
>};
>
>
>#endif
>#include <bar.h>
>
>class bar1 {
>};
>
>#include <bar.h>
>
>class bar2 {
>
>};
>#include <iostream.h>
>#include <exception>
>#include <dlfcn.h>
>
>int main(int argc, char **argv) {
>
>  void *handle;
>
>  // Premier test
>  try {
>        throw exception ();
>  }
>  catch (...) {
>        cout << "test exception BEFORE LIB LOADING .............."<<endl;
>  }
>
>  // Chargement de la lib
>  handle = dlopen ("./libbar.so", RTLD_NOW|RTLD_GLOBAL);
>  if (!handle) {
>        cerr<< "ERREUR : "<< dlerror()<<endl;
>        exit(1);
>  }
>
>  // Lib OK - Second test
>  cout << "dlopen succeded .............."<<endl;
>  try {
>        throw exception ();
>  }
>  catch (...) {
>        cout << "test exception LIB LOADED .............."<<endl;
>  }
>
>  dlclose(handle);
>  return 0 ;
>}






More information about the CMake mailing list