Bonjour,
Ce topic fait suite à celui-ci, mais le problème est a priori indépendant.
Avec cet ECM :
Fichier foo.hpp
Fichier foo.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 try.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 #include <iostream> #include "foo.hpp" void foo() { std::cout << "Foo.\n"; return; }
Je compile les fichiers objets sans problème:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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; }
Mais lors de la compilation de l'exécutable :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2$ g++ -c foo.cpp $ g++ -c try.cpp
Mes deux .o contiennent donc des symbols de fonctions identiques (ceux référant aux fonctions bessel et compagnie du binding de gmp/mpfr).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Comment y remédier ?
En vous remerciant.
Partager