1. 程式人生 > >ubuntu 下 make 編譯錯誤:undefined reference to cv::line

ubuntu 下 make 編譯錯誤:undefined reference to cv::line

在編譯一個專案時候出現 “undefined reference to cv::line” 的錯誤,是在連結其中一個靜態庫的時候出現的錯誤,錯誤如下:

/home/build/lib/libapriltags.a(TagDetection.cc.o): In function `AprilTags::TagDetection::draw(cv::Mat&) const':
TagDetection.cc:(.text+0x960): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
TagDetection.cc:(.text+0x9f9): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
TagDetection.cc:(.text+0xa93): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
TagDetection.cc:(.text+0xb06): undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'

       就上網查了一下,發現很多關於undefined reference這樣的問題,但是原因大多很複雜,在此,我以詳細地示例給出常見錯誤的各種原因以及解決方法,希望對其他遇到這種問題的有所幫助。

       經過多方面的排查發現,出現這個原因是因為AprilTags這個靜態庫的問題。 由於這個程式碼是從別人那接手的,在配置環境的過程中出現的這個問題。由於AprilTags這個靜態庫別人在編譯的時候是基於他的環境,即基於opencv2.4.8編譯的,我用的環境是opencv3.1.0的版本,但是之前不知道是這個問題。

        所以解決辦法有兩種,一種是使用和AprilTags這個靜態庫編譯時相同的opencv版本,即使用opencv2.4.8, 另一種方法是 在opencv3.1.0下重新將AprilTags這個靜態庫編譯一遍。

        一般出現這種問題都很隱祕,在解決的時候要多方面排查。