运行C++的问题2013年使用CLION的代码

发布于 2025-01-27 09:04:20 字数 1660 浏览 3 评论 0原文

[我对C ++的经验很少,这是我十多年后第一次使用它]。

从2013年开始,我需要运行一些C ++代码,并且我遇到了问题。我在OSX Monterey(M1硅芯片)上使用CLION。如果我运行一个非常简单的脚本(下面的main.cc),我会发现错误

Undefined symbols for architecture arm64:
  "Hair::read(char const*, bool)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture arm64

是因为我试图运行的代码是用与我用来编译的代码编写的C ++版本不同的?还是与我正在使用的架构有关的问题?谢谢!

数据集和原始代码可用在这里

main.cpp

#include <opencv2/opencv.hpp>
#include <iostream>
#include <Hair.h>

using namespace cv;
using namespace std;

int main() {
    const char *path = "strands00001.data";
    Hair hair;
    hair.read(path, false);
    return 0;
}

这是我要调用的功能:

bool Hair::read(const char *filename, bool flip_strands /* = false */)
{
    bool ok = ends_with(filename, ".data") ?
        read_bin(filename) : read_asc(filename);

    if (!ok)
        return false;

    if (flip_strands) {
        int nstrands = strands.size();
        for (int i = 0; i < nstrands; i++)
            reverse(strands[i].begin(), strands[i].end());
    }

    // Look for a .xf file, and apply it if found
    xform xf;
    if (xf.read(xfname(filename)))
        apply_xf(xf);

    return true;
}

cmakelists.txt

cmake_minimum_required(VERSION 2.8)
project( OpenCVTest )
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( OpenCVTest main.cpp )
target_link_libraries( OpenCVTest  ${OpenCV_LIBS})

[I have very little experience with c++, and this is the first time I use it after more than 10 years].

I need to run some c++ code from 2013, and I am having issues doing so. I am using Clion on OSX Monterey (M1 Silicon chip). If I run a very simple script (main.cc below), I get the error

Undefined symbols for architecture arm64:
  "Hair::read(char const*, bool)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture arm64

Is this because the code I am trying to run was written in a different version of c++ than the one I am using to compile it? Or is it an issue related to the architecture I am using? Thanks!

The dataset and the original code is available here.

main.cpp

#include <opencv2/opencv.hpp>
#include <iostream>
#include <Hair.h>

using namespace cv;
using namespace std;

int main() {
    const char *path = "strands00001.data";
    Hair hair;
    hair.read(path, false);
    return 0;
}

Here is the function I'm trying to call:

bool Hair::read(const char *filename, bool flip_strands /* = false */)
{
    bool ok = ends_with(filename, ".data") ?
        read_bin(filename) : read_asc(filename);

    if (!ok)
        return false;

    if (flip_strands) {
        int nstrands = strands.size();
        for (int i = 0; i < nstrands; i++)
            reverse(strands[i].begin(), strands[i].end());
    }

    // Look for a .xf file, and apply it if found
    xform xf;
    if (xf.read(xfname(filename)))
        apply_xf(xf);

    return true;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project( OpenCVTest )
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( OpenCVTest main.cpp )
target_link_libraries( OpenCVTest  ${OpenCV_LIBS})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沦落红尘 2025-02-03 09:04:20

问题与架构或C ++版本无关。由于您的cmakelists.txt没有编译包含它的文件,因此找不到hair :: read的定义。您还需要告诉它除了main.cpp之外,还需要编译hiar.cpp

add_executable( OpenCVTest main.cpp Hair.cpp )

The problem has nothing to do with architecture or the version of C++. The definition of Hair::read couldn't be found because your CMakeLists.txt wasn't compiling the file that contained it. You need to tell it to compile Hair.cpp in addition to main.cpp, like this:

add_executable( OpenCVTest main.cpp Hair.cpp )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文