Re: [eigen] shared libraries and including Eigen in base class

[ Thread Index | Date Index | More Archives ]

Indeed, thanks. This fixed things as far as I can tell.

Patch attached if no objections. Both functions required inline to compile for me.

On 8 June 2010 10:51, joel falcou <joel.falcou@xxxxxx> wrote:
Trevor Irons wrote:
I have a quick question

With the following classes

// base.h
#ifndef  BASE_INC
#define  BASE_INC
#include <Eigen/Eigen>
class Base {
       Base ();                           ~Base ();                   }; // -----  end of class  Base  -----
#endif   // ----- #ifndef BASE_INC  -----

// base.cpp
#include "base.h"
Base::Base() {}
Base::~Base() {}

// derived.h
#ifndef  DERIVED_INC
#define  DERIVED_INC
#include "base.h"
class Derived : public Base {
       Derived ();                           ~Derived ();                   }; // -----  end of class  Derived  -----
#endif   // ----- #ifndef DERIVED_INC  -----

#include "derived.h"
Derived::Derived() {}
Derived::~Derived() {}

If I compile these into a static library, all is fine. But using gcc and compiling into a shared library, the objects are made fine, but the call to the linker fails.

g++ -o base.os -c -fPIC -I/home/tirons/src/eigen base.cpp
g++ -o derived.os -c -fPIC -I/home/tirons/src/eigen derived.cpp

g++ -o -shared base.os derived.os

derived.os: In function `Eigen::l1CacheSize()':
derived.cpp:(.text+0x25cf): multiple definition of `Eigen::l1CacheSize()'
base.os:base.cpp:(.text+0x25cf): first defined here
derived.os: In function `Eigen::setL1CacheSize(long)':
derived.cpp:(.text+0x25f8): multiple definition of `Eigen::setL1CacheSize(long)'
base.os:base.cpp:(.text+0x25f8): first defined here

Is there some way around this? This type of code has been fine before some recent changes. I know these changes should help performance though. Maybe there are compelling reasons why you shouldn't be including Eigen in any base classes?

Thanks again,

Sounds some inline is missing on these functions.

# HG changeset patch
# User Trevor Irons <trevorirons@xxxxxxxxx>
# Date 1276016210 21600
# Node ID 717d617f1020c1490532623d3ff9086d7f75ba6a
# Parent  485014664186ed58371e308436535f27ac46b5de
added inline to setL1Cache functions to avoid shared object compile error

diff -r 485014664186 -r 717d617f1020 Eigen/src/Core/products/GeneralBlockPanelKernel.h
--- a/Eigen/src/Core/products/GeneralBlockPanelKernel.h	Tue Jun 08 16:02:22 2010 +0200
+++ b/Eigen/src/Core/products/GeneralBlockPanelKernel.h	Tue Jun 08 10:56:50 2010 -0600
@@ -82,7 +82,7 @@
 /** \returns the currently set cpu cache size (in bytes) used to estimate the ideal blocking size parameters.
   * \sa setL1CacheSize */
-std::ptrdiff_t l1CacheSize()
+inline std::ptrdiff_t l1CacheSize()
   std::ptrdiff_t ret;
   ei_manage_caching_sizes(GetAction, &ret);
@@ -104,7 +104,7 @@
   * with blocks of size max_m x max_k.
   * \sa ei_setBlockingSizes */
-void setL1CacheSize(std::ptrdiff_t cache_size) { ei_manage_caching_sizes(SetAction,&cache_size); }
+inline void setL1CacheSize(std::ptrdiff_t cache_size) { ei_manage_caching_sizes(SetAction,&cache_size); }
 /** Set the blocking size parameters \a maxK and \a maxM for the scalar type \a Scalar.
   * Note that in practice there is no distinction between scalar types of same size.

Mail converted by MHonArc 2.6.19+