gpt4 book ai didi

c++ - XCode 构建失败 "undefined Symbols for architecture x86_64"

转载 作者:行者123 更新时间:2023-11-28 02:00:51 27 4
gpt4 key购买 nike

已解决:对于 OPENCV 解决方案,从 Jvinniec 查找答案,对于 FAST.H 解决方案,查找编辑

我查找了几个类似的问题,但还没有找到适合我的代码的解决方案。我得到的错误看起来像这样:

Undefined symbols for architecture x86_64:
"fast9_score(unsigned char const*, int, xy*, int, int)", referenced from:
detectCornersFast(unsigned char const*, int, int, int, int, int*) in main.o
"fast9_detect(unsigned char const*, int, int, int, int, int*)", referenced from:
detectCornersFast(unsigned char const*, int, int, int, int, int*) in main.o
"nonmax_suppression(xy const*, int const*, int, int*)", referenced from:
detectCornersFast(unsigned char const*, int, int, int, int, int*) in main.o
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in main.o
"cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
_main in main.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in main.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::operator=(cv::Mat const&) in main.o
cv::Mat::Mat(cv::Mat const&) in main.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in main.o
cv::String::String(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
"cv::imread(cv::String const&, int)", referenced from:
_main in main.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in main.o
"cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
_main in main.o
"cv::waitKey(int)", referenced from:
_main in main.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我在 XCode 中使用的架构是通用的。我构建并添加了 openCV 的搜索路径,而 fast9 方法位于 fast.h header 中。我试图删除项目的派生数据,但没有任何帮助。这是我的 main.cpp 代码:

#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include "opencv2/opencv.hpp"
#include "fast.h"

using namespace std;
using namespace cv;

typedef unsigned char byte;

Mat src; Mat dst; Mat tmp;
int rows; int cols;
byte* image;
xy* nonmax;

byte * matToBytes(Mat image){

int size = image.total() * image.elemSize();
byte * bytes = new byte[size];
std::memcpy(bytes, image.data, size * sizeof(byte));

return bytes;

}

xy* detectCornersFast(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners){

xy* corners;
int num_corners;
int* scores;
xy* nonmax;

corners = fast9_detect(im, xsize, ysize, stride, b, &num_corners);
scores = fast9_score(im, stride, corners, num_corners, b);
nonmax = nonmax_suppression(corners, scores, num_corners, ret_num_corners);

free(corners);
free(scores);

return nonmax;

}

int main(int argc, const char * argv[]) {

// insert code here...

vector<Mat> img;
vector<int> num_corners;
vector<xy*> nms;

src = imread(argv[1],1);

img.push_back(src);
double factor = sqrt(2);

for(int i = 0; i < 5; i++){

int ret_num_corners;
rows = src.rows/factor;
cols = src.cols/factor;

resize(src, tmp, Size(rows,cols),0,0, INTER_NEAREST);

GaussianBlur(tmp, dst, Size(5,5),0,0);

image = matToBytes(dst);

nonmax = detectCornersFast(image, tmp.rows, tmp.cols, tmp.rows, 20, &ret_num_corners);

img.push_back(dst);
nms.push_back(nonmax);
num_corners.push_back(ret_num_corners);

src = dst;

}

for(int i = 0; i <img.size(); i++){

string name = "Display Window " + std::to_string(i);
cout << "Number of Corners" << num_corners[i] << endl;
cout << "Nonmax Supression" << nms[i] << endl;
namedWindow(name, WINDOW_AUTOSIZE);
imshow(name, img[i]);
}

waitKey();
return 0;
}

编辑:对于 OpenCV 帮助添加本教程中的链接器标志:OpenCVfast 中的方法位于我的项目文件夹中的 .c 文件中。 .h 文件也在那里。我只是在这里发布 .h 文件,因为 .c 文件太长了,因为它是机械生成的。

解决方案:这是我对快速方法的错误。我完全忘记在 #include "fast.h" 的 main.cpp 中添加 Extern "C"{},因为它调用 C 文件而不是 C++ 文件。

快.h

#ifndef FAST_H
#define FAST_H

typedef struct { int x, y; } xy;
typedef unsigned char byte;

int fast9_corner_score(const byte* p, const int pixel[], int bstart);

xy* fast9_detect(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners);

int* fast9_score(const byte* i, int stride, xy* corners, int num_corners, int b);

xy* fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners);

xy* nonmax_suppression(const xy* corners, const int* scores, int num_corners, int* ret_num_nonmax);

#endif

最佳答案

听起来好像您只在项目“build设置”->“搜索路径”->“用户 header 搜索路径”字段下添加了这些依赖项的 header 搜索路径。这将使 xcode 在您开发时知道这些类存在,但不会使您的项目能够构建。您还应该确保您的项目知道在哪里可以找到定义您正在使用的 openCV 和 fast9 符号的库(即 .so 文件用于这两个依赖项的位置)。您可以通过在“Build Settings”->“Linking”->“Other Linker Flags”下添加适当的链接器标志来做到这一点。还要确保这些字段是为您尝试编译的目标设置的,而不仅仅是项目。

如果您不确定链接器标志是什么,这里有一个简短的例子。我想链接以下库:

/path/to/some/project/lib/libfoo.so

我会将以下内容添加到“其他链接器标志”字段:

-L/path/to/some/project/lib -lfoo

基本上-L在目录和 -l 之前在没有“lib”和“.so”的库名称之前。

注意:每当我在我的 xcode 项目中包含外部依赖项时,我也会将“build设置”->“搜索路径”->“始终搜索用户路径”设置为"is",以防任何依赖项包含带有角度的 header 括号如 #include <header.h> .

关于c++ - XCode 构建失败 "undefined Symbols for architecture x86_64",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39620558/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com