当前位置: 技术问答>linux和unix
关于创建共享库(.so)的问题,高手帮忙
来源: 互联网 发布时间:2015-03-02
本文导语: 以下程序通过 g++ -shared prime.cc -o prime.so 来生成一个共享库prime.so //---------------prime.cc--------------- #include #include bool check_prime(unsigned long n) { unsigned long upperbound = (unsigned long) sqrt((double)n); unsigned long i; fo...
以下程序通过 g++ -shared prime.cc -o prime.so
来生成一个共享库prime.so
//---------------prime.cc---------------
#include
#include
bool check_prime(unsigned long n)
{
unsigned long upperbound = (unsigned long) sqrt((double)n);
unsigned long i;
for (i = 2; i upperbound);
}
//--------------------------------------
但是在使用共享库函数的时候遇到了问题:
//-------------ex.cc--------------------
....
bool (*check_prime)(unsigned long n);
....
void *handle = dlopen("prime.so", RTLD_LAZY);
check_prime = (bool (*)(unsigned long)) dlsym(handle, "check_prime");
error = dlerror();
if (error != NULL)
{
cerr
来生成一个共享库prime.so
//---------------prime.cc---------------
#include
#include
bool check_prime(unsigned long n)
{
unsigned long upperbound = (unsigned long) sqrt((double)n);
unsigned long i;
for (i = 2; i upperbound);
}
//--------------------------------------
但是在使用共享库函数的时候遇到了问题:
//-------------ex.cc--------------------
....
bool (*check_prime)(unsigned long n);
....
void *handle = dlopen("prime.so", RTLD_LAZY);
check_prime = (bool (*)(unsigned long)) dlsym(handle, "check_prime");
error = dlerror();
if (error != NULL)
{
cerr