LinuxϱàÒ붯̬¿â£¬¾²Ì¬¿â£¬ÒÔ¼°µ÷ÓÃ
so_test.h£º
#include
#include
void test_a();
void test_b();
void test_c();
test_a.c£º
#include "so_test.h"
void test_a()
{
printf("this is in test_a...\n");
}
test_b.c£º
#include "so_test.h"
void test_b()
{
printf("this is in test_b...\n");
}
test_a.c£º
#include "so_test.h"
void test_c()
{
printf("this is in test_c...\n");
}
½«Õ⼸¸öÎļþ±àÒë³ÉÒ»¸ö¶¯Ì¬¿â£ºlibtest.so
$ gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so
test.c£º
#include "so_test.h"
int main()
{
test_a();
test_b();
test_c();
return 0;
}
l ½«test.cÓ붯̬¿âlibtest.soÁ´½ÓÉú³ÉÖ´ÐÐÎļþtest£º
$ gcc test.c -L. -ltest -o test
l ²âÊÔÊÇ·ñ¶¯Ì¬Á¬½Ó£¬Èç¹ûÁгölibtest.so£¬ÄÇôӦ¸ÃÊÇÁ¬½ÓÕý³£ÁË
$ ldd test
×îÖ÷ÒªµÄÊÇGCCÃüÁîÐеÄÒ»¸öÑ¡Ïî:
-shared
¸ÃÑ¡ÏîÖ¸¶¨Éú³É¶¯Ì¬Á¬½Ó¿â£¨ÈÃÁ¬½ÓÆ÷Éú³ÉTÀàÐ͵ĵ¼³ö·ûºÅ±í£¬ÓÐʱºòÒ²Éú³ÉÈõÁ¬½ÓWÀàÐ͵ĵ¼³ö·ûºÅ£©£¬²»ÓøñêÖ¾Íⲿ³ÌÐòÎÞ·¨Á¬½Ó¡£Ï൱ÓÚÒ»¸ö¿ÉÖ´ÐÐÎļþ
l
-fPIC£º±íʾ±àÒëΪλÖöÀÁ¢µÄ´úÂ룬²»ÓôËÑ¡ÏîµÄ»°±àÒëºóµÄ´úÂëÊÇλÖÃÏà¹ØµÄËùÒÔ¶¯Ì¬ÔØÈëʱÊÇͨ¹ý´úÂ뿽±´µÄ·½Ê½À´Âú×㲻ͬ½ø³ÌµÄÐèÒª£¬¶ø²»ÄÜ´ïµ½Õæ
Õý´úÂë¶Î¹²ÏíµÄÄ¿µÄ¡£
l -L.£º±íʾҪÁ¬½ÓµÄ¿âÔÚµ±Ç°Ä¿Â¼ÖÐ
l -ltest£º±àÒëÆ÷²éÕÒ¶¯Ì¬Á¬½Ó¿âʱÓÐÒþº¬µÄÃüÃû¹æÔò£¬¼´ÔÚ¸ø³öµÄÃû×ÖÇ°Ãæ¼ÓÉÏlib£¬ºóÃæ¼ÓÉÏ.soÀ´È·¶¨¿âµÄÃû³Æ
l LD_LIBRARY_PATH£ºÕâ¸ö»·¾³±äÁ¿Ö¸Ê¾¶¯Ì¬Á¬½ÓÆ÷¿ÉÒÔ×°Ôض¯Ì¬¿âµÄ·¾¶¡£
×îºó. Êä³ö¿âµÄ·¾¶£¬»òÕß¿½±´µ½/libĿ¼ÏÂ
export LD_LIBRARY_PATH=. // ÀÏÆÅ´óÈ˸æËß°³µÄ
Ö´ÐÐ ./test
¸ã¶¨
¾²Ì¬:
ÏȱàÒë³É.o
gcc -c test_a.c test_b.c test_c.c
È»ºóÓÃarÃüÁî
ar -r libtest.a test_a.o test_b.o test_c.o
Ïà¹ØÎĵµ£º
2009 Äê 4 ÔÂ 23 ÈÕ
±¾ÎÄÖÐÎÒÃÇÕë¶Ô Linux É϶àÏ̱߳à³ÌµÄÖ÷ÒªÌØÐÔ×ܽá³ö 5 Ìõ¾Ñ飬ÓÃÒÔ¸ÄÉÆ Linux ¶àÏ̱߳à³ÌµÄÏ°¹ßºÍ±ÜÃâÆäÖеĿª·¢ÏÝÚå¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇ´©²åһЩ Windows µÄ±à³ÌÓÃÀýÓÃÒÔ¶Ô±È Linux ÌØÐÔ£¬ÒÔ¼ÓÉî¶ÁÕßÓ¡Ïó¡£
±³¾°
Linux ƽ̨ÉϵĶàÏ̳߳ÌÐò¿ª·¢Ïà¶ÔÓ¦ÆäËûƽ̨£¨±ÈÈç Windows£©µÄ¶àÏß³Ì API ÓÐһЩϸ΢ ......
# uname -a
Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
(²é¿´µ±Ç°²Ù×÷ϵͳÄÚºËÐÅÏ¢)
# cat /etc/issue | grep Linux
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
(²é¿´µ±Ç°²Ù×÷ϵͳ·¢ÐаæÐÅÏ¢)
# cat /proc/cpuinfo | grep name | cut -f2 -d: ......
ÔÎļû£ºhttp://www.cppblog.com/flashboy/articles/47012.html
1¡¢ÐÞ¸ÄÓû§½ø³Ì¿É´ò¿ªÎļþÊýÏÞÖÆ
ÔÚLinuxƽ̨ÉÏ£¬ÎÞÂÛ±àд¿Í»§¶Ë³ÌÐò»¹ÊÇ·þÎñ¶Ë³ÌÐò£¬ÔÚ½øÐи߲¢·¢TCPÁ¬½Ó´¦Àíʱ£¬×î¸ßµÄ²¢·¢ÊýÁ¿¶¼ÒªÊܵ½ÏµÍ³¶ÔÓû§µ¥Ò»½ø³Ìͬʱ¿É´ò¿ªÎļþÊýÁ¿µÄÏÞÖÆ(ÕâÊÇÒòΪϵͳΪÿ¸öTCPÁ¬½Ó¶¼Òª´´½¨Ò»¸ösocket¾ä±ú£¬Ã¿¸ ......
LinuxµÄI/O»úÖƾÀúÁËһϼ¸¸ö½×¶ÎµÄÑݽø£º
1. ͬ²½×èÈûI/O: Óû§½ø³Ì½øÐÐI/O²Ù×÷£¬Ò»Ö±×èÈûµ½I/O²Ù×÷Íê³ÉΪֹ¡£
2. ͬ²½·Ç×èÈûI/O: Óû§³ÌÐò¿ÉÒÔͨ¹ýÉèÖÃÎļþÃèÊö·ûµÄÊôÐÔO_NONBLOCK£¬I/O²Ù×÷¿ÉÒÔÁ¢¼´·µ»Ø£¬µ«ÊDz¢²»±£Ö¤I/O²Ù×÷³É¹¦¡£
3. Ò첽ʼþ×èÈûI/O: Óû§½ø³Ì¿ÉÒÔ¶ÔI/Oʼþ½øÐÐ×èÈû£¬µ«ÊÇI/O²Ù×÷²¢²»×èÈû¡£Í¨¹ýse ......
Èý¸öÎļþ£¬Ò»¸öÍ·Îļþ£¬Ò»¸ö¶Á£¬Ò»¸öд£¬ÓÃͬһ¸ökeyÖµÉêÇë¹²ÏíÄÚ´æ¡£
//shm.h
#ifndef _SHM_COM_H
#define _SHM_COM_H 1
#define TEXT_SZ 2048
struct shared_use_at
{
int written_by_you;
char some_text[TEXT_SZ];
};
struct kts
{
int power;
int mod ......