0

I'm trying to make a C++ wrapper for Unity3D in C# based in OpenCV but first of all I'm trying to make a .a static library in C++ in order to make the wrapper. (I don't know if I'm doing right this).

But my problem is on building a new static library with Xcode.

(PD: I'm asking this question because Google is full of "how to make a static library for iOS and that's not what I'm looking for).

I make: New -> Project -> Mac OSx Frameworks and Libraries -> Library (Static, STL framework).

Then I have my two files: .h and .cp

file1.cp:

#include <iostream>
#include "/Users/rafaelruizmunoz/Documents/OpenCV_projects/OpenCVDebug/OpenCVDebug/mylib.h"

using namespace std;
using namespace cv;

float* prueba_funcion(unsigned char* a, int cols, int rows) {
    Mat mat = Mat(rows, cols, CV_8U, a);
    float* o = giveMeMiddlePoints(mat); // this function gets called from the include
    return o;

}

file1.h

#ifndef file1_
#define file1_

/* The classes below are exported */
#pragma GCC visibility push(default)

class file1
{
    public:
        float* prueba_funcion(unsigned char *, int, int);
};

#pragma GCC visibility pop
#endif

I press Cmd + B to build the library and I try to make a new Command Line project (for testing), importing my libfile1.a and my header file1.h in the Command Line project:

main.cpp

#include <iostream>
#include "/Users/rafaelruizmunoz/Desktop/file1.h"

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";

    unsigned char data[9] = {3,3,3,1,9,1,2,2,2};

    file1 f;
    float* q = f.prueba_funcion(data, 3, 3);
    cout << endl << q;

    return 0;
}

but I get linker errors (it's like if my static library was compiled in a wrong way):

Undefined symbols for architecture x86_64: "file1::prueba_funcion(unsigned char*, int, int)", referenced from: _main 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)

Do you know what I'm really doing bad?

Thank you in advance. Regards.

1 Answer 1

1

In file1.cpp, instead of

float* prueba_funcion(unsigned char* a, int cols, int rows)

write

float* file1::prueba_funcion(unsigned char* a, int cols, int rows)

Otherwise you're not defining a member function of file1 but a free function that just happens to have the same name.

Oh, and you'll have to #include "file1.h" in file1.cpp to make the class definition known there.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much... I'm really newbie at some points in C++ (I just make Command Tool :D )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.