ÔÚLinuxÉÏʹÓÃCMake¹¹½¨¿çƽ̨³ÌÐòµÄÉèÖÃÒªÁì
ÔÚlinuxÉÏʹÓÃcmake¹¹½¨¿çƽ̨³ÌÐòµÄÉèÖÃÒªÁì
ÔÚ¿ª·¢¿çƽ̨³ÌÐòʱ£¬Ò»¸öÖ÷ÒªµÄ¹¤¾ßÊÇCMake¡£CMakeÊÇÒ»¸ö¿ªÔ´µÄ¿çƽ̨¹¹½¨¹¤¾ß£¬¿ÉÒÔ×Ô¶¯ÌìÉúÖÖÖÖƽ̨ÉϵĹ¹½¨Îļþ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxÉÏʹÓÃCMakeÀ´ÉèÖú͹¹½¨¿çƽ̨³ÌÐò¡£
CMakeµÄ×°ÖÃ
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃCMake¡£ÔÚ´ó´ó¶¼Linux¿¯ÐаæÉÏ£¬¿ÉÒÔʹÓðü¹ÜÀíÆ÷À´×°ÖÃCMake¡£ÀýÈ磬ÔÚUbuntuÉÏ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî×°ÖÃCMake£º
sudo apt-get install cmake
µÇ¼ºó¸´ÖÆ
ÈôÊÇÄãµÄLinux¿¯ÐаæûÓаüÀ¨CMakeµÄÈí¼þ°ü£¬Äã¿ÉÒÔ´ÓCMakeµÄ¹Ù·½ÍøÕ¾ÏÂÔØÔ´´úÂ룬Ȼºóƾ֤¹Ù·½ÎĵµÖеÄָʾ¾ÙÐбàÒëºÍ×°Öá£
½¨ÉèCMakeLists.txtÎļþ
Ò»µ©CMake×°ÖÃÍê³É£¬ÎÒÃǾͿÉÒÔ×îÏȱàдCMakeLists.txtÎļþÁË¡£CMakeLists.txtÎļþ°üÀ¨ÁËCMakeµÄÉèÖÃÖ¸ÁÓÃÓÚ¸æËßCMakeÔõÑù¹¹½¨ÎÒÃǵijÌÐò¡£
½¨ÉèÒ»¸ö¿ÕµÄÎı¾Îļþ£¬½«ÆäÃüÃûΪCMakeLists.txt£¬²¢ÔÚÎļþÖÐÊäÈëÒÔÏÂÄÚÈÝ£º
cmake_minimum_required(VERSION 3.10) project(MyProject) # Ìí¼ÓÔ´Îļþ add_executable(MyExecutable main.cpp) # ÉèÖÿÉÖ´ÐÐÎļþÊä³ö·¾¶ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÖ¸ÁîÊ×ÏÈÖ¸¶¨ÁËÎÒÃÇʹÓõÄCMakeµÄ×îµÍ°æ±¾¡£È»ºó£¬Í¨¹ýprojectÏÂÁÎÒÃÇÖ¸¶¨ÁËÏîÄ¿µÄÃû³Æ¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«ÏîÄ¿ÃüÃûΪMyProject¡£
½ÓÏÂÀ´£¬Ê¹ÓÃadd_executableÏÂÁîÌí¼ÓÔ´Îļþ¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«main.cppÎļþÌí¼Óµ½¿ÉÖ´ÐÐÎļþÖС£Äã¿ÉÒÔƾ֤ÄãµÄÏîÄ¿Ìí¼Ó¸ü¶àµÄÔ´Îļþ¡£
×îºó£¬Ê¹ÓÃsetÏÂÁîÉèÖÿÉÖ´ÐÐÎļþµÄÊä³ö·¾¶¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«¿ÉÖ´ÐÐÎļþÊä³öµ½Ò»¸öÃûΪbinµÄĿ¼ÖС£
±àÒëºÍ¹¹½¨ÏîÄ¿
Íê³ÉCMakeLists.txtÎļþµÄ±àдºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃCMakeÀ´±àÒëºÍ¹¹½¨ÎÒÃǵÄÏîÄ¿¡£
Ê×ÏÈ£¬½¨ÉèÒ»¸öÃûΪbuildµÄĿ¼£¬²¢½øÈë¸ÃĿ¼£º
mkdir build cd build
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÔËÐÐcmakeÏÂÁîÀ´ÌìÉú¹¹½¨Îļþ£º
cmake ..
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«¹¹½¨ÎļþÌìÉúÔÚÉÏÒ»¼¶Ä¿Â¼ÖУ¬ÒÔÊÇÎÒÃÇʹÓÃ..ÌåÏÖÉÏÒ»¼¶Ä¿Â¼¡£
ÔËÐÐcmakeÏÂÁîºó£¬CMake»áƾ֤CMakeLists.txtÎļþÌìÉúÏìÓ¦µÄ¹¹½¨Îļþ¡£
×îºó£¬Ê¹ÓÃmakeÏÂÁîÀ´±àÒëºÍ¹¹½¨ÏîÄ¿£º
make
µÇ¼ºó¸´ÖÆ
makeÏÂÁ»áÖ´ÐбàÒëºÍÁ´½Ó²Ù×÷£¬²¢ÌìÉú×îÖյĿÉÖ´ÐÐÎļþ¡£
ÔËÐгÌÐò
Íê³É±àÒëºÍ¹¹½¨ºó£¬ÎÒÃÇ¿ÉÒÔÔËÐÐÌìÉúµÄ¿ÉÖ´ÐÐÎļþ¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǵĿÉÖ´ÐÐÎļþÃûΪMyExecutable¡£
ÔËÐпÉÖ´ÐÐÎļþµÄÒªÁìÈ¡¾öÓÚÄãµÄÏîÄ¿µÄÀàÐͺÍÐèÇó¡£ÀýÈ磬ÈôÊÇÄãµÄ¿ÉÖ´ÐÐÎļþÊÇÒ»¸öÏÂÁîÐгÌÐò£¬Äã¿ÉÒÔÔÚÖÕ¶ËÖÐÔËÐÐËü£º
./bin/MyExecutable
µÇ¼ºó¸´ÖÆ
ÈôÊÇÄãµÄ¿ÉÖ´ÐÐÎļþÊÇÒ»¸öͼÐνçÃæ³ÌÐò£¬Äã¿ÉÒÔͨ¹ýͼÐνçÃæÀ´Æô¶¯Ëü¡£
×ܽá
ͨ¹ýCMake£¬ÎÒÃÇ¿ÉÒÔÀû±ãµØÔÚLinuxÉϹ¹½¨¿çƽ̨³ÌÐò¡£ÎÒÃÇÖ»Ðè±àдһ¸ö¼òÆÓµÄCMakeLists.txtÎļþ£¬È»ºóʹÓÃCMakeÀ´ÌìÉú¹¹½¨Îļþ¡£È»ºóͨ¹ýmakeÏÂÁîÀ´±àÒëºÍ¹¹½¨ÏîÄ¿¡£ÕâʹµÃ³ÌÐòÔÚÖÖÖÖƽ̨ÉϹ¹½¨ºÍÔËÐбäµÃÔ½·¢ÈÝÒס£Ï£Íû±¾ÎÄÄÜ×ÊÖúÄã×îÏÈʹÓÃCMakeÀ´¹¹½¨¿çƽ̨³ÌÐò¡£
ÒÔÉÏÊÇÔÚlinuxÉÏʹÓÃcmake¹¹½¨¿çƽ̨³ÌÐòµÄÉèÖÃÒªÁ졣ϣÍû¶ÔÄãÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇÔÚLinuxÉÏʹÓÃCMake¹¹½¨¿çƽ̨³ÌÐòµÄÉèÖÃÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡