-3
我已通过多个堆栈溢出职位消失,试图执行下面的例子与C++对象类 我具有以下的代码使用的dlopen类对象。未定义参考误差时用C++
1)文件hello.cc
#include <stdio.h>
#include "hello.h"
A::A() {
init1();
}
void A::init1() {
printf("\n init ");
}
2)文件hello.h
#include <iostream>
class A {
public:
A();
void init1();
inline void fun() { cout << "\n Inside fun"; }
};
extern "C" A* createA() {
return new A;
}
}
3)文件的main.cpp
#include<iostream>
#include<dlfcn.h>
#include "hello.h"
using namespace std;
int main() {
void *handle;
handle = dlopen("./libhello.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle) {
cout << "The error is " << dlerror();
}
return 0 ;
}
我使用以下步骤创建共享库
1) g++ -g -fPIC -c hello.cc
2) g++ -g -shared -o libhello.so hello.o
3) g++ -g -o myprog main.cpp -
main.cpp:(.text+0x18): undefined reference to `A::A()' . The function createA in hello.h is declared so the same can be used to dlsym
- 我无法使用createA在对dlsym
- 我越来越未定义的引用`A :: A(),即使我不使用的dlsym
- 我的查询是什么是正确的是使用C++类对象的dlsym
- 从dlopen的风云人物,我不能够推断出是RTLD_LAZY RTLD_GLOBAL RTLD_NOW标志
C不能处理的类。 –
这是C++代码 – TechEnthusiast
'extern“C”A * createA()'明确表示它不是。 –