IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Problème de compilation g++ : méthode "tout en un" vs "compilation + linkage"


Sujet :

C++

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 32
    Points : 16
    Points
    16
    Par défaut Problème de compilation g++ : méthode "tout en un" vs "compilation + linkage"
    Bonjour,

    J'ai quelques soucis pour compiler un code c++ en ligne de commande sur Ubuntu 11.10 (64 bits).

    Je voudrais compiler un projet simple. Les fichiers sont calibration.cpp et calibration.hpp

    calibration.hpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #ifndef  CALIBRATION_INC
    #define  CALIBRATION_INC
     
    #include <math.h>
    #include <iostream>
    #include <fstream>
     
    #include <opencv2/opencv.hpp>
     
    #endif
    include dans calibration.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    #include "calibration.hpp"
     
    using namespace cv;
    Lorsque j'utilise cette commande :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g++ -o calibration calibration.cpp -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy
    Tout marche bien. L'exécutable est bien créé et fonctionne.

    J'ai ensuite essayé de créer l'exécutable en deux fois : compilation + linkage et là ça ne marche plus et je ne comprends pas pourqoi.

    Compilation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g++ -o calibration.o -c -I/usr/local/include/opencv -I/usr/local/include calibration.cpp
    calibration .o est bien créé dans le répertoire.

    Linkage :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g++ -o calibration -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy calibration.o
    et là j'obtiens ce message d'erreur :
    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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    calibration.o: In function `cv::operator<<(cv::FileStorage&, char const*)':
    calibration.cpp:(.text+0x5f): undefined reference to `cv::operator<<(cv::FileStorage&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    calibration.o: In function `main':
    calibration.cpp:(.text+0xc9): undefined reference to `cvCreateCameraCapture'
    calibration.cpp:(.text+0x109): undefined reference to `cvSetCaptureProperty'
    calibration.cpp:(.text+0x11f): undefined reference to `cvSetCaptureProperty'
    calibration.cpp:(.text+0x135): undefined reference to `cvSetCaptureProperty'
    calibration.cpp:(.text+0x14a): undefined reference to `cvGrabFrame'
    calibration.cpp:(.text+0x1a3): undefined reference to `cvRetrieveFrame'
    calibration.cpp:(.text+0x1b6): undefined reference to `cvNamedWindow'
    calibration.cpp:(.text+0x1c5): undefined reference to `cvNamedWindow'
    calibration.cpp:(.text+0x1d6): undefined reference to `cvShowImage'
    calibration.cpp:(.text+0x3a2): undefined reference to `cvWaitKey'
    calibration.cpp:(.text+0x3f3): undefined reference to `cvQueryFrame'
    calibration.cpp:(.text+0x412): undefined reference to `cv::Mat::Mat(_IplImage const*, bool)'
    calibration.cpp:(.text+0x457): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0x470): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x490): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
    calibration.cpp:(.text+0x4ab): undefined reference to `cv::Mat::Mat(_IplImage const*, bool)'
    calibration.cpp:(.text+0x54a): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x56c): undefined reference to `cv::findChessboardCorners(cv::_InputArray const&, cv::Size_<int>, cv::_OutputArray const&, int)'
    calibration.cpp:(.text+0x60d): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x643): undefined reference to `cv::cornerSubPix(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Size_<int>, cv::TermCriteria)'
    calibration.cpp:(.text+0x6b0): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x6e2): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0x704): undefined reference to `cv::drawChessboardCorners(cv::_OutputArray const&, cv::Size_<int>, cv::_InputArray const&, bool)'
    calibration.cpp:(.text+0x72c): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x769): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
    calibration.cpp:(.text+0x795): undefined reference to `cvShowImage'
    calibration.cpp:(.text+0x84e): undefined reference to `cv::_OutputArray::_OutputArray(std::vector<cv::Mat, std::allocator<cv::Mat> >&)'
    calibration.cpp:(.text+0x867): undefined reference to `cv::_OutputArray::_OutputArray(std::vector<cv::Mat, std::allocator<cv::Mat> >&)'
    calibration.cpp:(.text+0x880): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0x899): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0x8b4): undefined reference to `cv::Mat::Mat(_IplImage const*, bool)'
    calibration.cpp:(.text+0x948): undefined reference to `cv::calibrateCamera(cv::_InputArray const&, cv::_InputArray const&, cv::Size_<int>, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, int)'
    calibration.cpp:(.text+0x9af): undefined reference to `cv::FileStorage::FileStorage(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    calibration.cpp:(.text+0xa47): undefined reference to `cv::FileStorage::~FileStorage()'
    calibration.cpp:(.text+0xa7d): undefined reference to `cvQueryFrame'
    calibration.cpp:(.text+0xa9c): undefined reference to `cv::Mat::Mat(_IplImage const*, bool)'
    calibration.cpp:(.text+0xae1): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0xafa): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0xb1a): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
    calibration.cpp:(.text+0xb35): undefined reference to `cv::Mat::Mat(_IplImage const*, bool)'
    calibration.cpp:(.text+0xbd4): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0xbf6): undefined reference to `cv::findChessboardCorners(cv::_InputArray const&, cv::Size_<int>, cv::_OutputArray const&, int)'
    calibration.cpp:(.text+0xc97): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0xccd): undefined reference to `cv::cornerSubPix(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Size_<int>, cv::TermCriteria)'
    calibration.cpp:(.text+0xffe): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0x1017): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text+0x1030): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x1049): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x1080): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x10b7): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x10f2): undefined reference to `cv::solvePnP(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, bool)'
    calibration.cpp:(.text+0x1124): undefined reference to `cv::noArray()'
    calibration.cpp:(.text+0x1159): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x1172): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x118b): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x11a4): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x11db): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x121b): undefined reference to `cv::projectPoints(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, double)'
    calibration.cpp:(.text+0x122f): undefined reference to `cv::noArray()'
    calibration.cpp:(.text+0x1264): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x127d): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x1296): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x12af): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x12e6): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x1326): undefined reference to `cv::projectPoints(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, double)'
    calibration.cpp:(.text+0x14e8): undefined reference to `cv::fillConvexPoly(cv::Mat&, cv::Point_<int> const*, int, cv::Scalar_<double> const&, int, int)'
    calibration.cpp:(.text+0x15b1): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
    calibration.cpp:(.text+0x167a): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
    calibration.cpp:(.text+0x1743): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
    calibration.cpp:(.text+0x180c): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
    calibration.cpp:(.text+0x18d5): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
    calibration.o:calibration.cpp:(.text+0x199e): more undefined references to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)' follow
    calibration.o: In function `main':
    calibration.cpp:(.text+0x1e6d): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
    calibration.cpp:(.text+0x1eaa): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
    calibration.cpp:(.text+0x1f5a): undefined reference to `cvQueryFrame'
    calibration.cpp:(.text+0x1f6f): undefined reference to `cvShowImage'
    calibration.cpp:(.text+0x2056): undefined reference to `cv::FileStorage::~FileStorage()'
    calibration.cpp:(.text+0x208d): undefined reference to `cv::FileStorage::~FileStorage()'
    calibration.o: In function `cv::FileStorage& cv::operator<< <cv::Mat>(cv::FileStorage&, cv::Mat const&)':
    calibration.cpp:(.text+0x2370): undefined reference to `cv::Exception::Exception(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    calibration.cpp:(.text+0x237c): undefined reference to `cv::error(cv::Exception const&)'
    calibration.cpp:(.text+0x2388): undefined reference to `cv::Exception::~Exception()'
    calibration.cpp:(.text+0x23f4): undefined reference to `cv::write(cv::FileStorage&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&)'
    calibration.cpp:(.text+0x2433): undefined reference to `cv::Exception::~Exception()'
    calibration.o: In function `cv::Mat::~Mat()':
    calibration.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
    calibration.o: In function `cv::Mat::clone() const':
    calibration.cpp:(.text._ZNK2cv3Mat5cloneEv[cv::Mat::clone() const]+0x2c): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text._ZNK2cv3Mat5cloneEv[cv::Mat::clone() const]+0x3f): undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
    calibration.o: In function `cv::Mat::create(int, int, int)':
    calibration.cpp:(.text._ZN2cv3Mat6createEiii[cv::Mat::create(int, int, int)]+0x8e): undefined reference to `cv::Mat::create(int, int const*, int)'
    calibration.o: In function `cv::Mat::release()':
    calibration.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
    calibration.o: In function `cv::_OutputArray::_OutputArray<cv::Point_<float> >(std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >&)':
    calibration.cpp:(.text._ZN2cv12_OutputArrayC2INS_6Point_IfEEEERSt6vectorIT_SaIS5_EE[_ZN2cv12_OutputArrayC5INS_6Point_IfEEEERSt6vectorIT_SaIS5_EE]+0x2a): undefined reference to `vtable for cv::_OutputArray'
    calibration.o: In function `cv::Mat::Mat<cv::Point_<float> >(std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > > const&, bool)':
    calibration.cpp:(.text._ZN2cv3MatC2INS_6Point_IfEEEERKSt6vectorIT_SaIS5_EEb[_ZN2cv3MatC5INS_6Point_IfEEEERKSt6vectorIT_SaIS5_EEb]+0x1f8): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text._ZN2cv3MatC2INS_6Point_IfEEEERKSt6vectorIT_SaIS5_EEb[_ZN2cv3MatC5INS_6Point_IfEEEERKSt6vectorIT_SaIS5_EEb]+0x258): undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
    calibration.o: In function `cv::_InputArray::_InputArray<cv::Point3_<float> >(std::vector<std::vector<cv::Point3_<float>, std::allocator<cv::Point3_<float> > >, std::allocator<std::vector<cv::Point3_<float>, std::allocator<cv::Point3_<float> > > > > const&)':
    calibration.cpp:(.text._ZN2cv11_InputArrayC2INS_7Point3_IfEEEERKSt6vectorIS4_IT_SaIS5_EESaIS7_EE[_ZN2cv11_InputArrayC5INS_7Point3_IfEEEERKSt6vectorIS4_IT_SaIS5_EESaIS7_EE]+0x17): undefined reference to `vtable for cv::_InputArray'
    calibration.o: In function `cv::_InputArray::_InputArray<cv::Point_<float> >(std::vector<std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >, std::allocator<std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > > > > const&)':
    calibration.cpp:(.text._ZN2cv11_InputArrayC2INS_6Point_IfEEEERKSt6vectorIS4_IT_SaIS5_EESaIS7_EE[_ZN2cv11_InputArrayC5INS_6Point_IfEEEERKSt6vectorIS4_IT_SaIS5_EESaIS7_EE]+0x17): undefined reference to `vtable for cv::_InputArray'
    calibration.o: In function `cv::Mat::Mat<cv::Point3_<float> >(std::vector<cv::Point3_<float>, std::allocator<cv::Point3_<float> > > const&, bool)':
    calibration.cpp:(.text._ZN2cv3MatC2INS_7Point3_IfEEEERKSt6vectorIT_SaIS5_EEb[_ZN2cv3MatC5INS_7Point3_IfEEEERKSt6vectorIT_SaIS5_EEb]+0x1f8): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
    calibration.cpp:(.text._ZN2cv3MatC2INS_7Point3_IfEEEERKSt6vectorIT_SaIS5_EEb[_ZN2cv3MatC5INS_7Point3_IfEEEERKSt6vectorIT_SaIS5_EEb]+0x258): undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
    calibration.o: In function `cv::_InputArray::_InputArray<cv::Point_<float> >(std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > > const&)':
    calibration.cpp:(.text._ZN2cv11_InputArrayC2INS_6Point_IfEEEERKSt6vectorIT_SaIS5_EE[_ZN2cv11_InputArrayC5INS_6Point_IfEEEERKSt6vectorIT_SaIS5_EE]+0x17): undefined reference to `vtable for cv::_InputArray'
    collect2: ld returned 1 exit status
    Pour moi les commandes "tout en un" ou "compilation + linkage" sont équivalentes, pourquoi dans un cas cela fonctionne et dans l'autre non ?

    Bonne journée,

    Merci

  2. #2
    Membre éclairé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2010
    Messages
    517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Santé

    Informations forums :
    Inscription : Avril 2010
    Messages : 517
    Points : 718
    Points
    718
    Par défaut
    Salut,
    As tu essayé:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g++ -o calibration.o -c -I/usr/local/include/opencv -I/usr/local/include calibration.cpp -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy
    et ensuite:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g++ -o calibration calibration.o
    ?

  3. #3
    screetch
    Invité(e)
    Par défaut
    mets les options -l apres le fichier .o

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 32
    Points : 16
    Points
    16
    Par défaut
    Merci c'était bien ça ! Il faut mettre calibration.o avant les librairies.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 21/04/2014, 13h52
  2. Problème d'accès aux méthodes d'une classe
    Par RR instinct dans le forum Langage
    Réponses: 5
    Dernier message: 26/06/2006, 14h51
  3. Problème pour appeler une méthode d'une autre classe
    Par tse_tilky_moje_imja dans le forum Général Python
    Réponses: 7
    Dernier message: 03/03/2006, 13h33
  4. Réponses: 11
    Dernier message: 29/04/2005, 19h45
  5. [TOMCAT] JSP problème d'accès aux méthodes d'une classes
    Par gunnm dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 22/05/2004, 14h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo