Qhov wikiHow no qhia koj yuav ua li cas sau C program los ntawm qhov chaw, siv GNU Compiler (GCC) rau Linux thiab Minimalist GNU (MinGW) rau Windows.
Kauj ruam
Txoj Kev 1 ntawm 2: Siv GCC rau Unix
Kauj Ruam 1. Qhib Terminal qhov rai ntawm koj lub computer Unix
Kauj Ruam 2. Nkag mus rau lo lus txib gcc --version thiab nias Enter kom tso saib GCC version ntawm lub khoos phis tawj
Yog tias koj lub khoos phis tawj qhia cov lus txib tsis pom lus, GCC yuav tsis raug teeb tsa hauv koj lub khoos phis tawj.
- Yog tias xav tau, teeb tsa GCC los ntawm kev ua raws li phau ntawv qhia rau koj li Linux faib.
- Txhawm rau sau cov phiaj xwm C ++, siv "g ++", tsis yog "gcc".
Kauj Ruam 3. Qhib daim nplaub tshev uas koj tau khaws qhov chaws ntawm qhov program
Piv txwv, yog tias txoj haujlwm program "akurapopo.c" nyob hauv/usr/yuliaR/qhov chaw nplaub tshev, sau cov lus txib cd/usr/yuliaR/qhov chaw
Kauj Ruam 4. Sau qhov hais kom ua gcc akurapopo.c Ako AkuRapopo
Hloov "akurapopo.c" nrog koj qhov program qhov chaws npe, thiab "AkuRapopo" nrog koj lub npe xav tau. Cov txheej txheem muab tso ua ke yuav pib.
- Yog tias muaj qhov ua yuam kev tshwm sim thaum txheej txheem muab tso ua ke, sau cov ntaub ntawv yuam kev nrog qhov hais kom ua gcc -Wall -o errorlog akurapopo.c. Tom qab ntawd, tso saib "errorlog" cov ntaub ntawv nrog tus miv errorlog hais kom ua.
- Sau cov program los ntawm ntau qhov chaws cov ntaub ntawv nrog cov lus txib gcc -o programname file1.c file2.c file3.c.
- Txhawm rau suav ntau qhov haujlwm los ntawm ntau qhov chaws nyob ib zaug, siv qhov hais kom ua gcc -c file1.c file2.c file3.c.
Kauj Ruam 5. Khiav qhov program suav nrog cov lus txib./programname
Txoj Kev 2 ntawm 2: Siv MinGW rau Windows
Kauj Ruam 1. Rub Minimalist GNU rau Windows los ntawm
MinGW yog qhov yooj yim-rau-nruab GCC pob rau Windows.
Kauj Ruam 2. Khiav qhov program MinGW kev teeb tsa
Yog tias qhov program teeb tsa tsis qhib cia li nyem ob npaug rau MinGW cov ntawv hauv Downloads nplaub tshev, tom qab ntawd nyem Nruab
Kauj Ruam 3. Kho qhov kev xaiv teeb tsa program, tom qab ntawd nyem Txuas ntxiv
Cov ntawv pom zoo rau nruab MinGW yog C: / MinGW. Yog tias koj xav tau hloov daim nplaub tshev teeb tsa, tsis txhob xaiv lub nplaub tshev nrog lub npe uas muaj cov chaw (xws li Cov Ntaub Ntawv Cov Ntaub Ntawv)
Kauj ruam 4. Xaiv tus compiler koj xav nruab
- Txhawm rau teeb tsa qhov kev pom zoo tsawg kawg suav nrog, xaiv Basic Setup nyob rau sab laug pane, tom qab ntawd zuam tag nrho cov ntawv sib dhos uas tshwm nyob rau sab xis ntawm lub ntsiab pane.
- Yog tias xav tau, koj tuaj yeem xaiv Txhua Pob Khoom thiab zuam tag nrho cov sib xyaw ua ke.
Kauj Ruam 5. Nyem rau Installation cov ntawv qhia zaub mov nyob rau sab saum toj sab laug ntawm MinGW
Kauj Ruam 6. Nyem Thov Hloov
Kauj Ruam 7. Nyem Thov kom rub tawm thiab teeb tsa tus muab tso ua ke
Kauj Ruam 8. Ntxiv MinGW PATH mus rau qhov system ib puag ncig sib txawv los ntawm cov hauv qab no:
- Nias Win+S qhib qhov Tshawb nrhiav cov ntawv, tom qab ntawd nkag mus rau lo lus tseem ceeb ib puag ncig.
- Hauv cov txiaj ntsig tshawb fawb, nyem Kho kom raug qhov system ib puag ncig hloov pauv.
- Nyem Environment Variables.
- Nyem Kho kom raug raws li lub npov sab saum toj (hauv qab Cov Neeg Siv Hloov Pauv).
- Nkag mus rau qhov kawg ntawm lub npov Variable Values.
- Sau; C: / MinGW / bin tom kawg ntawm cov ntawv hauv lub npov. Yog tias koj tau teeb tsa MinGW hauv lwm daim nplaub tshev, hloov; C: / MinGW / bin nrog; C: / installationfoldername / bin.
- Nyem OK ob zaug kom kaw lub qhov rais.
Kauj Ruam 9. Qhib kab hais kom ua qhov rais ua Tus Thawj Coj los ntawm cov hauv qab no:
- Nias Win+S, tom qab ntawd sau cmd.
- Right-click Command Prompt hauv cov txiaj ntsig tshawb fawb, tom qab ntawd nyem Run as Administrator.
- Nyem Yog los tso cai hloov pauv rau lub khoos phis tawj.
Kauj Ruam 10. Qhib daim nplaub tshev uas koj tau khaws qhov chaws ntawm txoj haujlwm
Piv txwv li, yog tias koj tau txuag qhov chaws "lailacanggung.c" hauv C: / Source / Programs nplaub tshev, sau cov lus txib cd C: / Source / Programs
Kauj Ruam 11. Nkag mus hais kom ua gcc lailacanggung.c –o lailacanggung.exe
Hloov lub npe filename nrog lub npe ntawm koj li program code file. Tom qab txheej txheem sau ua ke tiav, koj yuav pom kab lus hais dua. Yuam kev uas tshwm sim yuav tsis tshwm.
Yuam kev hauv txoj haujlwm program yuav tsum raug kho ua ntej pib txheej txheem sau ua ke. Txoj cai program uas muaj qhov ua yuam kev tsis tuaj yeem suav sau
Kauj Ruam 12. Sau lub npe ntawm koj qhov program kom khiav nws, piv txwv li lailacanggung.exe
Lub tswv yim
- Thaum koj suav qhov program nrog -g qhov ntsuas, tus neeg sau yuav suav nrog cov ntaub ntawv debugtug uas tsim nyog rau GDB, GCC qhov kev pabcuam debug ua haujlwm. Cov ntaub ntawv no yuav ua rau koj yooj yim dua rau kev debug.
- Txhawm rau suav cov haujlwm loj, koj tuaj yeem xub tsim Makefile.
- Yog tias koj lub khoos phis tawj tau ua kom nrawm dua, qhov haujlwm loj yuav nce ntxiv, thiab qhov raug yuav tsis zoo. Ntawm qhov tod tes, yog tias koj ua kom qhov loj me lossis qhov raug ntawm qhov haujlwm, qhov nrawm ntawm txoj haujlwm tuaj yeem txo qis.
- Thaum suav cov program C ++, siv G ++ raws li koj xav tau GCC. C ++ cov ntaub ntawv muaj.cpp txuas ntxiv siv.c.