分类:
2008-08-09 23:40:06
./dll.so: undefined symbol: _ZN1AC1EiSegmentation fault |
All: main dll main: static dll main.cpp g++ -ldl -o main main.cpp dll: dll.cpp static g++ -shared -L. -lA -o dll.so dll.cpp static: A.cpp g++ -c A.cpp ar rc libA.a A.o |
class A { public: A(int a); }; |
#include "A.h" #include <iostream> using namespace std; A::A(int a) { cout << "in A.A() " << a << endl; } |
#include <string> #include <iostream> #include "A.h" using namespace std; template<int F> class dll { public: A *a; public: dll(int id) { a = new A(id); cout << id << " " << F << endl; } }; template class dll<4>; extern "C" { void maker(int id) { new dll<4>(id); } } |
#include <dlfcn.h> #include <iostream> using namespace std; int main(int argc, char* argv[]) { char *p; void *lib; lib = dlopen("./dll.so", RTLD_LAZY); if (lib == NULL) { cout << "NULL" << endl; p = dlerror(); cout << p << endl; } else cout << std::hex << lib << endl; typedef void (*FUNC) (int); FUNC sym = (FUNC) dlsym(lib, "maker"); sym(3); return 0; } |