运行C++的问题2013年使用CLION的代码
[我对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题与架构或C ++版本无关。由于您的
cmakelists.txt
没有编译包含它的文件,因此找不到hair :: read
的定义。您还需要告诉它除了main.cpp
之外,还需要编译hiar.cpp
。The problem has nothing to do with architecture or the version of C++. The definition of
Hair::read
couldn't be found because yourCMakeLists.txt
wasn't compiling the file that contained it. You need to tell it to compileHair.cpp
in addition tomain.cpp
, like this: