[英]Creating a static library (.a) in C++ (Not for iOS)
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. 我试图在基于OpenCV的C#中为Unity3D创建C ++包装器,但首先,我试图在C ++中创建一个.a
静态库以制造包装器。 (I don't know if I'm doing right this). (我不知道我是否做对了)。
But my problem is on building a new static library with Xcode. 但是我的问题是使用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). (PD:我问这个问题是因为Google充满了“如何为iOS创建静态库,而这不是我想要的)。
I make: New -> Project -> Mac OSx Frameworks and Libraries -> Library (Static, STL framework). 我输入:新建->项目-> Mac OSx框架和库->库(静态,STL框架)。
Then I have my two files: .h
and .cp
然后我有两个文件: .h
和.cp
file1.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 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: 我按Cmd + B构建库,然后尝试创建一个新的命令行项目(用于测试),将我的libfile1.a和头文件file1.h导入到命令行项目中:
main.cpp 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) 架构x86_64的未定义符号:“ file1 :: prueba_funcion(unsigned char *,int,int)”,引用自:main.o中的_main ld:架构x86_64的符号未找到clang:错误:链接器命令失败,退出代码1(使用-v查看调用)
Do you know what I'm really doing bad? 你知道我在做什么吗?
Thank you in advance. 先感谢您。 Regards. 问候。
In file1.cpp
, instead of 在file1.cpp
,而不是
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. 否则,您不是在定义file1
的成员函数,而是定义一个恰好具有相同名称的自由函数。
Oh, and you'll have to #include "file1.h"
in file1.cpp
to make the class definition known there. 哦,您必须在file1.cpp
#include "file1.h"
才能使类定义在那里知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.