尊龙凯时人生就是搏

ʹÓÃCMake¹¹½¨Linux¸ßÐÔÄÜÅÌËãÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ

ʹÓÃcmake¹¹½¨linux¸ßÐÔÄÜÅÌËãÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ

ÔÚLinuxÇéÐÎÏ¿ª·¢¸ßÐÔÄÜÅÌËãÓ¦ÓóÌÐòÊÇÒ»Ïî¾ßÓÐÌôÕ½ÐÔµÄʹÃü¡£ÎªÁËÄܹ»³ä·ÖʹÓöàºË´¦ÀíÆ÷ºÍ¸ßËÙµÄÍøÂçÅþÁ¬ £¬³ÌÐòµÄ±àÒëºÍÁ´½ÓÀú³ÌÐèÒª¾ÙÐÐһЩÓÅ»¯¡£CMakeÊÇÒ»¿îÊ¢ÐеĹ¹½¨¹¤¾ß £¬Ëü¿ÉÒÔ¼ò»¯¹¹½¨Àú³Ì £¬Í¬Ê±ÌṩÁËһЩÓÅ»¯Ñ¡Ïî¡£±¾ÎĽ«ÏÈÈÝһЩʹÓÃcmake¹¹½¨linux¸ßÐÔÄÜÅÌËãÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ £¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£

Ò»¡¢×°ÖÃCMake

Ê×ÏÈ £¬ÎÒÃÇÐèҪװÖÃCMake¹¤¾ß¡£ÔÚ´ó´ó¶¼Linux¿¯ÐаæÖÐ £¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°ÖÃCMake£º

$ sudo apt-get install cmake

µÇ¼ºó¸´ÖÆ

¶þ¡¢½¨ÉèCMakeLists.txtÎļþ

CMakeʹÓÃCMakeLists.txtÎļþÀ´ÐÎòÏîÄ¿µÄ¹¹½¨¹æÔò¡£ÎÒÃÇ¿ÉÒÔÔÚÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öCMakeLists.txtÎļþ £¬È»ºóÔÚÆäÖнç˵¹¹½¨¹æÔò¡£

ÀýÈç £¬ÎÒÃǵÄÏîÄ¿°üÀ¨Á½¸öÔ´Îļþ£ºmain.cppºÍutils.cpp¡£ÎÒÃÇ¿ÉÒÔƾ֤ÒÔÏ·½·¨À´½¨ÉèCMakeLists.txtÎļþ£º

# CMake×îµÍ°æ±¾ÒªÇó
cmake_minimum_required(VERSION 3.10)

# ÏîÄ¿Ãû³Æ
project(MyApp)

# ½ç˵¿ÉÖ´ÐÐÎļþ
add_executable(MyApp main.cpp utils.cpp)

µÇ¼ºó¸´ÖÆ

ÉÏÊöʾÀýÖÐ £¬ÎÒÃÇÊ×ÏÈÖ¸¶¨ÁËËùÐèµÄCMakeµÄ×îµÍ°æ±¾¡£È»ºó £¬Ê¹ÓÃprojectÏÂÁî¸øÏîÄ¿ÃüÃû¡£×îºó £¬Ê¹ÓÃadd_executableÏÂÁî½ç˵ÁËÒ»¸ö¿ÉÖ´ÐÐÎļþMyApp £¬²¢½«main.cppºÍutils.cpp×÷ΪԴÎļþ¾ÙÐбàÒë¡£

Èý¡¢Ìí¼Ó±àÒëºÍÁ´½ÓÑ¡Ïî

ÔÚ¾ÙÐиßÐÔÄÜÅÌËãÓ¦ÓóÌÐòµÄ±àÒëºÍÁ´½Óʱ £¬ÎÒÃÇͨ³£ÐèÒªÌí¼ÓһЩ±àÒëÑ¡ÏîºÍÁ´½ÓÑ¡ÏîÒÔÓÅ»¯ÐÔÄÜ¡£

ÀýÈç £¬ÎÒÃÇ¿ÉÒÔʹÓÃ-O3Ñ¡Ïî¶Ô´úÂë¾ÙÐÐÓÅ»¯£º

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

µÇ¼ºó¸´ÖÆ

ÉÏÊöʾÀýÖÐ £¬ÎÒÃÇʹÓÃsetÏÂÁCMAKE_CXX_FLAGS±äÁ¿ÉèÖÃΪĿ½ñµÄCXXFLAGS±äÁ¿Öµ¼ÓÉÏ-O3Ñ¡Ïî £¬ÌåÏÖ¶ÔC++´úÂë¾ÙÐÐ×îºéÁ÷ƽµÄÓÅ»¯¡£

ÁíÍâ £¬ÈôÊÇÎÒÃǵijÌÐòÒÀÀµÓÚһЩÍⲿ¿â £¬ÎÒÃÇ»¹ÐèÒªÖ¸¶¨ÕâЩ¿âµÄλÖúÍÃû³Æ¡£ÀýÈç £¬ÈôÊÇÎÒÃǵijÌÐòÒÀÀµÓÚOpenMP¿â £¬ÎÒÃÇ¿ÉÒÔƾ֤ÒÔÏ·½·¨À´ÉèÖãº

# ²éÕÒOpenMP¿â
find_package(OpenMP REQUIRED)

# Ìí¼ÓOpenMP±àÒëÑ¡Ïî
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")

# Ìí¼ÓOpenMPÁ´½ÓÑ¡Ïî
target_link_libraries(MyApp ${OpenMP_CXX_LIBRARIES})

µÇ¼ºó¸´ÖÆ

ÉÏÊöʾÀýÖÐ £¬ÎÒÃÇÊ×ÏÈʹÓÃfind_packageÏÂÁî²éÕÒOpenMP¿â £¬²¢½«Æä´æ´¢ÔÚOpenMP±äÁ¿ÖС£È»ºó £¬Ê¹ÓÃsetÏÂÁ±àÒëÑ¡ÏîCMAKE_CXX_FLAGSÉèÖÃΪĿ½ñµÄCXXFLAGS±äÁ¿Öµ¼ÓÉÏOpenMPµÄ±àÒëÑ¡Ïî¡£×îºó £¬Ê¹ÓÃtarget_link_librariesÏÂÁOpenMPµÄÁ´½Ó¿âÌí¼Óµ½¿ÉÖ´ÐÐÎļþMyAppÖС£

ËÄ¡¢¾ÙÐй¹½¨

Íê³ÉÁËCMakeLists.txtÎļþµÄ±àдºó £¬ÎÒÃÇ¿ÉÒÔ¾ÙÐй¹½¨ÁË¡£Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öbuildÎļþ¼Ð £¬²¢½øÈë¸ÃÎļþ¼Ð£º

$ mkdir build
$ cd build

µÇ¼ºó¸´ÖÆ

È»ºó £¬Ê¹ÓÃcmakeÏÂÁîÀ´ÌìÉúMakefile£º

$ cmake ..

µÇ¼ºó¸´ÖÆ

½Ó×Å £¬Ê¹ÓÃmakeÏÂÁî¾ÙÐбàÒ룺

$ make

µÇ¼ºó¸´ÖÆ

µ½´ËΪֹ £¬ÎÒÃÇÒѾ­ÀֳɵØʹÓÃCMake¹¹½¨ÁËÎÒÃǵĸßÐÔÄÜÅÌËãÓ¦ÓóÌÐò¡£

×ܽá

ͨ¹ý±¾ÎĵÄÏÈÈÝ £¬ÎÒÃÇÏàʶÁËÔõÑùʹÓÃCMakeÀ´¹¹½¨Linux¸ßÐÔÄÜÅÌËãÓ¦ÓóÌÐò £¬²¢ÌṩÁËһЩ³£ÓõÄÉèÖü¼ÇɺʹúÂëʾÀý¡£Ê¹ÓÃCMake¿ÉÒÔ´ó´ó¼ò»¯¹¹½¨Àú³Ì £¬Ìá¸ß¿ª·¢Ð§ÂÊ¡£Ï£Íû±¾ÎĶÔÄúÓÐËù×ÊÖú £¬Äܹ»ÔÚÄúµÄÏîÄ¿ÖÐÊ©Õ¹×÷Óá£

ÒÔÉϾÍÊÇʹÓÃCMake¹¹½¨Linux¸ßÐÔÄÜÅÌËãÓ¦ÓóÌÐòµÄÉèÖü¼ÇɵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ