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

Brad King brad.king at kitware.com
Fri Apr 25 09:17:08 EDT 2003


> These are the posts I have found concerning the same problem :
> http://groups.google.fr/groups?q=dlopen+fpic+exception+handled&hl=fr&lr=&ie=UTF-8&oe=UTF-8&scoring=d&selm=3AB10AFD.C003554D%40earthlink.net&rnum=1

This one describes a problem resulting from having a C executable for
main() and loading a C++ shared library.

> http://groups.google.fr/groups?q=fpic+exception+dlopen+g%2B%2B&hl=fr&lr=&ie=UTF-8&oe=UTF-8&selm=449d8b5a.0105220805.54b7f35c%40posting.google.com&rnum=2

This one describes a problem with an exception passing through the
C-implemented dl library code.

> http://gcc.gnu.org/ml/gcc-bugs/1999-01/msg00782.html

This one seems to describe a bug that exists in egcs, which was a compiler
version before egcs and gcc merged together in gcc 2.95.  Note also that
the problem occurs even though the .o is built without -fPIC.

None of these seems to describe your problem exactly.  I'm surprised that
your example code fails for you because it doesn't have any of the
problems described in these messages.  I'd suggest looking for a solution
other than removing -fPIC, but if you end up deciding to go that way, here
is how:

Create a file that will be used to override makefile rule generation:

# MyMakeRules.cmake:
SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")

This file can be located anywhere you wish, and have any name.  The
CMAKE_SHARED_LIBRARY_CXX_FLAGS specifies the flags used to compile a .o
file that will be in a C++ shared library.  It is normally set to "-fPIC"
on linux.

Add the following cache entry to the project:

CMAKE_USER_MAKE_RULES_OVERRIDE:STRING=<path-to>MyMakeRules.cmake

(obviously, you have to write something in place of "<path-to>"). This
tells CMake where to load the project's override rules. You can setup your
CMake listfile code to do this automatically like this:

IF( ... test for whether this platform needs work-around ... )
  SET(CMAKE_USER_MAKE_RULES_OVERRIDE "${FOO_SOURCE_DIR}/MyMakeRules.cmake"
      CACHE STRING "Override makefile generation rules.")
ENDIF( ... test for whether this platform needs work-around ... )

-Brad




More information about the CMake mailing list