存在未定义的引用BUT标头

undefined reference BUT header is there

本文关键字:BUT 标头 引用 未定义 存在      更新时间:2023-10-16

我正在尝试运行ezsift库示例。该示例的名称为"image_match.cpp"。

这是代码

image_match.cpp

#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "../ezsift.h"
using namespace std;
#define USE_FIX_FILENAME 0
int main(int argc, char ** argv)
{
#if USE_FIX_FILENAME
    char * file1 = "img1.pgm";
    char * file2 = "img2.pgm";
#else
    if (argc != 3)
    {
        printf("Please input two image filenames.n");
        printf("usage: image_match img1 img2n");
        return -1;
    }
    char file1[255];
    char file2[255];
    memcpy(file1, argv[1], sizeof(char) * strlen(argv[1]));
    file1[strlen(argv[1])] = 0;
    memcpy(file2, argv[2], sizeof(char) * strlen(argv[2]));
    file2[strlen(argv[2])] = 0;
#endif
    // Read two input images
    ImageObj<uchar> image1, image2;
    if(image1.read_pgm(file1) != 0)
    {
        printf("Failed to open input image1!n");
        return -1;
    }
    if(image2.read_pgm(file2) != 0)
    {
        printf("Failed to open input image2!n");
        return -1;
    }
    printf("Image 1 loaded. Image size: %d x %dn", image1.w, image1.h);
    printf("Image 2 loaded. Image size: %d x %dn", image2.w, image2.h);
    // Double the original image as the first octive.
    double_original_image(true);
    // Detect keypoints
    list<SiftKeypoint> kpt_list1, kpt_list2;
    printf("nSIFT detection on image 1 ...n");
    sift_cpu(image1, kpt_list1, true);
    printf("# keypoints in image1: %dn", kpt_list1.size());
    printf("nSIFT detection on image 2 ...n");
    sift_cpu(image2, kpt_list2, true);
    printf("# keypoints in image2: %dn", kpt_list2.size());
    // Save keypoint list, and draw keypoints on images.
    char filename[255];
    sprintf(filename, "s_A_keypoints.ppm");
    draw_keypoints_to_ppm_file(filename, image1, kpt_list1);
    export_kpt_list_to_file("s_A_keypoints.key", kpt_list1, true);
    sprintf(filename, "s_B_keypoints.ppm");
    draw_keypoints_to_ppm_file(filename, image2, kpt_list2);
    export_kpt_list_to_file("s_B_keypoints.key", kpt_list2, true);
    // Match keypoints.
    list<MatchPair> match_list;
    match_keypoints(kpt_list1, kpt_list2, match_list);
    // Draw result image.
    sprintf(filename, "s_A_B_matching.ppm");
    draw_match_lines_to_ppm_file(filename, image1, image2, match_list);
    printf("# of matched keypoints: %dn", match_list.size());
    return 0;
}

ezsift.h

#ifndef EZSIFT_H
#define EZSIFT_H
#include "util/image.h"
#include "util/img_io.h"
#include <vector>
#include <list>
.
.
.
#endif
#define DEGREE_OF_DESCRIPTORS (128)
// Enable doubling of original image.
void double_original_image(bool doubleFirstOctave);
// Detect keypoints and extract descriptor.
int sift_cpu(
    const ImageObj<uchar> &image, 
    std::list<SiftKeypoint> & kpt_list, 
    bool bExtractDescriptors);
// Match keypoints from two keypoint lists.
int match_keypoints(
    std::list<SiftKeypoint> & kpt_list1,
    std::list<SiftKeypoint> & kpt_list2,
    std::list<MatchPair> & match_list);
.
.
.
#endif

(我不会在这里包含所有代码,我只是想给出一个想法。下载源代码并查看我正在谈论的文件很容易)

还有一个"ezsift.cpp"文件,在"util"文件夹中有更多文件

我正试着从终端运行它。我转到该目录并键入"gcc-image_match.cpp",但据说没有定义double_original_image、screen_cpu(以及头文件中的所有其他函数)。

更具体地说是给出这个错误:

image_match.cpp:(.text+0x1c7): undefined reference to `double_original_image(bool)'
image_match.cpp:(.text+0x20d): undefined reference to `sift_cpu(ImageObj<unsigned char> const&, std::list<_SiftKeypoint, std::allocator<_SiftKeypoint> >&, bool)'

(当然,这不是唯一的错误。它为所有功能提供了相同的错误)

然后我尝试了"gcc../ezsive.cpp image_match.cpp",但出现了同样的错误。

我做错了什么??我正在运行ubuntu 14.04。

(将Cameron的评论扩展为测试答案)

您需要使用程序(image_match.cpp)编译ezsift.cppimg_io.cpp,同时提供头文件(-Ipathtodirectory)的位置。以下是一个工作片段,假设您在examples目录中:

g++ image_match.cpp  ../ezsift.cpp ../util/img_io.cpp -I.. -o image_match