[Trilinos-Users] Building with -fPIC flag
wfspotz at sandia.gov
Sat Jul 30 11:39:36 MDT 2011
My suspicion here is that matlap, a dynamic tool, expects dynamic (shared) libraries. When you tried to load a static library, the lack of position independent code was the symptom, not the underlying problem. Given your Epetra/AztecOO behavior, my guess is that Epetra worked because Epetra does not depend on any other packages. However, AztecOO depends on Epetra, so when you tried to load AztecOO into matlab, it loaded Epetra a second time (which is how static libraries behave in a dynamic setting). At this point, matlab had two copies of Epetra, meaning duplication of symbols, and matlab (or the compiler that compiled it) got confused.
By compiling as shared, AztecOO will "share" the existing Epetra library, which is what you want.
On Jul 29, 2011, at 12:46 PM, Perschbacher, Brent M wrote:
> Hello Chris,
> What Bill said is true, turning on shared libraries will force the
> libraries to be built with position independent code. I have a feeling that
> this is more along the lines of what matlab is expecting too, ie using
> dlopen to load the correct libraries.
> However, what you did should work too, at least for building static libs
> with position independent code. I just did a test on my machine and adding
> -fPIC to the compile flags worked. Why your aztecoo libraries didn't built
> with it I couldn't say without more information. If you you really want to
> stay with static libraries I would suggest you run "make clean" in your
> build dir, delete your CMakeCache.txt file and CMakeFiles directory and then
> try configuring and building again. If you don't require static libraries
> then enabling shared libraries is the easiest way to go.
> On 7/29/11 12:27 PM, "Bill Spotz" <wfspotz at sandia.gov> wrote:
>> Position independent code is associate with shared libraries. I believe that
>> if you configure with
>> -D BUILD_SHARED_LIBS:BOOL=ON
>> then all of the libraries should be compiled properly for you.
>> On Jul 29, 2011, at 11:14 AM, Christopher Parmer wrote:
>>> Hi All,
>>> I'm linking my trilinos project with matlab and so I (er.. matlab mex files)
>>> need the libraries to be 'position independent' or compiled with the -fPIC
>>> I tried rebuilding trilinos (via ccmake, make, make install) with -fPIC in
>>> CMAKE_CXX_FLAGS, (and later I added it to CMAKE_C_FLAGS,
>>> CMAKE_EXE_LINKER_FLAGS), but I get the same error with respect to the
>>> libaztecoo and a few other packages. However, my simple examples with Epetra
>>> CrsMatrices now work.
>>> Am I missing a flag somewhere? Or are some libraries not written to be
>>> 'position independent'?
>>> Sorry if this is a simple question - I'm very new to linking and building
>>> large packages.
>>> (802) 343-5897
>>> Trilinos-Users mailing list
>>> Trilinos-Users at software.sandia.gov
>> ** Bill Spotz **
>> ** Sandia National Laboratories Voice: (505)845-0170 **
>> ** P.O. Box 5800 Fax: (505)284-0154 **
>> ** Albuquerque, NM 87185-0370 Email: wfspotz at sandia.gov **
>> Trilinos-Users mailing list
>> Trilinos-Users at software.sandia.gov
More information about the Trilinos-Users