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 <
Ïà¹ØÎĵµ£º
¡¡I2C×ÜÏß¾ßÓнṹ¼òµ¥Ê¹Ó÷½±ãµÄÌص㡣±¾ÎÄÃèÊöÁËlinuxÏÂI2CÇý¶¯µÄ½á¹¹£¬²¢ÔÚ´Ë»ù´¡Éϸø³öÁËI2CÉ豸Çý¶¯ºÍÓ¦ÓõÄʵÏÖ¡£
¡¡¡¡1 ÒýÑÔ
¡¡¡¡I2C (Inter£Integrated Circuit)×ÜÏßÊÇÒ»ÖÖÓÉPHILIPS¹«Ë¾¿ª·¢µÄÁ½Ïßʽ´®ÐÐ×ÜÏߣ¬ÓÃÓÚÁ¬½Ó΢¿ØÖÆÆ÷¼°ÆäÍâΧÉ豸¡£I2C×ÜÏß×îÖ÷ÒªµÄÓŵãÊÇÆä¼òµ¥ÐÔºÍÓÐЧÐÔ¡£ÓÉÓÚ½Ó¿ÚÖ±½ÓÔÚ×é¼þÖ ......
àÅ£¬ÕâÊǺÍƽͬѧµÄµãÌâ×÷ÎÄÁË£¬ºÇºÇ£¬Ëû·ÇÒªÁ˽âÎÒÊÇÔõô¿ª·¢Linux³ÌÐòµÄ£¬Ö÷ÒªÊÇÕâ¸ö¹¤×÷»·¾³ÊÇÈçºÎµÄ£¿
ÔʼÎÊÌâÈçÏ£º
ÎÊ£º
ÀÏʦ£¬¿ÉÒÔдһƪÎÄÕ½éÉÜÒ»ÏÂÈçºÎʹÓÃvim´î½¨ºÃÓõÄlinux¿ª·¢»·¾³Â𣿣¨±ÈÈçvimÈçºÎÉèÖÿì½Ý¼ü¿ÉÒÔ×öµ½Ò»¼ü±àÒëºÍÔËÐУ¬³£ÓõIJå¼þÈçºÎ°²×°µÈ£©
´ð£º
ÎÒ²»»áÓÃvim£¬Ò²´Ó²»Óá£
ÎÊ£º
ÌýË ......
¿ì½Ý¼ü£ºctrl+c ctrl+d
1.shell ·ÖΪͼÐÎshellºÍÃüÁîshell ÃüÁîshell·ÖΪbashºÍcsh£¬Çл»µ½cshÓÃcsh£¬exit·µ»Øbash
2.telnet Ô¶³ÌµÇ½unix
telnet 192.168.0.25
login£ºhz0904 Óû§Ãû
password£ºsd0904 ÃÜÂë¹æÔò£º6-8¸ö×Ö·û£¬ÖÁÉÙ°üº¬×ÖĸÒÔ¼°1¸öÊý×Ö£¬²»ÄÜÓëµÇ¼ÃûÏàͬ
3.passwd£º ÐÞ¸ÄÃÜÂë>ÊäÈëÏÖÓпÚÁî>ÊäÈë ......
±¾ÎÄÏêϸ·ÖÎöÁËLinux×ÀÃæ²Ù×÷ϵͳµÄÆô¶¯¹ý³Ì£¬Éæ¼°µ½BIOSϵͳ¡¢LILO ºÍGRUBÒýµ¼×°ÔسÌÐò£¬ÒÔ¼°bootsect¡¢setup¡¢vmlinuxµÈÓ³ÏñÎļþ£¬²¢½áºÏÒýµ¼¡¢Æô¶¯ÔÀíºÍ¾ßÌåµÄ´úÂëʵÏÖ»úÖÆÓÉdzÈëÉîµØ½øÐÐÁË·ÖÎö¡£
³õѧÕ߸սӴ¥Linux×ÀÃæϵͳ»á¸Ð¾õϵͳÆô¶¯ËٶȽÏÂý£¬ÄÇô£¬ÎªÊ²Ã´ËüµÄÆô¶¯ËÙ¶ÈÂýÄØ?±¾ÎľÍ×ÀÃæϵ ......
²é¿´ÎļþÄÚÈݵÄÌØÊâ·½·¨
¡¡¡¡ÏàÐÅ×î»ù±¾µÄcatºÍless,moreÄãÒѾºÜÊìϤÁË£¬Èç¹ûÓÐÌØÊâµÄÒªÇóÄØ£º
1. Èç¹ûÄãÖ»Ïë¿´ÎļþµÄÇ°5ÐУ¬¿ÉÒÔʹÓÃheadÃüÁÈ磺
head -5 /etc/passwd
2. Èç¹ûÄãÏë²é¿´ÎļþµÄºó10ÐУ¬¿ÉÒÔʹÓÃtailÃüÁÈ磺
tail -10 /etc/passwd
tail -f /var/log/messages
²ÎÊý-fʹtail²»Í£µØÈ¥¶Á×îеÄÄÚÈÝ£ ......