[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A multiple definition error in Creating library file: liboctave.dll.
From: |
Benjamin Lindner |
Subject: |
Re: A multiple definition error in Creating library file: liboctave.dll.a (gcc-4.3.2-dw2-TDM for mingw ) |
Date: |
Sat, 14 Feb 2009 16:55:10 +0100 |
User-agent: |
Thunderbird 2.0.0.18 (Windows/20081105) |
Creating library file: liboctave.dll.a
Sparse-C.o:Sparse-C.cc:(.text$_ZN11octave_sortISt7complexIdEE17ascending_compareES1_S1_[octave_sort<std::complex<double>
::ascending_compare(std::complex<double>, std::complex<double>)]+0x0):
multiple definition of `octave_sort<std::complex<double>
>::ascending_compare(std::complex<double>,
std::complex<double>)'
Array-C.o:c:\usr\Tatsu\mingwhome\octaves\octave-3.1.52\liboctave/Array-C.cc:44:
first defined here
This double-definition error occurs, because of different
implementations in the coding in Array-C.cc and Sparse-C.cc.
Array-C.cc defines a total template specialization of
octave_sort<Complex>::sort_ascending(const Complex&, const Complex&)
and
octave_sort<Complex>::sort_descending(const Complex&, const Complex&)
whereas Sparse-C.cc provides versions for
operator<(const Complex&, const Complex&)
and
operator>(const Complex&, const Complex&)
which are then used with the instantiated template function
octave_sort<T>::sort_ascending(const T&, const T&)
and
octave_sort<T>::sort_descending(const T&, const T&)
provided in octave-sort.cc.
I'm not sure this why this asymmtery, but changing the code in
Array-C.cc to define operator< and operator> as in Sparse-C.cc removes
the double-definition linker error.
Please consider the attached changeset.
BTW I also see that the code for comparing two Complex values differs in
Sparse-C.cc and Array-C.cc. Is this intentional?
benjamin
# HG changeset patch
# User Benjamin Lindner <address@hidden>
# Date 1234520357 -3600
# Node ID 61564358394a1d8fec880d01bcdad08ff200bd2e
# Parent 8f4e6bffc692606ff3dcea9cd669e617b17e8d88
fix multiple definition for octave_sort<Complex>::ascending_compare
diff -r 8f4e6bffc692 -r 61564358394a liboctave/Array-C.cc
--- a/liboctave/Array-C.cc Fri Feb 13 08:33:01 2009 +0100
+++ b/liboctave/Array-C.cc Fri Feb 13 11:19:17 2009 +0100
@@ -32,6 +32,25 @@
#include "Array.h"
#include "Array.cc"
+
+// FIXME -- should the comparison be the same as in Sparse-C.cc ?
+
+static bool
+operator < (const Complex& a, const Complex& b)
+{
+ return ((std::abs (a) < std::abs (b))
+ || ((std::abs (a) == std::abs (b)) && (arg (a) < arg (b))));
+}
+
+static bool
+operator > (const Complex& a, const Complex& b)
+{
+ return ((std::abs (a) > std::abs (b))
+ || ((std::abs (a) == std::abs (b)) && (arg (a) > arg (b))));
+}
+
+// This file must be included after the < and > operators are
+// defined to avoid errors with the Intel C++ compiler.
#include "oct-sort.cc"
template <>
@@ -41,22 +60,6 @@
return xisnan (x);
}
-template <>
-bool
-octave_sort<Complex>::ascending_compare (const Complex& a, const Complex& b)
-{
- return ((std::abs (a) < std::abs (b))
- || ((std::abs (a) == std::abs (b)) && (arg (a) < arg (b))));
-}
-
-template <>
-bool
-octave_sort<Complex>::descending_compare (const Complex& a, const Complex& b)
-{
- return ((std::abs (a) > std::abs (b))
- || ((std::abs (a) == std::abs (b)) && (arg (a) > arg (b))));
-}
-
static bool
nan_ascending_compare (const Complex& x, const Complex& y)
{
diff -r 8f4e6bffc692 -r 61564358394a liboctave/ChangeLog
--- a/liboctave/ChangeLog Fri Feb 13 08:33:01 2009 +0100
+++ b/liboctave/ChangeLog Fri Feb 13 11:19:17 2009 +0100
@@ -1,3 +1,10 @@
+2009-02-13 Benjamin Lindner <address@hidden>
+
+ * Array-C.cc: remove total template specialization of
octave_sort<T>::sort_ascending
+ and octave_sort<T>::sort_descending in favor of defining operator< and
operator> for
+ T=std::complex<double> (analogous to code in Sparse-C.cc). This fixes
double-defined
+ linker error with Sparse-C.cc
+
2009-02-12 Jaroslav Hajek <address@hidden>
* oct-inttypes.h (if_else_type): Remove