Link & multiple definition
Bonjour,
Ce topic fait suite à celui-ci, mais le problème est a priori indépendant.
Avec cet ECM :
Fichier foo.hpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #ifndef H_FOO
#define H_FOO
#include <boost/math/bindings/mpfr.hpp>
#include <boost/rational.hpp>
namespace std { // std : specialization
template <> class numeric_limits<mpz_class> {
public:
static const bool is_specialized = true;
static const bool is_signed = false;
};
} // namespace std
typedef boost::rational<mpz_class> rat;
class Foo {
private:
rat r;
public:
Foo() : r() {};
Foo(const rat& r_) : r(r_) {};
Foo(const mpz_class& n, const mpz_class& d) : r(n,d) {};
};
void foo();
#endif // H_FOO |
Fichier foo.cpp
Code:
1 2 3 4 5 6 7
| #include <iostream>
#include "foo.hpp"
void foo() {
std::cout << "Foo.\n";
return;
} |
Fichier try.cpp
Code:
1 2 3 4 5 6 7 8 9 10
| #include <iostream>
#include "foo.hpp"
int main(void) {
mpz_class num("17"), den("29");
Foo f(num, den);
foo();
return 0;
} |
Je compile les fichiers objets sans problème:
Code:
1 2
| $ g++ -c foo.cpp
$ g++ -c try.cpp |
Mais lors de la compilation de l'exécutable :
Code:
1 2 3 4 5 6 7 8 9 10 11
| $ g++ try.o foo.o -lgmp -lmpfr -lgmpfrxx
foo.o: In function `fmod(__gmp_expr<__mpfr_struct [1], __mpfr_struct [1]> const&, __gmp_expr<__mpfr_struct [1], __mpfr_struct [1]> const&)':
foo.cpp:(.text+0x0): multiple definition of `fmod(__gmp_expr<__mpfr_struct [1], __mpfr_struct [1]> const&, __gmp_expr<__mpfr_struct [1], __mpfr_struct [1]> const&)'
try.o:try.cpp:(.text+0x0): first defined here
foo.o: In function `boost::math::detail::bessel_i0(__gmp_expr<__mpfr_struct [1], __mpfr_struct [1]>)':
foo.cpp:(.text+0x1cc): multiple definition of `boost::math::detail::bessel_i0(__gmp_expr<__mpfr_struct [1], __mpfr_struct [1]>)'
try.o:try.cpp:(.text+0x1cc): first defined here
foo.o: In function `boost::math::detail::bessel_i1(__gmp_expr<__mpfr_struct [1], __mpfr_struct [1]>)':
foo.cpp:(.text+0xeb1): multiple definition of `boost::math::detail::bessel_i1(__gmp_expr<__mpfr_struct [1], __mpfr_struct [1]>)'
try.o:try.cpp:(.text+0xeb1): first defined here
collect2: ld returned 1 exit status |
Mes deux .o contiennent donc des symbols de fonctions identiques (ceux référant aux fonctions bessel et compagnie du binding de gmp/mpfr).
Comment y remédier ?
En vous remerciant.