ã¢ãã³ãªC, C++ã®éçºç°å¢ã®æ§ç¯æ¹æ³
ã¾ã C, C++ããªããããªã®ã§æ¸ãã¦ã¿ãã主ã«Linux(Debianã¨ãUbuntu)ã§ã®ç°å¢æ§ç¯ã«ã¤ãã¦ã
ã³ã³ãã¤ã©
ã¾ãã¯apt-getã§ã³ã³ãã¤ã©ãã¤ã³ã¹ãã¼ã«ãããUbuntuãDebianãªã以ä¸ã®ã³ãã³ãã§gccãg++ããã³æ¨æºã©ã¤ãã©ãªçãã¤ã³ã¹ãã¼ã«ãããã
$ sudo apt-get install build-essential
ãããã°ãã¼ã«
ãããã¬ããã³ãããã°ãã¼ã«ã¯å°ãªãã¨ã以ä¸ã®ä¸ã¤ã¯å ¥ããã(ãã¨ltraceã欲ããããªï¼)
- GDB
- è¨ããã¨ç¥ããGNUã®ãããã¬
- Valgrind
- ã¡ã¢ãªãªã¼ã¯ãä¸æ£ã¡ã¢ãªã¢ã¯ã»ã¹ã®æ¤åº
- strace
- ã·ã¹ãã ã³ã¼ã«ã®ãã¬ã¼ã¹
$ sudo apt-get install gdb valgrind strace
ãã«ããã¼ã«
C, C++ã®ãã«ããã¼ã«ã¨ããã°ã¾ãmakeãæµ®ãã¶ãã©ãæè¿ã§ã¯SConsãCMakeãªã©ã®ä»£æ¿ãã¼ã«ã§ãã«ãããOSSãè¦ããããã¨ãå¢ãã¦ããæããããã¨ã¯ãããä¾ç¶ã¨ãã¦ãã«ãã«makeãå¿ è¦ãªããã¸ã§ã¯ãã¯ããããããã®ã§ãã¨ããããmakeã¯å ¥ããã
$ sudo apt-get install make
makeã®ä»£æ¿ã¨ãã¦ã®SCons
SConsã¯æ°å¤ãããmakeã®ä»£æ¿ãã¼ã«ã®ãã¡ã®ä¸ã¤ãmakeã§ã¯ãã¡ã¤ã«éã®ä¾åé¢ä¿ãèªåã§è¨è¿°ããå¿
è¦ããããã©ãSConsã ã¨åãã¡ã¤ã«ã®ä¾åé¢ä¿ã®è§£æãå®è¡æã«èªåçã«è¡ã£ã¦ãããã®ã§ããã«ããã¡ã¤ã«ãMakefileã«æ¯ã¹ã¦ã·ã³ãã«ã«ãªãã¨ããå©ç¹ããããã¾ããã«ããã¡ã¤ã«ãPythonã§è¨è¿°ã§ããã®ã§ãMakefileã«æ¯ã¹ã¦ããªãèéã®å©ãæãæ¹ãã§ãããSConsã®ç°¡åãªãã¥ã¼ããªã¢ã«ã«ã¤ãã¦ã¯こちらã
DebianãUbuntuãªãapt-getã§ç°¡åã«ã¤ã³ã¹ãã¼ã«ã§ããã
$ sudo apt-get install scons
ãã¹ã
CãªãCUnitãC++ãªãgoogletestããªã¹ã¹ã¡ãã»ãã«ãCppUnitããããã©ãä½ã¨ãããããã¯CUnitããã®ãããæ¸ãã«ãããããããªç©ã«ä»ä¸ãã£ã¦ããã®ã§ãå人çã«ãªã¹ã¹ã¡ã§ããªãã
$ sudo apt-get install libcunit1 libcunit1-dev # CUnit $ sudo apt-get install libgtest0 libgtest-dev # googletest
ãã¹ãã«ãã¬ãã¸
ãã¹ãã«ãã¬ãã¸ã«ã¯gcovã使ããããã¯GCCã«çµã¿è¾¼ã¾ãã¦ãããã®ã¨èãã¦ããã
$ gcc -coverage -o prog prog.c $ ./prog $ gcov prog.gcda File 'prog.c' Lines executed:87.25% of 102 $
ä¸è¨ã®éãã«ã³ãã³ããå®è¡ããã¨prog.gcovã¨ãããã¡ã¤ã«ãã§ãããã¾ãããã®å ´åã®ã«ãã¬ãã¸çã¯87.25%ã«ãªã£ã¦ãããgcovã®ä¸èº«ã¯ä»¥ä¸ã®ãããªæããã#ãã§å§ã¾ã£ã¦ããè¡ãå®è¡ããã¦ããªã(ãã¹ãã§ãã¦ããªããã¨)ã表ãã¦ããã
6146: 154: for (int i=0;i<c;++i) { 6139: 155: fnv_ent_t *tail = ents[i].next; 12366: 156: while (tail) { 88: 157: fnv_ent_t *current = tail; 88: 158: tail = tail->next; 88: 159: FNV_FREE(current); -: 160: } -: 161: } 7: 162: FNV_FREE(tbl); 7: 163:} -: 164: -: 165:/** -: 166: * print entries of hash table -: 167: */ #####: 168:void fnv_tbl_print(fnv_tbl_t *tbl, size_t c) { #####: 169: fnv_ent_t *ents = tbl->ents; #####: 170: for (int i=0;i<c;++i) { #####: 171: fnv_ent_t *ent = &ents[i]; #####: 172: if (ent->k == NULL) continue; #####: 173: printf("i = %d, key = %s, val = %s", i, ent->k, (char *)ent->v); #####: 174: if (ent->next != NULL) { #####: 175: fnv_ent_t *tail = ent->next; #####: 176: while (tail) { #####: 177: printf(" -> key = %s, val = %s", tail->k, (char *)tail->v); #####: 178: tail = tail->next; -: 179: } -: 180: } #####: 181: printf("\n"); -: 182: } #####: 183:}
ãããã¡ã¤ã©
C, C++ã®ãããã¡ã¤ã©ã ã¨gprofãããã¯google-perftoolsçãããã(追è¨ï¼gprofã¯oprofileã§ã¯ãªãbinutilsãã¤ã³ã¹ãã¼ã«ããã 2010/8/1 12:10)
$ sudo apt-get install binutils # gprof(æåããå ¥ã£ã¦ããã) $ sudo apt-get install libgoogle-perftools0 libgoogle-perftools-dev # google-peftools
åã ã®ç°¡åãªä½¿ãæ¹ã«ã¤ãã¦ã¯ãgprofã¯こちらããgoogle-perftoolsã¯こちらãããããããã
ã½ã¼ã¹ã³ã¼ãç´¢å¼
C, C++ã®ã½ã¼ã¹ã³ã¼ãç´¢å¼ã«ã¯GNU GLOBALããªã¹ã¹ã¡ãetagsãctagsã«ã¯ãªãè¤æ°åè£ã¸ã®å¯¾å¿ãå®ç¾©å ã ãã§ãªãåç §å ã¸ã®ã¸ã£ã³ããæ¤ç´¢ããµãã¼ããã¦ããã®ãã¨ã¦ã便å©ããã¨ã¨ãã£ã¿ã«ä¾åããªããEmacs使ããªãgtags.elãvim使ããªãgtags.vimãã¤ã³ã¹ãã¼ã«ãããããã®äºã¤ã®ãã¡ã¤ã«ã¯GNU GLOBALã®ã½ã¼ã¹ã³ã¼ãã«å«ã¾ãã¦ããã
$ sudo apt-get install global
ç´¢å¼ãçæããã«ã¯ã½ã¼ã¹ã³ã¼ãããããã£ã¬ã¯ããªã§gtagsã³ãã³ããå®è¡ããã
$ gtags -v # -v:verbose
gtagsã¯æ¢ã«ç´¢å¼ããããã©ããã«é¢ãããæåããç´¢å¼ãå ¨é¨ä½ãç´ãã®ã§ãæ¢ã«ããç´¢å¼ãæ´æ°ããå ´åã¯globalã³ãã³ãã«-uãä»å ãã¦å®è¡ããã
$ global -uv # -v:verbose
ããã±ã¼ã¸ã·ã¹ãã
C, C++ã«ããã¦Perlã®CPANãRubyã®gemsãPHPã®PEARã«ç¸å½ããããã±ã¼ã¸ã·ã¹ãã ã¯åå¨ããªããã§ãã¾ãåºæ¬çã«éçºã«æä½éå¿ è¦ãªããã±ã¼ã¸ã¯yumã¨ãaptã§ååã«ãã¼ã§ããã®ã§ãç¹ã«å°ããªãããããè¤æ°ã®ããã±ã¼ã¸ã·ã¹ãã (yumã¨PEARã¨ã)ããã¡ãæ··ãã«æ±ã£ãããçµ±ä¸ããããã«rpmãdebããã±ã¼ã¸ããã¡ãã¡ä½ããªããã°ãããªãã±ã¼ã¹ã¯LLã«æ¯ã¹ã¦å°ãªãã¨æãã
èªåããã¥ã¡ã³ãåãã¼ã«
C, C++ã ã¨Doxygenããæãæµ®ãã°ãªããã ãã©ãã»ãã«ããããã ãããï¼
$ sudo apt-get install doxygen
ãã¾ã«ã¯GCC以å¤ã§ããã«ããã¦ã¿ãã
åã¯æ®æ®µããLinuxä¸ã§ã»ã¼CUIãªã¿ã¼ããã«ã§éçºãã¦ãããã©ãèªåãä½ã£ã¦ãã©ã¤ãã©ãªã®åä½ç¢ºèªã®ããã«Windows7(64bitç)ãç«ã¡ä¸ãã¦Visual Studioã§ãã«ããããã¨ããã¾ã«ãããLinuxãMacã§ã¯åé¡ãªãåãã¦ããã®ã«Windowsã ã¨ããããã³ã³ãã¤ã«ãéããªãã¨ããã±ã¼ã¹ãããã*1ããã«éçºè ãWindowsä¸ã§ã®åä½ãå®å ¨ã«ã¯ä¿è¨¼ããªãæ¹éãæ¡ã£ã¦ããã®ã ã¨ãã¦ãVisual Studioã¯ã³ã³ãã¤ã©ã®ãã§ãã¯ã(ããã©ã«ãã®)GCCã«æ¯ã¹ã¦å³ããã®ã§ãããã°ã©ã ãVisual Studioã®ã³ã³ãã¤ã©ã«éãã ãã§ãããã°ã©ã ã®æ½å¨çãªãªã¹ã¯ãæ¤åºããã®ã«ã¯å½¹ç«ã¤ãGCCã§ãé©åã«è¤æ°ã®ãªãã·ã§ã³ãä»å ããã°ãããã ãããã©ãçé¢ç®ã«ä»å ãã¦ããã¨çµæ§ãªéã«ãªããããã¹ã¦ã®è¦åãªãã·ã§ã³ãä»ããã®ãã¢ã¬ãªã®ã§ãèªåãå¿ è¦ã ã¨æããªãã·ã§ã³ãé©å®ä»å ãã¦ããã®ãæ£ããé¸æã ã¨æããã§ãå°ãªãã¨ã-Wallãããã¯ä»ããããã
ãã®ä»ã®è¨èª
追è¨
ãªããâã®ã¨ã³ããªã¼ã«ãã©ãã¯ããã¯ãåè¨4åãéããã¦ãã¾ã£ããããããã¦ã¯ã¦ãã£ã¦æ´æ°ãã度ã«ãã©ãã¯ããã¯éä¿¡ããã¡ããã®ï¼
*1:ä¾ï¼unistd.hããªãã¨ãstdint.hããªãã¨ãè¨ããã¦