【问题标题】:Mac C++ Clion,Undefined symbols for architecture x86_64, FunctionMac C++ Clion,架构 x86_64 的未定义符号,函数
【发布时间】:2017-12-03 21:45:40
【问题描述】:

我是新人,使用MacOS Clion开发C++程序,一直没有解决问题,请大家帮忙,谢谢! .h 文件:

namespace VLJudge {

class JudgeProcess {

public:
    static JudgeProcess* instance();
    void fileProcess(const std::string &file_path_, const std::string &folder_out,
                     const std::vector<std::string> &outs);

private:
    static JudgeProcess* instance_;

    bool verifySizes(const cv::Mat &mat, cv::Rect mr);
};

}

.cpp 文件:

#include "judge/judge_process.h"
#include "vl.h"
using namespace cv;
using namespace std;
using namespace VL;
namespace VLJudge {
const int DEFAULT_WIDTH_SIZE = 1000;
const int THRESHOLD_MAX_VALUE = 255;
const int DEFAULT_GAUSSIANBLUR_SIZE = 11;
const int THRESHOLD_BLOCK_SIZE = 25;
const int THRESHOLD_CONST_VALUE = 5;

const int DEFAULT_MORPH_SIZE_WIDTH = 15;  // 17
const int DEFAULT_MORPH_SIZE_HEIGHT = 1;  // 3
void JudgeProcess::fileProcess(const std::string &file_path_, const std::string &folder_out,
                               const std::vector<std::string> &outs) {

    std::vector<std::string> files;
    cv::Mat image, zoom, blur, gray, threshold, morphology;

    image = cv::imread(file_path_, ImreadModes::IMREAD_COLOR);

    Utils::resizeScale(image, zoom, DEFAULT_WIDTH_SIZE);

    GaussianBlur(zoom, blur, Size(DEFAULT_GAUSSIANBLUR_SIZE, DEFAULT_GAUSSIANBLUR_SIZE), 0, 0);

    cvtColor(blur, gray, CV_RGB2GRAY);

    adaptiveThreshold(gray, threshold, THRESHOLD_MAX_VALUE, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV,
                      THRESHOLD_BLOCK_SIZE, THRESHOLD_CONST_VALUE);

    Mat element = cv::getStructuringElement(MORPH_ELLIPSE,
                                            Size(DEFAULT_MORPH_SIZE_WIDTH, DEFAULT_MORPH_SIZE_HEIGHT));
    morphologyEx(threshold, morphology, MORPH_CLOSE, element);

    vector<vector<Point> > contours;
    findContours(morphology, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

    vector<Rect> outRects;
    for (int i = 0; i < contours.size(); i++) {
        Rect rect = cv::boundingRect(Mat(contours.at(i)));
        if (verifySizes(zoom, rect)) {
            outRects.push_back(rect);
            cv::Mat tempImg;
            zoom(outRects[i]).copyTo(tempImg);
            string filename = folder_out + "/" + Utils::getFileName(file_path_) + "_" + Utils::int2str(i) + ".jpg";
            files.push_back(filename);
            imwrite(filename, tempImg);
        }
    }
}


bool JudgeProcess::verifySizes(const cv::Mat &mat, cv::Rect mr) {
    if (1.0 * mr.y > 100 || 1.0 * mr.width * mr.height < 510.0f || mr.x == 0 || mr.y == 0) {
        return false;
    }
    return true;
}

JudgeProcess* JudgeProcess::instance_ = nullptr;

JudgeProcess* JudgeProcess::instance() {
    if (!instance_) {
        instance_ = new JudgeProcess;
    }
    return instance_;
}

}

调用函数代码:

#include "vl.h"
#include "judge/judge_process.h"

using namespace std;

const string test_file_path = "../../resource/judge/origin/1_standard.png";
const string file_process = "../../resource/judge/origin/1_standard.png";

int main(int argc, char *argv[]) {
    std::vector<std::string> filenames ;
       VLJudge::JudgeProcess::instance()->fileProcess(test_file_path,file_process,filenames);

    for (int i = 0; i < filenames.size(); ++i) {
            string filename = filenames.at(i);
    }

    return 0;

}

和错误日志:

  • /Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/liqiang /Library/Caches/CLion12/cmake/generated/6f5d7cd5/6f5d7cd5/Debug --target VehicleLicenseOCR -- -j 4 扫描目标 VehicleLicenseOCR 的依赖关系 [ 50%] 构建 CXX 对象 CMakeFiles/VehicleLicenseOCR.dir/src/judge /main_judge.cpp.o [100%] 链接 CXX 可执行 VehicleLicenseOCR 架构 x86_64 的未定义符号: “VL​​Judge::JudgeProcess::fileProcess(std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&, std::__1: :vector, std::__1::allocator >, std::__1::allocator, std::__1::allocator > > > const&)”,引用自: main_judge.cpp.o 中的 _main “VL​​Judge::JudgeProcess::instance()”,引用自: main_judge.cpp.o 中的 _main ld:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) make[3]: * [VehicleLicenseOCR] 错误 1 make[2]: [CMakeFiles/VehicleLicenseOCR.dir/all] 错误 2 make[1]: [CMakeFiles/VehicleLicenseOCR.dir/rule] 错误 2 make: * [VehicleLicenseOCR] 错误 2

【问题讨论】:

    标签: c++ macos function clion


    【解决方案1】:

    我也遇到了类似的问题,虽然使用的是不同的库。

    我认为here 的答案可能会有所帮助!

    我认为您需要做的是正确配置您的 CMakeLists.txt 文件,以便在编译时链接这些库(前提是这些库已正确安装在您的系统上)。

    通常只需下载,然后执行以下命令即可安装库。

    ./configure
    make
    make install
    

    解决方案...

    我认为您的 CMakeLists.txt 文件应该包含与此类似的内容...

    包含mac os包目录

    这是我的库安装到的地方

    include_directories(/usr/local/lib/pkgconfig)
    

    查找库

    find_library(<LIBRARY_NAME>_lib <LIBRARY_NAME>)
    
    # Group the libraries
    set(frameworks
            ${<LIBRARY_NAME>_lib})
    

    对源文件进行分组

    set(SOURCE_FILES main.c main.h)
    
    add_executable(Test ${SOURCE_FILES})
    

    链接库

    target_link_libraries(Test ${frameworks})
    

    我希望这可以帮助您走上正轨!

    【讨论】:

      猜你喜欢
      • 2021-10-03
      • 2015-06-17
      • 2016-03-25
      • 2020-12-10
      • 2015-09-14
      • 2013-02-07
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      相关资源
      最近更新 更多