Cov txheej txheem:
- Khoom siv
- Kauj ruam 1: Download tau Installer
- Kauj Ruam 2: Txhim Kho MinGW kom raug
- Kauj Ruam 3: Kev Txhim Kho Pob
- Kauj Ruam 4: Muaj Peev Xwm Siv Koj Tus Neeg Sau Txhua Qhov Chaw Nrog CMD
- Kauj Ruam 5: Cov Kev Xaiv Muaj txiaj ntsig Koj tuaj yeem Siv Thaum Sib Sau Ua Haujlwm
Video: Yuav Ua Li Cas Teeb Kho Programming hauv C/C ++: 5 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:26
C thiab C ++ yog cov lus programming nrov uas muab kev nkag tau sai rau cov qauv thiab daws cov teeb meem nyuaj nrog cov peev txheej tsawg kawg nkaus. Qhov teeb meem yog nrhiav txoj hauv kev los sib sau ua ke thiab ua kom lub program ua tiav.
Ib qho ntawm koj cov kev xaiv yuav siv Visual Studio, uas yog cov ntawv nyeem-kho, muab tso ua ke hauv ib qho. Thaum muaj txiaj ntsig, qee tus yuav pom nws nyuaj dhau lossis xav tau txoj hauv kev yooj yim los hloov kho thiab suav lawv cov lej. Qhov ntawd yog qhov Minimalist GNU rau Windows los, lossis MinGW kom luv. Koj siv MinGW hauv koj kab lus kab lus sib tham, cov ntawv tsuas yog siv uas koj tuaj yeem nkag tau sai los ntawm nias lub pob qhov rai thiab ntaus "cmd".
Txog qhov kawg ntawm Cov Lus Qhia no, koj yuav tsum muaj MinGW teeb tsa kom raug, thiab tuaj yeem suav sau ib qho c/c ++ program nyob qhov twg ntawm koj lub computer.
NCO TSEG: Cov lus qhia no tsuas yog rau Windows ib puag ncig. Linux los nrog GCC, GNU sau cov neeg sau ua ke. Nov yog qhov txiaj ntsig xav tau rau peb ib puag ncig, kom tau GCC mus rau Windows.
Khoom siv
Koj yuav xav tau lub khoos phis tawj txhawm rau rub tawm software thiab tsim kev sib txuas hauv is taws nem rau kev teeb tsa ruaj khov thiab nrawm. Thaum tsis xav tau, koj kuj tseem xav tau tus ntiv tes xoo, yog tias koj xav kom muaj lub cev nqa tau ntawm MinGW teeb tsa.
Kauj ruam 1: Download tau Installer
Thawj qhov peb yuav tsum tau ua yog tau txais lub installer.
Txhawm rau ua qhov ntawd, peb yuav tsum mus rau MinGW lub vev xaib.
Los ntawm qhov ntawd, koj yuav xav mus rau qhov rub tawm txuas, nyob ntawm sab laug hauv ntu kev taw qhia. Yog tias koj tsis tuaj yeem pom nws lossis nws tau tsiv, qhov txuas no yuav coj koj mus rau ntawd
Qhov peb xav tau yog cov ntaub ntawv mingw-get-setup.exe. Thaum cov ntawv tau rub tawm, peb tuaj yeem txav mus rau qib tom ntej.
Kauj Ruam 2: Txhim Kho MinGW kom raug
Thawj qhov nws nug yog qhov twg koj xav nruab nws. Txhawm rau kom nkag tau yooj yim, Kuv pom zoo tso nws hauv phau ntawv teev npe ua ntej. Txwv tsis pub, koj tuaj yeem teeb tsa qhov no nyob txhua qhov chaw, txawm tias ntawm tus ntiv tes xoo.
Qhov kev xaiv tom ntej tham txog Tus Neeg Siv Kev Sib Tham rau MinGW. Peb yuav ua haujlwm nrog UI hauv qhov no, vim nws zoo dua los saib seb peb tuaj yeem ua dab tsi.
Kauj Ruam 3: Kev Txhim Kho Pob
Tam sim no uas peb tau ua tiav kev teeb tsa ntawm MinGW, peb yuav tsum xaiv cov pob tshwj xeeb rau nruab. Hauv cov lus qhia no, peb yuav ua kom yooj yim thiab ua haujlwm nrog cov txheej txheem yooj yim, vim peb tuaj yeem tau txais qhov txiaj ntsig xav tau yam tsis tas yuav nkag mus rau txhua qhov ntawm cov pob khoom uas MinGW muab.
Nyob rau sab laug Cov Ntsiab Lus, kom ntseeg tau tias koj tab tom saib Basic Setup. Los ntawm qhov ntawd koj yuav tsum pom 7 yam khoom hauv lub rooj raug. Txog C/C ++ cov ntawv sau, koj yuav xav teeb tsa cov pob hauv qab no: mingw32-base-bin thiab mingw32-gcc-g ++-bin. GCC siv rau c cov haujlwm, thiab G ++ siv rau C ++ cov haujlwm.
Txhawm rau teeb tsa pob, nyem rau pob thiab tom qab ntawd nyem "Kos rau Kev teeb tsa". Thaum koj tau cim cov pob koj xav tau, mus rau sab laug sab saum toj thiab nyem rau ntawm "Installation". Koj yuav ces "Thov Hloov," uas tom qab ntawd yuav qhia koj lub qhov rai tshiab uas qhia pom qhov kev hloov pauv uas koj yuav ua. Nyem "Txais" thiab kev teeb tsa yuav pib. Kev rub tawm yuav pib, thiab tom qab ntawd lwm lub qhov rai yuav tshwm, lub sijhawm no qhia koj yog tias koj kev teeb tsa tiav.
Kauj Ruam 4: Muaj Peev Xwm Siv Koj Tus Neeg Sau Txhua Qhov Chaw Nrog CMD
Nrog koj tus tshiab compiler tau teeb tsa, koj yuav pom tias koj cov lus txib tam sim no tsis paub gcc lossis g ++ raws li cov lus txib. Txhawm rau ua qhov no koj yuav tsum ua cov hauv qab no:
- Nias lub Windows qhov tseem ceeb, ntaus hauv "Kho qhov system ib puag ncig hloov pauv" thiab tom qab ntawd ntaus nkag
- Ib lub qhov rai tshiab yuav tshwm tuaj, hu ua System Properties.
- Yog tias tsis tau muaj, mus rau Advanced tab.
- Saib mus rau hauv qab txoj cai, thiab nyem rau ntawm Ib puag ncig hloov pauv.
- Los ntawm qhov ntawd, koj yuav pom ob daim ntawv teev cov npe sib txawv. Nyob ntawm koj nyiam, koj tuaj yeem teeb tsa txoj hauv kev no hauv ib tus neeg siv, lossis cov kab ke dav. Txawm li cas los xij, nrhiav qhov "Path" variable thiab nyem rau ntawm Edit.
- Los ntawm lub qhov rai tshiab, nyem rau Tshiab nyob rau sab xis ntawm lub qhov rais, thiab tom qab ntawv ntaus hauv qab no: "C: MinGW bin". Peb yuav tsum coj nws mus rau hauv phau ntawv teev npe hauv peb qhov kev teeb tsa vim tias qhov ntawd yog qhov uas peb cov neeg sau ua ke, gcc thiab g ++, muaj nyob.
- Los ntawm qhov ntawd, ntaus OK hauv ob lub qhov rais, thiab qhib qhov hais kom ua tshiab. Ntaus hauv gcc lossis g ++ thiab saib yog tias cov lus txib tau teb rov qab rau koj. Kuaj nws ntxiv los ntawm kev ua C lossis C ++ program thiab sim sau nws
Tam sim no koj muaj peev xwm los tsim cov phiaj xwm thiab sau lawv nyob txhua qhov chaw ntawm koj lub system.
Txhawm rau suav qhov program, txhua yam koj yuav tsum ua yog hu rau gcc yog tias nws yog c program, lossis g ++ yog nws yog c ++ program, thiab tom qab ntawd ntaus lub npe ntawm qhov program koj xav sau. Piv txwv: gcc helloworld.c lossis g ++ helloworld.cpp
Cov kauj ruam tom ntej, thaum xaiv tau, piav qhia qee qhov kev xaiv muaj txiaj ntsig uas koj tuaj yeem siv nrog koj tus neeg sau.
Kauj Ruam 5: Cov Kev Xaiv Muaj txiaj ntsig Koj tuaj yeem Siv Thaum Sib Sau Ua Haujlwm
Thaum tsis tas yuav suav koj cov haujlwm, cov kev xaiv no yuav pab koj hauv kev debugging koj cov cai.
Cov syntax rau qhov koj tso cov kev xaiv no yog li hauv qab no rau gcc lossis g ++: g (cc/++) -option kev sib cav
- -o: qhov kev xaiv no tso cai rau koj rau npe lub program ntawm kev suav sau. Los ntawm lub neej ntawd, koj qhov program yuav raug hu ua a.exe. Yog li los ntawm kev ua: "gcc helloworld.c -o Nyob Zoo", koj yuav tau txais Hello.exe
-
-g: qhov kev xaiv no tso cai rau lwm txoj haujlwm kom tuaj yeem siv koj cov cai. "gdb" lossis GNU Debugger xav tau qhov -g kev xaiv txhawm rau ua haujlwm. GNU Debugger yog cov cuab yeej muaj txiaj ntsig zoo hauv qhov uas nws tso cai rau koj pom li cas koj cov kev hloov pauv thiab cov cai ua haujlwm ib kab zuj zus. Nws tau nce qib me ntsis rau cov neeg tuaj tshiab, yog li nws yog lub tswv yim zoo los saib cov lus txib uas koj tuaj yeem ua hauv nws.
NCO TSEG: Thaum muaj txiaj ntsig, yog tias koj tsis npaj yuav siv gdb, tom qab ntawd koj yuav tsum tsis txhob siv -g, vim tias cov ntaub ntawv loj dua ntau dua li koj tus qauv exe ntawv
- -Wall, -Werror, -Wextra, thiab -pedantic yog txhua qhov ceeb toom cuam tshuam txog kev xaiv. Phab ntsa Wextra thiab pedantic yuav ntes feem ntau yuam kev thiab ceeb toom thaum Werror hloov tag nrho cov lus ceeb toom rau hauv qhov ua yuam kev. Qhov sib txawv ntawm ob qho no yog tias yog koj qhov program muaj lus ceeb toom, nws tseem yuav suav sau. Yog tias nws muaj qhov yuam kev, txawm li cas los xij; qhov program yuav tsis muab tso ua ke. Kev ua phem nyob rau hauv rooj plaub no yog kev coj ua ntau dua li cov cuab yeej, hauv qhov nws tswj hwm kev coj ua raug cai raws li tus qauv c, uas coj kuv mus rau qhov kev xaiv kawg kuv xav tham
-
--std =: Qhov kev xaiv no qhia rau tus neeg siv ntawm tus qauv siv. Txawm hais tias tej zaum tsis tseem ceeb hauv feem ntau, yog tias koj tau txais cov cai qub uas tsis tuaj yeem ua haujlwm hauv tus txheej txheem niaj hnub no, qhov kev xaiv no yuav tswj hwm tus qauv uas koj xaiv. Qee cov qauv tseem ceeb yog c99, c89, gnu99, gnu 89, thiab lwm yam. Kuv yuav hais ib txwm koj yuav tsis siv qhov kev xaiv no tshwj tsis yog koj xav tau.
NCO TSEG: Qhov kev xaiv no tsuas yog rau c
- Piv txwv ntawm cov kev xaiv ua ke: gcc --std = c99 -Wall -Wextra -pedantic -Werror -g helloworld.c -o nyob zoo
- Piv txwv ntawm cov kev xaiv ua ke hauv c ++: g ++ -Wall -Wextra -pedantic -Werror -g helloworld.c -o nyob zoo