存在未定义的引用BUT标头
undefined reference BUT header is there
我正在尝试运行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.cpp
和img_io.cpp
,同时提供头文件(-Ipathtodirectory
)的位置。以下是一个工作片段,假设您在examples
目录中:
g++ image_match.cpp ../ezsift.cpp ../util/img_io.cpp -I.. -o image_match
相关文章:
- g++ 说函数不存在,即使包含正确的标头
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 在CMake中使用find_package时,是否会显式包含标头
- 错误"Could not find Boost"(缺少:上下文标头)
- 如何在标头中声明(或定义)函数的问题
- 如何避免在仅标头库中C++类/变量重定义
- C++算法标头中,为什么要使用 "!(val < *first)" ?
- C++标头错误 C2238 意外标记";"
- std::initializer_list,大括号初始化和标头
- 在 c++ 中拆分类和标头中的继承,错误
- 如何确定哪个标头调用 c++ 中的另一个标头
- 如何在生成文件中添加多个标头 (HDR) 和对象?
- 我可以在运行时重新定义在 OpenCascade/OCCT 标头中定义的 c++ 静态常量吗?
- GCC,CMake,预编译标头和维护依赖项
- VisualStudio:使用 Suse Enterprise Server 12 SP5 时,不会下载远程库标头
- 一个标头库中的错误
- 可视化 Bazel C++预编译标头实现
- 如何在 CMake 中添加预编译标头用于 Visual Studio 生成器
- 使用 GN 构建预编译标头
- 存在未定义的引用BUT标头