Linux shared library Loading function
Link from: http://www.faqs.org/docs/Linux-mini/C++-dlopen.html
//1. == main.cpp =============================================
// How to build?
// g++ -o main main.cpp -ldl
//=======================================================
#include <iostream>
#include <dlfcn.h>
int main() {
using std::cout;
using std::cerr;
cout << "C++ dlopen demo\n\n";
// open the library
cout << "Opening hello.so...\n";
void* handle = dlopen("./hello.so", RTLD_LAZY);
if (!handle) {
cerr << "Cannot open library: " << dlerror() << '\n';
return 1;
}
// load the symbol
cout << "Loading symbol hello...\n";
typedef void (*hello_t)();
hello_t hello = (hello_t) dlsym(handle, "hello");
if (!hello) {
cerr << "Cannot load symbol 'hello': " << dlerror() <<
'\n';
dlclose(handle);
return 1;
}
// use it to do the calculation
cout << "Calling hello...\n";
hello();
// close the library
cout << "Closing library...\n";
dlclose(handle);
}
// 2=====hello.cpp ========================================
// How to build?
// g++ -c -fPIC hello.cpp
// g++ -shared -o hello.so
-fPIC hello.o
//======================================================
#include <
Ïà¹ØÎĵµ£º
ÏëÒªÔÚÐéÄâ»úϵÄlinuxÓëwindows»¥Áª£¬×î¹Ø¼üµÄÖ»ÐèÒª3²½£º
1.Ò»¶¨ÒªÉèÖÃÐéÄâ»úµÄÍø¿¨ÎªÇŽÓģʽ£¬ÕÒ¸öÒ»¶¨²»ÄÜÍü¡£
2.ÉèÖÃlinuxϵÄipµØÖ·£¬ vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #ÍøÂçÃû³Æ
BOOTPROTO=static #¾²Ì¬»ñÈ¡ipµØÖ·
IPADD ......
¡¡I2C×ÜÏß¾ßÓнṹ¼òµ¥Ê¹Ó÷½±ãµÄÌص㡣±¾ÎÄÃèÊöÁËlinuxÏÂI2CÇý¶¯µÄ½á¹¹£¬²¢ÔÚ´Ë»ù´¡Éϸø³öÁËI2CÉ豸Çý¶¯ºÍÓ¦ÓõÄʵÏÖ¡£
¡¡¡¡1 ÒýÑÔ
¡¡¡¡I2C (Inter£Integrated Circuit)×ÜÏßÊÇÒ»ÖÖÓÉPHILIPS¹«Ë¾¿ª·¢µÄÁ½Ïßʽ´®ÐÐ×ÜÏߣ¬ÓÃÓÚÁ¬½Ó΢¿ØÖÆÆ÷¼°ÆäÍâΧÉ豸¡£I2C×ÜÏß×îÖ÷ÒªµÄÓŵãÊÇÆä¼òµ¥ÐÔºÍÓÐЧÐÔ¡£ÓÉÓÚ½Ó¿ÚÖ±½ÓÔÚ×é¼þÖ ......
ΪVMwareÌí¼ÓÐéÄâÓ²ÅÌ
VMware°²×°linuxµÄʱºòĬÈÏ·ÖÅäµÄ¿Õ¼äÊÇ4GB£¬¿ÉÄܻ᲻¹»£¬Õâ¸öʱºò¿ÉÒÔͨ¹ýÔö¼ÓÒ»¿éÐéÄâÓ²ÅÌ£¬½«/usr»òÆäËûÄÚÈÝ¿½±´¹ýÈ¥½â¾öÕâ¸öÎÊÌ⣺
´´½¨ÐéÄâÓ²ÅÌ
1¡¢¹Ø±ÕV ......
1 ÒýÑÔ
¡¡¡¡Linux²Ù×÷ϵͳÒò¾ßÓÐÔ´´úÂ빫¿ª¡¢±ãÓڲüõ¡¢Óй㷺µÄ´¦ÀíÆ÷Ö§³ÖµÈÓŵ㣬³ÉΪµ±Ç°Ç¶ÈëʽϵͳµÄÈÈÃÅÑ¡Ôñ¡£»ùÓÚI2C×ÜÏߵļüÅÌÀ©Õ¹É豸Ö÷ÒªÓÃÓÚÂú×ãǶÈëʽÉ豸ÖжԶఴ¼üµÄÐèÇó£¬Çý¶¯³ÌÐòÔÚϵͳÆô¶¯Ê±¶ÔÓ²¼þ½øÐгõʼ»¯¡£ÔÚϵͳÆô¶¯ºóʵÏÖÓ²¼þºÍÓ¦ÓóÌÐòÖ®¼äµÄÊý¾Ý½»»¥¡£Õë¶ÔS3C2410΢´¦ÀíÆ÷ºÍ¼üÅÌɨÃè¹ÜÀíÆ÷¼þ£¬ÉîÈ ......
1¡¢ÓÃGCC±àÒë
1.1¡¢´´½¨Ô´Îļþ
(main.c) C Ô´Îļþ - main.c
#include
#include “reciprocal.hpp”
int main (int argc, char **argv)
{
int i;
i = atoi (argv[1]);
printf (“The reciprocal of %d is %g\n”, i, reciprocal (i ......