CºÍC++»ìºÏ±à³Ì(__cplusplus Óë external "c" µÄʹÓÃ)
http://www.diybl.com/course/3_program/c++/cppjs/20090403/163906.html
CºÍC++»ìºÏ±à³Ì(__cplusplus Óë external "c" µÄʹÓÃ)
www.diybl.com¡¡Ê±¼ä£º2009-04-03¡¡×÷Õß:ÄäÃû ±à¼:sky µã»÷£º¡¡124 [ÆÀÂÛ]
µÚÒ»ÖÖÀí½â
±ÈÈç˵ÄãÓÃC++¿ª·¢ÁËÒ»¸öDLL¿â£¬ÎªÁËÄܹ»ÈÃCÓïÑÔÒ²Äܹ»µ÷ÓÃÄãµÄDLLÊä³ö(Export)µÄº¯Êý£¬ÄãÐèÒªÓÃextern "C"À´Ç¿ÖƱàÒëÆ÷²»ÒªÐÞ¸ÄÄãµÄ
º¯ÊýÃû¡£
ͨ³££¬ÔÚCÓïÑÔµÄÍ·ÎļþÖо³£¿ÉÒÔ¿´µ½ÀàËÆÏÂÃæÕâÖÖÐÎʽµÄ´úÂ룺
#ifdef __cplusplus
extern "C" {
#endif
/**** some declaration or so *****/
#ifdef __cplusplus
}
#endif /* end of __cplusplus */
ÄÇô£¬ÕâÖÖд·¨Ê²Ã´ÓÃÄØ£¿Êµ¼ÊÉÏ£¬ÕâÊÇΪÁËÈÃCPPÄܹ»ÓëC½Ó¿Ú¶ø²ÉÓõÄÒ»ÖÖÓï·¨ÐÎʽ¡£Ö®ËùÒÔ²ÉÓÃÕâÖÖ·½Ê½£¬ÊÇÒòΪÁ½ÖÖÓïÑÔÖ®¼äµÄһЩ²î
ÒìËùµ¼Öµġ£ÓÉÓÚCPPÖ§³Ö¶à̬ÐÔ£¬Ò²¾ÍÊǾßÓÐÏàͬº¯ÊýÃûµÄº¯Êý¿ÉÒÔÍê³É²»Í¬µÄ¹¦ÄÜ£¬CPPͨ³£ÊÇͨ¹ý²ÎÊýÇø·Ö¾ßÌåµ÷ÓõÄÊÇÄÄÒ»¸öº¯Êý¡£ÔÚ
±àÒëµÄʱºò£¬CPP±àÒëÆ÷»á½«²ÎÊýÀàÐͺͺ¯ÊýÃûÁ¬½ÓÔÚÒ»Æð£¬ÓÚÊÇÔÚ³ÌÐò±àÒë³ÉΪĿ±êÎļþÒÔºó£¬CPP±àÒëÆ÷¿ÉÒÔÖ±½Ó¸ù¾ÝÄ¿±êÎļþÖеķûºÅÃû
½«¶à¸öÄ¿±êÎļþÁ¬½Ó³ÉÒ»¸öÄ¿±êÎļþ»òÕß¿ÉÖ´ÐÐÎļþ¡£µ«ÊÇÔÚCÓïÑÔÖУ¬ÓÉÓÚÍêȫûÓжà̬ÐԵĸÅÄC±àÒëÆ÷ÔÚ±àÒëʱ³ýÁË»áÔÚº¯ÊýÃûÇ°ÃæÌí
¼ÓÒ»¸öÏ»®ÏßÖ®Í⣬ʲôҲ²»»á×ö£¨ÖÁÉٺܶà±àÒëÆ÷¶¼ÊÇÕâÑù¸ÉµÄ£©¡£ÓÉÓÚÕâÖÖµÄÔÒò£¬µ±²ÉÓÃCPPÓëC»ìºÏ±à³ÌµÄʱºò£¬¾Í¿ÉÄÜ»á³öÎÊÌâ¡£¼Ù
ÉèÔÚijһ¸öÍ·ÎļþÖж¨ÒåÁËÕâÑùÒ»¸öº¯Êý£º
int foo(int a, int b);
¶øÕâ¸öº¯ÊýµÄʵÏÖλÓÚÒ»¸ö.cÎļþÖУ¬Í¬Ê±£¬ÔÚ.cppÎļþÖе÷ÓÃÁËÕâ¸öº¯Êý¡£ÄÇô£¬µ±CPP±àÒëÆ÷±àÒëÕâ¸öº¯ÊýµÄʱºò£¬¾ÍÓпÉÄÜ»á°ÑÕâ¸öº¯Êý
Ãû¸Ä³É_fooii£¬ÕâÀïµÄii±íʾº¯ÊýµÄµÚÒ»²ÎÊýºÍµÚ¶þ²ÎÊý¶¼ÊÇÕûÐÍ¡£¶øC±àÒëÆ÷È´ÓпÉÄܽ«Õâ¸öº¯ÊýÃû±àÒë³É_foo¡£Ò²¾ÍÊÇ˵£¬ÔÚCPP±àÒëÆ÷µÃ
µ½µÄÄ¿±êÎļþÖУ¬foo()º¯ÊýÊÇÓÉ_fooii·ûºÅÀ´ÒýÓõģ¬¶øÔÚC±àÒëÆ÷Éú³ÉµÄÄ¿±êÎļþÖУ¬foo()º¯ÊýÊÇÓÉ_fooÖ¸´úµÄ¡£µ«Á¬½ÓÆ÷¹¤×÷µÄʱºò£¬Ëü
¿É²»¹ÜÉϲã²ÉÓõÄÊÇʲôÓïÑÔ£¬ËüÖ»ÈÏÄ¿±êÎļþÖеķûºÅ¡£ÓÚÊÇ£¬Á¬½ÓÆ÷½«»á·¢ÏÖÔÚ.cppÖе÷ÓÃÁËfoo()º¯Êý£¬µ«ÊÇÔÚÆäËüµÄÄ¿±êÎļþÖÐÈ´ÕÒ²»
µ½_fooiiÕâ¸ö·ûºÅ£¬ÓÚÊÇÌáʾÁ¬½Ó¹ý³Ì³ö´í¡£extern "C" {}ÕâÖÖÓï·¨ÐÎʽ¾ÍÊÇÓÃÀ´½â¾öÕâ¸öÎÊÌâµÄ¡£±¾ÎĽ«ÒÔʾÀý¶ÔÕâ¸öÎÊÌâ½øÐÐ˵Ã÷¡£
Ê×ÏȼÙÉèÓÐÏÂÃæÕâÑùÈý¸öÎļþ£º
/* file: test_extern_c.h */
#ifndef __TEST_EXTERN_C_H__
#define __TEST_EXTERN_C_H__
Ïà¹ØÎĵµ£º
°æȨÉêÃ÷£ºÒÔÏÂÄÚÈÝÊôÓÚ×÷ÕßÕýÔÚд×÷µÄ¡¶Èí¼þ²âÊÔʵ¼ù¡·Ò»ÊéµÄÄÚÈÝ£¬Î´¾Ðí¿É²»µÃÓÃÓÚÈκÎÕýʽ³ö°æÎïÖУ¬Èç¹ûתÔØÇë×¢Ã÷³ö´¦¡£
×÷ÕߣºÖÜΰÃ÷
´úÂë¼ìÊÓÒªµã
´úÂë¼ìÊÓ¼¼ÄÜÊôÓÚ¿ª·¢ÈËÔ±µÄ»ù±¾¹¦£¬Äܹ»ºÜ´ó³Ì¶ÈµØ·´Ó¦³ö¿ª·¢ÈËÔ±µÄÄÜÁ¦Ë®Æ½£¬Ç°Ãæ4.4.1½ÚÒѾ½²¹ýÌá¸ßÆÀÉó¼ìÊӵķ½·¨¡£ÏÂÃæÒÔʵ¼ÊµÄC/C++ÓïÑÔ·½ÃæµÄ´úÂëÀ´½²½â ......
Ò»Sun Studio ¼ò½é
Sun Studio ÊÇ Solaris/OpenSolaris ²Ù×÷ϵͳÉϵÄÊ×Ñ¡¿ª·¢»·¾³¡£Ëü°üº¬²¢ÓÅ»¯ÁË C ¡¢ C++ ¼° Fortran ±àÒëÆ÷£¬¶øÇÒÈÚÈëÁËÒµ½çÁìÏ鵀 IDE ºÍÐÔÄܵ÷ÊÔ¼¼Êõ¡£Ëæ×ÅÈíÓ²¼þ¼¼Êõ·¢Õ¹¹ØϵµÄµ÷Õû£¬¿ª·¢¶à´¦ÀíÆ÷ºÍ¶àÏß³ÌÓ¦ÓõÄÖØÒªÐÔÕýÈÕÒæÍ»³ö£¬¶ø Sun StudioÔÚ¿ª·¢¶àÏ̳߳ÌÐò£¨Ó ......
×î½üÔÚ×ö³ÌÐòʱÐèҪʹÓÃÒ»¸öÒѾ±àºÃµÄC³ÌÐòÔ´Îļþ£¨ÓÐÍ·Îļþ£©£¬½«Í·Îļþ¼ÓÈëÒªµ÷ÓõÄÔ´ÎļþÖУ¬µ÷ÓÃÏàÓ¦Cº¯Êý£¬±àÒëʱ³öÏÖÈçÏ´íÎó£º
sss.c(3129) : fatal error C1010: unexpected end of file while looking for precompiled header directive
ÔÚÍøÉϲéÁËÏà¹Ø×ÊÁÏ£¬Ëµ²»ÄÜÔÚCÔ´ÎļþÖаüº¬"stdafx.h"Îļþ£¬
ÖªµÀÐèÒªÒ ......
ÒÔÏÂÊǼ¸¸ö¼¬ÊÖµÄ
C ÎÊÌâ, ºÜÄÑ×ö, ¿´¿´×Ô¼º»á×ö¼¸¸ö?
How do you write a program which produces its own source code as its output?
How can I find the day of the week given the date?
Why doesn’t C have nested functions?
What is the most efficient way to count the num ......
C/C++ÊÇ×îÖ÷ÒªµÄ±à³ÌÓïÑÔ¡£ÕâÀïÁгöÁË50ÃûÓÅÐãÍøÕ¾ºÍÍøÒ³Çåµ¥£¬ÕâЩÍøÕ¾Ìṩc/c++Ô´´úÂë¡£Õâ·ÝÇåµ¥ÌṩÁËÔ´´úÂëµÄÁ´½ÓÒÔ¼°ËüÃǵÄС˵Ã÷¡£ÎÒÒѾ¡Á¦°üÀ¨×î¼ÑµÄC/C++Ô´´úÂëµÄÍøÕ¾¡£Õâ²»ÊÇÒ»¸öÍêÕûµÄÇåµ¥£¬ÄúÓн¨Òé¿ÉÒÔÁªÏµÎÒ£¬ÎÒ½«»¶ÓÄúµÄ½¨Ò飬ÒÔ½øÒ»²½¼ÓÇ¿Õâ·½ÃæµÄÇåµ¥¡£
1¡¢http://snippets.dzone.com/tag/c/ --ÊýÒÔǧ¼Æ ......