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