1.ÒýÑÔ
±¾ÎĵÄд×÷Ä¿µÄ²¢²»ÔÚÓÚÌṩC/C++³ÌÐòÔ±ÇóÖ°ÃæÊÔÖ¸µ¼£¬¶øÖ¼ÔÚ´Ó¼¼ÊõÉÏ·ÖÎöÃæÊÔÌâµÄÄÚº¡£ÎÄÖеĴó¶àÊýÃæÊÔÌâÀ´×Ô¸÷´óÂÛ̳£¬²¿·ÖÊÔÌâ½â´ðÒ²²Î¿¼ÁËÍøÓѵÄÒâ¼û¡£
Ðí¶àÃæÊÔÌâ¿´ËƼòµ¥£¬È´ÐèÒªÉîºñµÄ»ù±¾¹¦²ÅÄܸø³öÍêÃÀµÄ½â´ð¡£ÆóÒµÒªÇóÃæÊÔÕßдһ¸ö×î¼òµ¥µÄstrcpyº¯Êý¶¼¿É¿´³öÃæÊÔÕßÔÚ¼¼ÊõÉϾ¿¾¹´ïµ½ÁËÔõÑùµÄ³Ì
¶È£¬ÎÒÃÇÄÜÕæÕýдºÃÒ»¸östrcpyº¯ÊýÂð£¿ÎÒÃǶ¼¾õµÃ×Ô¼ºÄÜ£¬¿ÉÊÇÎÒÃÇд³öµÄstrcpyºÜ¿ÉÄÜÖ»ÄÜÄõ½10·ÖÖеÄ2·Ö¡£¶ÁÕß¿É´Ó±¾ÎÄ¿´µ½strcpy
º¯Êý´Ó2·Öµ½10·Ö½â´ðµÄÀý×Ó£¬¿´¿´×Ô¼ºÊôÓÚʲôÑùµÄ²ã´Î¡£´ËÍ⣬»¹ÓÐһЩÃæÊÔÌ⿼²éÃæÊÔÕßÃô½ÝµÄ˼άÄÜÁ¦¡£
·ÖÎöÕâЩÃæÊÔÌ⣬±¾Éí°üº¬ºÜÇ¿µÄȤζÐÔ£»¶ø×÷ΪһÃûÑз¢ÈËÔ±£¬Í¨¹ý¶ÔÕâЩÃæÊÔÌâµÄÉîÈëÆÊÎöÔò¿É½øÒ»²½ÔöÇ¿×ÔÉíµÄÄÚ¹¦¡£
2.ÕÒ´íÌâ
ÊÔÌâ1£º
void test1()
{
char string[10];
char* str1 = "0123456789";
strcpy( string, str1 );
}
ÊÔÌâ2£º
void test2()
{
char string[10], str1[10];
int i;
for(i=0; i<10; i++)
{
str1[i] = 'a'£»
}
strcpy( string, str1 )£»
}
ÊÔÌâ3£º
void ......
1.ÒýÑÔ
±¾ÎĵÄд×÷Ä¿µÄ²¢²»ÔÚÓÚÌṩC/C++³ÌÐòÔ±ÇóÖ°ÃæÊÔÖ¸µ¼£¬¶øÖ¼ÔÚ´Ó¼¼ÊõÉÏ·ÖÎöÃæÊÔÌâµÄÄÚº¡£ÎÄÖеĴó¶àÊýÃæÊÔÌâÀ´×Ô¸÷´óÂÛ̳£¬²¿·ÖÊÔÌâ½â´ðÒ²²Î¿¼ÁËÍøÓѵÄÒâ¼û¡£
Ðí¶àÃæÊÔÌâ¿´ËƼòµ¥£¬È´ÐèÒªÉîºñµÄ»ù±¾¹¦²ÅÄܸø³öÍêÃÀµÄ½â´ð¡£ÆóÒµÒªÇóÃæÊÔÕßдһ¸ö×î¼òµ¥µÄstrcpyº¯Êý¶¼¿É¿´³öÃæÊÔÕßÔÚ¼¼ÊõÉϾ¿¾¹´ïµ½ÁËÔõÑùµÄ³Ì
¶È£¬ÎÒÃÇÄÜÕæÕýдºÃÒ»¸östrcpyº¯ÊýÂð£¿ÎÒÃǶ¼¾õµÃ×Ô¼ºÄÜ£¬¿ÉÊÇÎÒÃÇд³öµÄstrcpyºÜ¿ÉÄÜÖ»ÄÜÄõ½10·ÖÖеÄ2·Ö¡£¶ÁÕß¿É´Ó±¾ÎÄ¿´µ½strcpy
º¯Êý´Ó2·Öµ½10·Ö½â´ðµÄÀý×Ó£¬¿´¿´×Ô¼ºÊôÓÚʲôÑùµÄ²ã´Î¡£´ËÍ⣬»¹ÓÐһЩÃæÊÔÌ⿼²éÃæÊÔÕßÃô½ÝµÄ˼άÄÜÁ¦¡£
·ÖÎöÕâЩÃæÊÔÌ⣬±¾Éí°üº¬ºÜÇ¿µÄȤζÐÔ£»¶ø×÷ΪһÃûÑз¢ÈËÔ±£¬Í¨¹ý¶ÔÕâЩÃæÊÔÌâµÄÉîÈëÆÊÎöÔò¿É½øÒ»²½ÔöÇ¿×ÔÉíµÄÄÚ¹¦¡£
2.ÕÒ´íÌâ
ÊÔÌâ1£º
void test1()
{
char string[10];
char* str1 = "0123456789";
strcpy( string, str1 );
}
ÊÔÌâ2£º
void test2()
{
char string[10], str1[10];
int i;
for(i=0; i<10; i++)
{
str1[i] = 'a'£»
}
strcpy( string, str1 )£»
}
ÊÔÌâ3£º
void ......
µ±Òª½¨Á¢Ï̵߳Èʱ£¬ÔÚLinuxÏ£¬ÓÃÎı¾±à¼£¬ÔÚ¼üÈë“g++ -lpthread”.......“¿ÉÒÔ°Ñ¿âpthreadÒýÈ딣¬±àÒëͨ¹ý¡£ÏÖÔÚÏëÓÃeclipse£¬µ«ÊÇĬÈÏÇé¿öÏ£¬ÒýÈë²»ÁËpthread¡£»á±¨“undefined reference to phread_create”µÈ´íÎó¡£
½â¾ö·½·¨£º¿ÉÒÔÔÚprojectÖкõ½properties
ÔÚÀïÃæµÄ“Tool Settings”£»ÀïÕÒµ½“GCC C++ Linker”¡£
ÔÚÆäÖеēLibraries”ÉÏÌí¼Ó“pthread”£¬°´“ok”£¬ÖØбàÒë¾Í¿ÉÒÔÁË¡£ ......
µ±Òª½¨Á¢Ï̵߳Èʱ£¬ÔÚLinuxÏ£¬ÓÃÎı¾±à¼£¬ÔÚ¼üÈë“g++ -lpthread”.......“¿ÉÒÔ°Ñ¿âpthreadÒýÈ딣¬±àÒëͨ¹ý¡£ÏÖÔÚÏëÓÃeclipse£¬µ«ÊÇĬÈÏÇé¿öÏ£¬ÒýÈë²»ÁËpthread¡£»á±¨“undefined reference to phread_create”µÈ´íÎó¡£
½â¾ö·½·¨£º¿ÉÒÔÔÚprojectÖкõ½properties
ÔÚÀïÃæµÄ“Tool Settings”£»ÀïÕÒµ½“GCC C++ Linker”¡£
ÔÚÆäÖеēLibraries”ÉÏÌí¼Ó“pthread”£¬°´“ok”£¬ÖØбàÒë¾Í¿ÉÒÔÁË¡£ ......
µ±Òª½¨Á¢Ï̵߳Èʱ£¬ÔÚLinuxÏ£¬ÓÃÎı¾±à¼£¬ÔÚ¼üÈë“g++ -lpthread”.......“¿ÉÒÔ°Ñ¿âpthreadÒýÈ딣¬±àÒëͨ¹ý¡£ÏÖÔÚÏëÓÃeclipse£¬µ«ÊÇĬÈÏÇé¿öÏ£¬ÒýÈë²»ÁËpthread¡£»á±¨“undefined reference to phread_create”µÈ´íÎó¡£
½â¾ö·½·¨£º¿ÉÒÔÔÚprojectÖкõ½properties
ÔÚÀïÃæµÄ“Tool Settings”£»ÀïÕÒµ½“GCC C++ Linker”¡£
ÔÚÆäÖеēLibraries”ÉÏÌí¼Ó“pthread”£¬°´“ok”£¬ÖØбàÒë¾Í¿ÉÒÔÁË¡£ ......
ת×Ô£ºhttp://blog.csdn.net/xiaocai0001/archive/2006/04/14/662921.aspx
static¹Ø¼ü×ÖÊÇC, C++Öж¼´æÔڵĹؼü×Ö, ËüÖ÷ÒªÓÐÈýÖÖʹÓ÷½Ê½, ÆäÖÐÇ°Á½ÖÖÔÚC/C++ÓïÑÔÖÐʹÓÃ, µÚÈýÖÖÖ»ÔÚC++ÖÐʹÓÃ(C,C++ÖоßÌåϸ΢²Ù×÷²»¾¡Ïàͬ, ±¾ÎÄÒÔC++Ϊ׼).
(1)¾Ö²¿¾²Ì¬±äÁ¿
(2)Íⲿ¾²Ì¬±äÁ¿/º¯Êý
(3)¾²Ì¬Êý¾Ý³ÉÔ±/³ÉÔ±º¯Êý
ÏÂÃæ¾ÍÕâÈýÖÖʹÓ÷½Ê½¼°×¢ÒâÊÂÏî·Ö±ð˵Ã÷
Ò»¡¢¾Ö²¿¾²Ì¬±äÁ¿
ÔÚC/C++ÖÐ, ¾Ö²¿±äÁ¿°´ÕÕ´æ´¢ÐÎʽ¿É·ÖΪÈýÖÖauto, static, register
(<CÓïÑÔ³ÌÐòÉè¼Æ(µÚ¶þ°æ)>Ì·ºÆÇ¿, µÚ174-175Ò³)
ÓëautoÀàÐÍ(ÆÕͨ)¾Ö²¿±äÁ¿Ïà±È, static¾Ö²¿±äÁ¿ÓÐÈýµã²»Í¬
1. ´æ´¢¿Õ¼ä·ÖÅ䲻ͬ
autoÀàÐÍ·ÖÅäÔÚÕ»ÉÏ, ÊôÓÚ¶¯Ì¬´æ´¢Àà±ð, Õ¼¶¯Ì¬´æ´¢Çø¿Õ¼ä, º¯Êýµ÷ÓýáÊøºó×Ô¶¯ÊÍ·Å, ¶østatic·ÖÅäÔÚ¾²Ì¬´æ´¢Çø, ÔÚ³ÌÐòÕû¸öÔËÐÐÆڼ䶼²»ÊÍ·Å. Á½ÕßÖ®¼äµÄ×÷ÓÃÓòÏàͬ, µ«Éú´æÆÚ²»Í¬.
2. static¾Ö²¿±äÁ¿ÔÚËù´¦Ä£¿éÔÚ³õ´ÎÔËÐÐʱ½øÐгõʼ»¯¹¤×÷, ÇÒÖ»²Ù×÷Ò»´Î
3. ¶ÔÓÚ¾Ö²¿¾²Ì¬±äÁ¿, Èç¹û²»¸³³õÖµ, ±àÒëÆÚ»á×Ô¶¯¸³³õÖµ0»ò¿Õ×Ö·û, ¶øautoÀàÐ͵ijõÖµÊDz»È·¶¨µÄ. (¶ÔÓÚC++ÖеÄclass¶ÔÏóÀýÍâ, classµÄ¶ÔÏóʵÀýÈç¹û²»³õʼ»¯, Ôò»á×Ô¶¯µ÷ÓÃĬÈϹ¹Ô캯Êý, ²»¹ÜÊÇ·ñÊÇstaticÀàÐÍ)
Ìصã: static¾Ö²¿±äÁ¿ ......
ת×Ô£ºhttp://blog.csdn.net/xiaocai0001/archive/2006/04/14/662921.aspx
static¹Ø¼ü×ÖÊÇC, C++Öж¼´æÔڵĹؼü×Ö, ËüÖ÷ÒªÓÐÈýÖÖʹÓ÷½Ê½, ÆäÖÐÇ°Á½ÖÖÔÚC/C++ÓïÑÔÖÐʹÓÃ, µÚÈýÖÖÖ»ÔÚC++ÖÐʹÓÃ(C,C++ÖоßÌåϸ΢²Ù×÷²»¾¡Ïàͬ, ±¾ÎÄÒÔC++Ϊ׼).
(1)¾Ö²¿¾²Ì¬±äÁ¿
(2)Íⲿ¾²Ì¬±äÁ¿/º¯Êý
(3)¾²Ì¬Êý¾Ý³ÉÔ±/³ÉÔ±º¯Êý
ÏÂÃæ¾ÍÕâÈýÖÖʹÓ÷½Ê½¼°×¢ÒâÊÂÏî·Ö±ð˵Ã÷
Ò»¡¢¾Ö²¿¾²Ì¬±äÁ¿
ÔÚC/C++ÖÐ, ¾Ö²¿±äÁ¿°´ÕÕ´æ´¢ÐÎʽ¿É·ÖΪÈýÖÖauto, static, register
(<CÓïÑÔ³ÌÐòÉè¼Æ(µÚ¶þ°æ)>Ì·ºÆÇ¿, µÚ174-175Ò³)
ÓëautoÀàÐÍ(ÆÕͨ)¾Ö²¿±äÁ¿Ïà±È, static¾Ö²¿±äÁ¿ÓÐÈýµã²»Í¬
1. ´æ´¢¿Õ¼ä·ÖÅ䲻ͬ
autoÀàÐÍ·ÖÅäÔÚÕ»ÉÏ, ÊôÓÚ¶¯Ì¬´æ´¢Àà±ð, Õ¼¶¯Ì¬´æ´¢Çø¿Õ¼ä, º¯Êýµ÷ÓýáÊøºó×Ô¶¯ÊÍ·Å, ¶østatic·ÖÅäÔÚ¾²Ì¬´æ´¢Çø, ÔÚ³ÌÐòÕû¸öÔËÐÐÆڼ䶼²»ÊÍ·Å. Á½ÕßÖ®¼äµÄ×÷ÓÃÓòÏàͬ, µ«Éú´æÆÚ²»Í¬.
2. static¾Ö²¿±äÁ¿ÔÚËù´¦Ä£¿éÔÚ³õ´ÎÔËÐÐʱ½øÐгõʼ»¯¹¤×÷, ÇÒÖ»²Ù×÷Ò»´Î
3. ¶ÔÓÚ¾Ö²¿¾²Ì¬±äÁ¿, Èç¹û²»¸³³õÖµ, ±àÒëÆÚ»á×Ô¶¯¸³³õÖµ0»ò¿Õ×Ö·û, ¶øautoÀàÐ͵ijõÖµÊDz»È·¶¨µÄ. (¶ÔÓÚC++ÖеÄclass¶ÔÏóÀýÍâ, classµÄ¶ÔÏóʵÀýÈç¹û²»³õʼ»¯, Ôò»á×Ô¶¯µ÷ÓÃĬÈϹ¹Ô캯Êý, ²»¹ÜÊÇ·ñÊÇstaticÀàÐÍ)
Ìصã: static¾Ö²¿±äÁ¿ ......
GCC ÖÐÎÄÊÖ²á
¡¡¡¡http://www.nbfan.com/forum/dispbbs....&ID=1433&page=1
¡¡¡¡GNU make Ö¸ÄÏ
¡¡¡¡http://www.linuxsir.org/bbs/showthr...&threadid=40431
¡¡¡¡autoconf-2.57ÊÖ²á(Ó¢ÎÄ)
¡¡¡¡http://www.gnu.org/software/autocon...toconf_toc.html
¡¡¡¡Autoconf-2.13ÊÖ²á
¡¡¡¡http://www.linuxforum.net/books/autoconf.html
¡¡¡¡Ê¹Óà automake
¡¡¡¡http://263.aka.org.cn/Lectures/002/...-2.1.4/230.html
¡¡¡¡Ê¹ÓÃCVS½øÐа汾¹ÜÀí
¡¡¡¡http://www.linuxforum.net/books/cvsintro.html & ......
GCC ÖÐÎÄÊÖ²á
¡¡¡¡http://www.nbfan.com/forum/dispbbs....&ID=1433&page=1
¡¡¡¡GNU make Ö¸ÄÏ
¡¡¡¡http://www.linuxsir.org/bbs/showthr...&threadid=40431
¡¡¡¡autoconf-2.57ÊÖ²á(Ó¢ÎÄ)
¡¡¡¡http://www.gnu.org/software/autocon...toconf_toc.html
¡¡¡¡Autoconf-2.13ÊÖ²á
¡¡¡¡http://www.linuxforum.net/books/autoconf.html
¡¡¡¡Ê¹Óà automake
¡¡¡¡http://263.aka.org.cn/Lectures/002/...-2.1.4/230.html
¡¡¡¡Ê¹ÓÃCVS½øÐа汾¹ÜÀí
¡¡¡¡http://www.linuxforum.net/books/cvsintro.html & ......
GCC ÖÐÎÄÊÖ²á
¡¡¡¡http://www.nbfan.com/forum/dispbbs....&ID=1433&page=1
¡¡¡¡GNU make Ö¸ÄÏ
¡¡¡¡http://www.linuxsir.org/bbs/showthr...&threadid=40431
¡¡¡¡autoconf-2.57ÊÖ²á(Ó¢ÎÄ)
¡¡¡¡http://www.gnu.org/software/autocon...toconf_toc.html
¡¡¡¡Autoconf-2.13ÊÖ²á
¡¡¡¡http://www.linuxforum.net/books/autoconf.html
¡¡¡¡Ê¹Óà automake
¡¡¡¡http://263.aka.org.cn/Lectures/002/...-2.1.4/230.html
¡¡¡¡Ê¹ÓÃCVS½øÐа汾¹ÜÀí
¡¡¡¡http://www.linuxforum.net/books/cvsintro.html & ......
http://www.gamedev.net/reference/programming/features/orgfiles/page2.asp
ͨ¹ýËĸöpitfall½²½âÍ·ÎļþµÄÓÉÀ´ºÍºÃ´¦£¬ÒÔ¼°Ê¹ÓÃÍ·Îļþ¶¨Òåinline func and template.
Remember that, as far as the compiler is concerned, there is absolutely no difference between a header file and a source file.
The key idea is that headers contain the interface, and the source files contain the actual implementation.This means that one source file uses another source file via the second source file's header.
main body
By now you're probably convinced that there are benefits to splitting up your project into several smaller files. So, how would you go about it? Although some of the decisions you make will be reasonably arbitrary, there are some basic rules that you should follow to ensure that it all works.
Firstly, look at how you would split your code into sections. Often this is by splitting it into separate subsystems, or 'modules', such as sound, music, graphics, file handling, etc. Create new files wi ......
http://www.gamedev.net/reference/programming/features/orgfiles/page2.asp
ͨ¹ýËĸöpitfall½²½âÍ·ÎļþµÄÓÉÀ´ºÍºÃ´¦£¬ÒÔ¼°Ê¹ÓÃÍ·Îļþ¶¨Òåinline func and template.
Remember that, as far as the compiler is concerned, there is absolutely no difference between a header file and a source file.
The key idea is that headers contain the interface, and the source files contain the actual implementation.This means that one source file uses another source file via the second source file's header.
main body
By now you're probably convinced that there are benefits to splitting up your project into several smaller files. So, how would you go about it? Although some of the decisions you make will be reasonably arbitrary, there are some basic rules that you should follow to ensure that it all works.
Firstly, look at how you would split your code into sections. Often this is by splitting it into separate subsystems, or 'modules', such as sound, music, graphics, file handling, etc. Create new files wi ......
1.gcc°üº¬µÄc/c++±àÒëÆ÷
gcc,ccÓëc++,g++
gccºÍccÊÇÒ»ÑùµÄ£¬c++ºÍg++ÊÇÒ»ÑùµÄ¡£Ò»°ãc³ÌÐò¾ÍÓÃgcc±àÒ룬c++³ÌÐò¾ÍÓÃg++±àÒë¡£
2.gccµÄ»ù±¾Ó÷¨
gcc test.c£ºÈç¹ûûÓÐÖ¸¶¨Êä³öµÄÎļþ£¬Ä¬ÈϽ«±àÒë³öÒ»¸öÃûΪa.outµÄ³ÌÐò
gcc test.c -o test£º-o²ÎÊýÓÃÀ´Ö¸¶¨Éú³ÉÄ¿±ê³ÌÐòµÄÃû×Ö£¬ÕâÑù½«±àÒë³öÒ»¸öÃûΪtestµÄ³ÌÐò¡£
3.Ϊʲô»á³öÏÖundefined reference to 'xxxxx'´íÎó£¿
Ê×ÏÈÕâÊÇÁ´½Ó´íÎ󣬲»ÊDZàÒë´íÎó£¬Ò²¾ÍÊÇ˵Èç¹ûÖ»ÓÐÕâ¸ö´íÎó£¬ËµÃ÷ÄãµÄ³ÌÐòÔ´Âë±¾ÉíûÓÐÎÊÌ⣬ÊÇÄãÓñàÒëÆ÷±àÒëʱ²ÎÊýÓõò»¶Ô£¬ÄãûÓÐÖ¸¶¨Á´½Ó³ÌÐòÒªÓõ½µÃ¿â£¬±ÈÈçÄãµÄ³ÌÐòÀïÓõ½ÁËһЩÊýѧº¯Êý£¬ÄÇôÄã¾ÍÒªÔÚ±àÒë²ÎÊýÀïÖ¸¶¨³ÌÐòÒªÁ´½ÓÊýѧ¿â£¬·½·¨ÊÇÔÚ±àÒëÃüÁîÐÐÀï¼ÓÈë-lm¡£
4.-l²ÎÊýºÍ-L²ÎÊý
-l²ÎÊý¾ÍÊÇÓÃÀ´Ö¸¶¨³ÌÐòÒªÁ´½ÓµÄ¿â£¬-l²ÎÊý½ô½ÓמÍÊÇ¿âÃû£¬ÄÇô¿âÃû¸úÕæÕýµÄ¿âÎļþÃûÓÐʲô¹ØϵÄØ£¿¾ÍÄÃÊýѧ¿âÀ´Ëµ£¬ËûµÄ¿âÃûÊÇm£¬ËûµÄ¿âÎļþÃûÊÇlibm.so£¬ºÜÈÝÒ׿´³ö£¬°Ñ¿âÎļþÃûµÄÍ·libºÍβ.soÈ¥µô¾ÍÊÇ¿âÃûÁË¡£
ºÃÁËÏÖÔÚÎÒÃÇÖªµÀÔõôµÃµ½¿âÃûÁË£¬±ÈÈçÎÒÃÇ×ÔÒÑÒªÓõ½Ò»¸öµÚÈý·½ÌṩµÄ¿âÃû×Ö½Ðlibtest.so£¬ÄÇôÎÒÃÇÖ»Òª°Ñlibtest.so¿½±´µ½/usr/libÀ±àÒëʱ¼ÓÉÏ-ltest²ÎÊý£¬ÎÒÃǾÍÄÜÓÃÉÏlibtest.so¿âÁË£ ......
1.gcc°üº¬µÄc/c++±àÒëÆ÷
gcc,ccÓëc++,g++
gccºÍccÊÇÒ»ÑùµÄ£¬c++ºÍg++ÊÇÒ»ÑùµÄ¡£Ò»°ãc³ÌÐò¾ÍÓÃgcc±àÒ룬c++³ÌÐò¾ÍÓÃg++±àÒë¡£
2.gccµÄ»ù±¾Ó÷¨
gcc test.c£ºÈç¹ûûÓÐÖ¸¶¨Êä³öµÄÎļþ£¬Ä¬ÈϽ«±àÒë³öÒ»¸öÃûΪa.outµÄ³ÌÐò
gcc test.c -o test£º-o²ÎÊýÓÃÀ´Ö¸¶¨Éú³ÉÄ¿±ê³ÌÐòµÄÃû×Ö£¬ÕâÑù½«±àÒë³öÒ»¸öÃûΪtestµÄ³ÌÐò¡£
3.Ϊʲô»á³öÏÖundefined reference to 'xxxxx'´íÎó£¿
Ê×ÏÈÕâÊÇÁ´½Ó´íÎ󣬲»ÊDZàÒë´íÎó£¬Ò²¾ÍÊÇ˵Èç¹ûÖ»ÓÐÕâ¸ö´íÎó£¬ËµÃ÷ÄãµÄ³ÌÐòÔ´Âë±¾ÉíûÓÐÎÊÌ⣬ÊÇÄãÓñàÒëÆ÷±àÒëʱ²ÎÊýÓõò»¶Ô£¬ÄãûÓÐÖ¸¶¨Á´½Ó³ÌÐòÒªÓõ½µÃ¿â£¬±ÈÈçÄãµÄ³ÌÐòÀïÓõ½ÁËһЩÊýѧº¯Êý£¬ÄÇôÄã¾ÍÒªÔÚ±àÒë²ÎÊýÀïÖ¸¶¨³ÌÐòÒªÁ´½ÓÊýѧ¿â£¬·½·¨ÊÇÔÚ±àÒëÃüÁîÐÐÀï¼ÓÈë-lm¡£
4.-l²ÎÊýºÍ-L²ÎÊý
-l²ÎÊý¾ÍÊÇÓÃÀ´Ö¸¶¨³ÌÐòÒªÁ´½ÓµÄ¿â£¬-l²ÎÊý½ô½ÓמÍÊÇ¿âÃû£¬ÄÇô¿âÃû¸úÕæÕýµÄ¿âÎļþÃûÓÐʲô¹ØϵÄØ£¿¾ÍÄÃÊýѧ¿âÀ´Ëµ£¬ËûµÄ¿âÃûÊÇm£¬ËûµÄ¿âÎļþÃûÊÇlibm.so£¬ºÜÈÝÒ׿´³ö£¬°Ñ¿âÎļþÃûµÄÍ·libºÍβ.soÈ¥µô¾ÍÊÇ¿âÃûÁË¡£
ºÃÁËÏÖÔÚÎÒÃÇÖªµÀÔõôµÃµ½¿âÃûÁË£¬±ÈÈçÎÒÃÇ×ÔÒÑÒªÓõ½Ò»¸öµÚÈý·½ÌṩµÄ¿âÃû×Ö½Ðlibtest.so£¬ÄÇôÎÒÃÇÖ»Òª°Ñlibtest.so¿½±´µ½/usr/libÀ±àÒëʱ¼ÓÉÏ-ltest²ÎÊý£¬ÎÒÃǾÍÄÜÓÃÉÏlibtest.so¿âÁË£ ......
1.gcc°üº¬µÄc/c++±àÒëÆ÷
gcc,ccÓëc++,g++
gccºÍccÊÇÒ»ÑùµÄ£¬c++ºÍg++ÊÇÒ»ÑùµÄ¡£Ò»°ãc³ÌÐò¾ÍÓÃgcc±àÒ룬c++³ÌÐò¾ÍÓÃg++±àÒë¡£
2.gccµÄ»ù±¾Ó÷¨
gcc test.c£ºÈç¹ûûÓÐÖ¸¶¨Êä³öµÄÎļþ£¬Ä¬ÈϽ«±àÒë³öÒ»¸öÃûΪa.outµÄ³ÌÐò
gcc test.c -o test£º-o²ÎÊýÓÃÀ´Ö¸¶¨Éú³ÉÄ¿±ê³ÌÐòµÄÃû×Ö£¬ÕâÑù½«±àÒë³öÒ»¸öÃûΪtestµÄ³ÌÐò¡£
3.Ϊʲô»á³öÏÖundefined reference to 'xxxxx'´íÎó£¿
Ê×ÏÈÕâÊÇÁ´½Ó´íÎ󣬲»ÊDZàÒë´íÎó£¬Ò²¾ÍÊÇ˵Èç¹ûÖ»ÓÐÕâ¸ö´íÎó£¬ËµÃ÷ÄãµÄ³ÌÐòÔ´Âë±¾ÉíûÓÐÎÊÌ⣬ÊÇÄãÓñàÒëÆ÷±àÒëʱ²ÎÊýÓõò»¶Ô£¬ÄãûÓÐÖ¸¶¨Á´½Ó³ÌÐòÒªÓõ½µÃ¿â£¬±ÈÈçÄãµÄ³ÌÐòÀïÓõ½ÁËһЩÊýѧº¯Êý£¬ÄÇôÄã¾ÍÒªÔÚ±àÒë²ÎÊýÀïÖ¸¶¨³ÌÐòÒªÁ´½ÓÊýѧ¿â£¬·½·¨ÊÇÔÚ±àÒëÃüÁîÐÐÀï¼ÓÈë-lm¡£
4.-l²ÎÊýºÍ-L²ÎÊý
-l²ÎÊý¾ÍÊÇÓÃÀ´Ö¸¶¨³ÌÐòÒªÁ´½ÓµÄ¿â£¬-l²ÎÊý½ô½ÓמÍÊÇ¿âÃû£¬ÄÇô¿âÃû¸úÕæÕýµÄ¿âÎļþÃûÓÐʲô¹ØϵÄØ£¿¾ÍÄÃÊýѧ¿âÀ´Ëµ£¬ËûµÄ¿âÃûÊÇm£¬ËûµÄ¿âÎļþÃûÊÇlibm.so£¬ºÜÈÝÒ׿´³ö£¬°Ñ¿âÎļþÃûµÄÍ·libºÍβ.soÈ¥µô¾ÍÊÇ¿âÃûÁË¡£
ºÃÁËÏÖÔÚÎÒÃÇÖªµÀÔõôµÃµ½¿âÃûÁË£¬±ÈÈçÎÒÃÇ×ÔÒÑÒªÓõ½Ò»¸öµÚÈý·½ÌṩµÄ¿âÃû×Ö½Ðlibtest.so£¬ÄÇôÎÒÃÇÖ»Òª°Ñlibtest.so¿½±´µ½/usr/libÀ±àÒëʱ¼ÓÉÏ-ltest²ÎÊý£¬ÎÒÃǾÍÄÜÓÃÉÏlibtest.so¿âÁË£ ......