J'essaie d'utiliser la bibliothèque NTL, mais j'obtiens toujours des erreurs de compilation sur les symboles non définis.Erreurs de compilation à l'aide de la bibliothèque NTL
Exemple (extrait de la documentation NTL):
#include <NTL/ZZ.h>
NTL_CLIENT
int main()
{
ZZ a, b, c;
cin >> a;
cin >> b;
c = (a+1)*(b+1);
cout << c << "\n";
}
Résultat:
$ g++ -lntl simple.cpp
/tmp/ccGwxURb.o: In function `main':
simple.cpp:(.text+0x3a): undefined reference to `NTL::operator>>(std::basic_istream<char, std::char_traits<char> >&, NTL::ZZ&)'
simple.cpp:(.text+0x4b): undefined reference to `NTL::operator>>(std::basic_istream<char, std::char_traits<char> >&, NTL::ZZ&)'
simple.cpp:(.text+0xda): undefined reference to `NTL::operator<<(std::basic_ostream<char, std::char_traits<char> >&, NTL::ZZ const&)'
/tmp/ccGwxURb.o: In function `NTL::ZZ::operator=(NTL::ZZ const&)':
simple.cpp:(.text._ZN3NTL2ZZaSERKS0_[NTL::ZZ::operator=(NTL::ZZ const&)]+0x22): undefined reference to `_ntl_gcopy'
/tmp/ccGwxURb.o: In function `NTL::ZZ::~ZZ()':
simple.cpp:(.text._ZN3NTL2ZZD2Ev[_ZN3NTL2ZZD5Ev]+0x14): undefined reference to `_ntl_gfree'
/tmp/ccGwxURb.o: In function `NTL::add(NTL::ZZ&, NTL::ZZ const&, long)':
simple.cpp:(.text._ZN3NTL3addERNS_2ZZERKS0_l[NTL::add(NTL::ZZ&, NTL::ZZ const&, long)]+0x2a): undefined reference to `_ntl_gsadd'
/tmp/ccGwxURb.o: In function `NTL::mul(NTL::ZZ&, NTL::ZZ const&, NTL::ZZ const&)':
simple.cpp:(.text._ZN3NTL3mulERNS_2ZZERKS0_S3_[NTL::mul(NTL::ZZ&, NTL::ZZ const&, NTL::ZZ const&)]+0x2d): undefined reference to `_ntl_gmul'
collect2: ld returned 1 exit status
Les en-têtes NTL sont en /usr/include/NTL
, donc ils devraient être inclus.
Quel est le problème? Est-ce que je compile dans le mauvais sens? Si oui, où puis-je trouver le bon chemin, car il semble qu'il n'y ait pas une telle chose comme "comment compiler avec ntl" dans la documentation?
Si je using namespace NTL
au lieu de NTL_CLIENT
rien ne change:
$ ls /usr/lib | grep libntl
libntl-5.4.2.so
libntl.a
libntl.so
$ ls /usr/include | grep NTL
NTL
$ g++ -L/usr/lib -lntl -lgmp -lm simple.cpp
/tmp/ccwdQkr4.o: In function `main':
simple.cpp:(.text+0x3a): undefined reference to `NTL::operator>>(std::basic_istream<char, std::char_traits<char> >&, NTL::ZZ&)'
simple.cpp:(.text+0x4b): undefined reference to `NTL::operator>>(std::basic_istream<char, std::char_traits<char> >&, NTL::ZZ&)'
simple.cpp:(.text+0xda): undefined reference to `NTL::operator<<(std::basic_ostream<char, std::char_traits<char> >&, NTL::ZZ const&)'
/tmp/ccwdQkr4.o: In function `NTL::ZZ::operator=(NTL::ZZ const&)':
simple.cpp:(.text._ZN3NTL2ZZaSERKS0_[NTL::ZZ::operator=(NTL::ZZ const&)]+0x22): undefined reference to `_ntl_gcopy'
/tmp/ccwdQkr4.o: In function `NTL::ZZ::~ZZ()':
simple.cpp:(.text._ZN3NTL2ZZD2Ev[_ZN3NTL2ZZD5Ev]+0x14): undefined reference to `_ntl_gfree'
/tmp/ccwdQkr4.o: In function `NTL::add(NTL::ZZ&, NTL::ZZ const&, long)':
simple.cpp:(.text._ZN3NTL3addERNS_2ZZERKS0_l[NTL::add(NTL::ZZ&, NTL::ZZ const&, long)]+0x2a): undefined reference to `_ntl_gsadd'
/tmp/ccwdQkr4.o: In function `NTL::mul(NTL::ZZ&, NTL::ZZ const&, NTL::ZZ const&)':
simple.cpp:(.text._ZN3NTL3mulERNS_2ZZERKS0_S3_[NTL::mul(NTL::ZZ&, NTL::ZZ const&, NTL::ZZ const&)]+0x2d): undefined reference to `_ntl_gmul'
collect2: ld returned 1 exit status
$ cat simple.cpp
#include <NTL/ZZ.h>
using namespace NTL;
int main()
{
ZZ a, b, c;
std::cin >> a;
std::cin >> b;
c = (a+1)*(b+1);
std::cout << c << "\n";
}
Cette réponse passe à côté du point: 1) Si vous avez lu ma question, vous pouvez voir I * do * utiliser '-lntl', et j'ai aussi mentionné le fait que les NTL sont installés correctement [oui, je viens de dire que les en-têtes étaient à la bonne place, mais j'ai vérifié et il y a un libntl.so dans/usr/lib]. 2) Il n'y a pas de "documentation" pour NTL. J'ai trouvé une brève explication sur la compilation, mais cela ne résout pas le problème. – Bakuriu
Eh bien, vous n'utilisez pas '-lntl' pour résoudre les symboles. Il est correct que je ne l'ai pas vu mais en le mentionnant d'abord n'est pas où je regardais: les dossiers d'objet, en incluant des bibliothèques, sont traités de gauche à droite. Mentionnez les bibliothèques après votre source si vous voulez que les symboles soient résolus. –
Ok, mettre le "-lX" après l'argument fonctionne. Mais je ne comprends pas pourquoi cela devrait arriver. Pourquoi l'ordre est-il important? Et aussi, j'ai toujours pensé que la façon "correcte" d'appeler un programme est '$ name [options] arguments ...', alors pourquoi 'g ++' veut des arguments avant les options? – Bakuriu