尊龙凯时人生就是博

ʹÓÃCMake¹¹½¨LinuxÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ

ʹÓÃcmake¹¹½¨linuxÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ

СÐò£º

ÔÚLinux¿ª·¢ÖÐ £¬Ê¹ÓÃCMake×÷Ϊ¹¹½¨¹¤¾ß¿ÉÒÔ´ó´ó¼ò»¯ÏîÄ¿µÄÖÎÀíºÍ¹¹½¨Àú³Ì¡£CMakeÊÇÒ»ÖÖ¿çƽ̨µÄ¹¹½¨ÏµÍ³ £¬Ëü¿ÉÒÔƾ֤²î±ðƽ̨µÄÌØÕ÷ºÍÐèÇóÌìÉú¶ÔÓ¦µÄ¹¹½¨Îļþ £¬ºÃ±ÈMakefile»òVisual StudioµÄ½â¾ö¼Æ»®¡£±¾ÎĽ«ÏÈÈÝһЩʹÓÃcmake¹¹½¨linuxÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ £¬²¢Ìṩ´úÂëʾÀý×ÊÖú¶ÁÕßѧϰºÍÕÆÎÕÕâЩ¼¼ÇÉ¡£

Ò». ×°ÖÃCMake

ʹÓÃCMake¹¹½¨LinuxÓ¦ÓóÌÐò֮ǰ £¬Ê×ÏÈÐèҪװÖÃCMake¡£ÔÚUbuntuϵͳÖÐ £¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°ÖÃCMake£º

sudo apt-get install cmake

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³ÉÖ®ºó £¬¿ÉÒÔͨ¹ýÔËÐÐÒÔÏÂÏÂÁîÀ´¼ì²éCMakeÊÇ·ñ×°ÖÃÀֳɣº

cmake --version

µÇ¼ºó¸´ÖÆ

ÈôÊÇÏÔʾÁËCMakeµÄ°æ±¾ÐÅÏ¢ £¬ÔòÌåÏÖ×°ÖÃÀֳɡ£

¶þ. ±àдCMakeLists.txtÎļþ

CMakeµÄÉèÖÃÎļþÊÇCMakeLists.txt £¬ËüÐÎòÁËÏîÄ¿µÄ¹¹½¨Àú³ÌºÍËùÐèµÄÒÀÀµÏî¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄCMakeLists.txtÎļþʾÀý£º

cmake_minimum_required(VERSION 3.0) # ÉèÖÃCMake×îµÍ°æ±¾ÒªÇó

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

# ÉèÖÃÔ´Îļþ
set(SOURCES
    main.cpp
    utils.cpp
)

# ÉèÖÃÍ·Îļþ·¾¶
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# ÉèÖÿÉÖ´ÐÐÎļþÊä³ö·¾¶
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

# ÌìÉú¿ÉÖ´ÐÐÎļþ
add_executable(${PROJECT_NAME} ${SOURCES})

µÇ¼ºó¸´ÖÆ

ÒÔÉÏʾÀýÖÐ £¬cmake_minimum_requiredÖ¸¶¨ÁËCMakeµÄ×îµÍ°æ±¾ÒªÇó £¬projectÉèÖÃÁËÏîÄ¿Ãû³Æ £¬setÉèÖÃÁËÔ´ÎļþÁбí £¬include_directoriesÖ¸¶¨ÁËÍ·ÎļþËÑË÷·¾¶ £¬setÉèÖÃÁË¿ÉÖ´ÐÐÎļþÊä³ö·¾¶ £¬add_executableÌìÉúÁË¿ÉÖ´ÐÐÎļþ¡£

Èý. ÉèÖñàÒëÆ÷Ñ¡ÏîºÍÁ´½Ó¿â

CMake¿ÉÒÔƾ֤²î±ðµÄÐèÇóÀ´ÉèÖñàÒëÆ÷Ñ¡ÏîºÍÁ´½Ó¿â¡£ÏÂÃæÊÇһЩ³£ÓõÄÉèÖÃÑ¡ÏîʾÀý£º

# ÉèÖÃC++±ê×¼
set(CMAKE_CXX_STANDARD 11)

# ÉèÖñàÒëÆ÷Ñ¡Ïî
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")

# ÉèÖÃÁ´½Ó¿â
target_link_libraries(${PROJECT_NAME} lib1 lib2)

µÇ¼ºó¸´ÖÆ

ÒÔÉÏʾÀýÖÐ £¬set(CMAKE_CXX_STANDARD 11)ÉèÖÃÁËC++±ê׼ΪC++11 £¬set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -Wall -Wextra”)ÉèÖÃÁ˱àÒëÆ÷Ñ¡ÏîΪ”-Wall -Wextra” £¬target_link_librariesÖ¸¶¨ÁËÁ´½Ó¿â¡£

ËÄ. ¹¹½¨ÏîÄ¿

ÔÚCMakeLists.txtËùÔÚµÄĿ¼ÏÂÖ´ÐÐÒÔÏÂÏÂÁîÀ´¹¹½¨ÏîÄ¿£º

mkdir build
cd build
cmake ..
make

µÇ¼ºó¸´ÖÆ

mkdir build½¨ÉèÁËÒ»¸öÓÃÓÚ¹¹½¨µÄĿ¼ £¬cd build½øÈë¸ÃĿ¼ £¬cmake ..ÓÃÓÚÌìÉú¹¹½¨Îļþ £¬makeÓÃÓÚ¾ÙÐÐÏÖʵµÄ¹¹½¨Àú³Ì¡£

½áÂÛ£º

ͨ¹ýѧϰÒÔÉϵÄÉèÖü¼ÇÉ £¬¶ÁÕß¿ÉÒÔÕÆÎÕʹÓÃCMake¹¹½¨LinuxÓ¦ÓóÌÐòµÄ»ù±¾ÒªÁìºÍ¼¼ÇÉ¡£CMakeµÄÇ¿Ê¢¹¦Ð§ºÍÎÞаÐÔʹµÃËüÔÚ´óÐÍÏîÄ¿µÄ¹¹½¨Àú³ÌÖкÜÊÇÓÐÓà £¬×ÊÖú¿ª·¢Õ߸üÀû±ãµØÖÎÀíÏîÄ¿ºÍÒÀÀµÏϣÍû±¾ÎÄÄܹ»¶Ô¶ÁÕßÔÚLinux¿ª·¢ÖÐʹÓÃCMakeÓÐËù×ÊÖú¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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