ÔÚLinuxϵͳÉÏʹÓÃCLion¾ÙÐпçƽ̨C/C++¿ª·¢µÄÉèÖü¼ÇÉ
ÔÚlinuxϵͳÉÏʹÓÃclion¾ÙÐпçƽ̨c/c++¿ª·¢µÄÉèÖü¼ÇÉ
CLionÊÇÒ»¿î¹¦Ð§Ç¿Ê¢µÄ¿çƽ̨¼¯³É¿ª·¢ÇéÐΣ¨IDE£©£¬ËüÄܹ»×ÊÖú¿ª·¢Õ߸ßЧµØ¿ª·¢C/C++ÏîÄ¿¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxϵͳÉÏÉèÖÃCLion£¬ÒÔ±ã¾ÙÐпçƽ̨µÄC/C++¿ª·¢£¬²¢¸½´ø´úÂëʾÀý¡£
Ò»¡¢×°ÖÃCLion
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏÂÔز¢×°ÖÃCLion¡£¿ÉÒÔÔÚJetBrains¹ÙÍøÉÏÏÂÔص½×îа汾µÄCLion¡£ÏÂÔØÍê³Éºó£¬Ê¹ÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
tar -xzf CLion-*.tar.gz cd clion-*/bin ./clion.sh
µÇ¼ºó¸´ÖÆ
¶þ¡¢½¨ÉèC/C++ÏîÄ¿
·¿ªCLionºó£¬Ñ¡Ôñ¡°Create New Project¡±¡£
ÔÚ¡°New Project¡±´°¿ÚÖУ¬Ñ¡Ôñ¡°C Executable¡±»ò¡°C++ Executable¡±ÏîÄ¿ÀàÐÍ£¬µã»÷¡°Next¡±°´Å¥¡£
ÔÚ¡°Project Name¡±À¸ÖÐÊäÈëÏîÄ¿Ãû³Æ£¬Ñ¡ÔñÏîÄ¿ÉúÑĵÄ·¾¶£¬È»ºóµã»÷¡°Next¡±¡£
ÔÚ¡°Toolchains¡±Ñ¡ÏîÖУ¬Ñ¡ÔñÄãµÄ±àÒëÆ÷¡£ÈôÊÇÄãÒѾװÖÃÁËGCC»òÕßClang£¬CLion»á×Ô¶¯¼ì²âµ½ËüÃÇ£¬ÄãÖ»ÐèҪѡÔñ׼ȷµÄ¹¤¾ßÁ´¡£
µã»÷¡°Next¡±ºÍ¡°Finish¡±°´Å¥£¬CLion½«×Ô¶¯ÌìÉúÒ»¸öC/C++ÏîÄ¿µÄ»ù±¾¿ò¼Ü¡£
Èý¡¢ÉèÖÃÎļþ°üÀ¨Â·¾¶
ÓÐʱ¼ä£¬ÎÒÃÇÐèÒªÔÚÏîÄ¿ÖаüÀ¨Ò»Ð©Ìض¨µÄÎļþ»ò¿â¡£ÎªÁËʹ±àÒëÆ÷׼ȷµØÕÒµ½ÕâЩÎļþ»ò¿â£¬ÎÒÃÇÐèÒªÉèÖÃÎļþ°üÀ¨Â·¾¶¡£ÔÚCLionÖУ¬Õâ¿ÉÒÔͨ¹ýÒÔÏ°취Íê³É£º
Á¬Ã¦Ñ§Ï°¡°C++Ãâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
·¿ª¡°File¡±²Ëµ¥£¬Ñ¡Ôñ¡°Settings¡±¡£
ÔÚ¡°Settings¡±´°¿ÚÖÐÑ¡Ôñ¡°Build, Execution, Deployment -> CMake¡±¡£
ÔÚ¡°CMake¡±Ñ¡ÏÖУ¬ÔÚ¡°CMake options¡±À¸ÖÐÊäÈëÒÔÏÂÄÚÈÝ£º
-DCMAKE_INCLUDE_PATH=/path/to/include
µÇ¼ºó¸´ÖÆ
½«”/path/to/include”Ì滻ΪÄãÐèÒª°üÀ¨µÄÎļþ»ò¿âµÄ·¾¶¡£ÈôÊÇÓжà¸ö·¾¶£¬Ê¹Ó÷ֺŽ«ËüÃÇÍÑÀ뿪¡£
µã»÷¡°Apply¡±ºÍ¡°OK¡±°´Å¥£¬CLion½«ÖØмÓÔØCMake²¢ÉèÖÃеÄÎļþ°üÀ¨Â·¾¶¡£
ËÄ¡¢ÉèÖÃÔ¤´¦Öóͷ£Æ÷ºê
ÓÐʱ¼ä£¬ÎÒÃÇÐèҪƾ֤²î±ðµÄƽ̨»ò±àÒëÉèÖã¬ÆôÓûò½ûÓòî±ðµÄÔ¤´¦Öóͷ£Æ÷ºê¡£ÔÚCLionÖУ¬¿ÉÒÔͨ¹ýÒÔÏ°취Íê³É£º
·¿ª¡°File¡±²Ëµ¥£¬Ñ¡Ôñ¡°Settings¡±¡£
ÔÚ¡°Settings¡±´°¿ÚÖÐÑ¡Ôñ¡°Build, Execution, Deployment -> CMake¡±¡£
ÔÚ¡°CMake¡±Ñ¡ÏÖУ¬ÔÚ¡°CMake options¡±À¸ÖÐÊäÈëÒÔÏÂÄÚÈÝ£º
-DDEFINE_MACRO
µÇ¼ºó¸´ÖÆ
½«¡°DEFINE_MACRO¡±Ì滻ΪÄãÏëÒª½ç˵µÄÔ¤´¦Öóͷ£Æ÷ºêµÄÃû³Æ¡£ÈôÊÇÓжà¸öºê£¬Ê¹Ó÷ֺŽ«ËüÃÇÍÑÀ뿪¡£
µã»÷¡°Apply¡±ºÍ¡°OK¡±°´Å¥£¬CLion½«ÖØмÓÔØCMake²¢ÉèÖÃеÄÔ¤´¦Öóͷ£Æ÷ºê¡£
Îå¡¢ÉèÖõ÷ÊÔÆ÷
ÔÚCLionÖУ¬¿ÉÒÔʹÓÃGDB×÷ΪĬÈϵĵ÷ÊÔÆ÷¡£ÒªÉèÖõ÷ÊÔÆ÷£¬¿ÉÒÔƾ֤ÒÔÏ°취¾ÙÐУº
·¿ª¡°File¡±²Ëµ¥£¬Ñ¡Ôñ¡°Settings¡±¡£
ÔÚ¡°Settings¡±´°¿ÚÖÐÑ¡Ôñ¡°Build, Execution, Deployment -> Toolchains¡±¡£
ÔÚ¡°Debugger¡±Ñ¡ÏÖУ¬Ñ¡Ôñ¡°GDB¡±×÷ΪĬÈϵ÷ÊÔÆ÷£¬²¢ÉèÖÃGDBËùÐèµÄ·¾¶¡£
µã»÷¡°Apply¡±ºÍ¡°OK¡±°´Å¥£¬CLion½«ÖØмÓÔص÷ÊÔÆ÷ÉèÖá£
Áù¡¢Ê¾Àý´úÂë
ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý´úÂ룬ÑÝʾÁËÔõÑùÔÚCLionÖÐʹÓÃCMake¾ÙÐÐC/C++ÏîÄ¿µÄ¿çƽ̨¿ª·¢£º
#include <stdio.h> int main() { printf("Hello, CLion! "); return 0; }
µÇ¼ºó¸´ÖÆ
Æß¡¢×ܽá
ͨ¹ý±¾ÎÄËùÏÈÈݵÄÉèÖü¼ÇÉ£¬ÎÒÃÇ¿ÉÒÔÔÚLinuxϵͳÉϸüÀû±ãµØʹÓÃCLion¾ÙÐпçƽ̨µÄC/C++¿ª·¢¡£Í¨¹ýÉèÖÃÎļþ°üÀ¨Â·¾¶¡¢Ô¤´¦Öóͷ£Æ÷ºêºÍµ÷ÊÔÆ÷£¬¿ÉÒÔÓÐÓÃÌá¸ß¿ª·¢Ð§ÂÊ¡£Í¬Ê±£¬ÅäºÏCLionÇ¿Ê¢µÄ´úÂë±à¼ºÍµ÷ÊÔ¹¦Ð§£¬ÎÒÃÇÄܹ»¸üÇáËɵؾÙÐÐC/C++ÏîÄ¿¿ª·¢¡£
Ï£Íû±¾ÎÄÄܶÔÄãÔÚLinuxÉÏʹÓÃCLion¾ÙÐÐC/C++¿ª·¢µÄÉèÖÃÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇÔÚLinuxϵͳÉÏʹÓÃCLion¾ÙÐпçƽ̨C/C++¿ª·¢µÄÉèÖü¼ÇɵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡