Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issue running c++ code from 2013 using Clion

[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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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})

>Solution :

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 )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading