2011-08-02 13 views
5

Cuando puedo compilar mi código consigo un montón de errores que SPAN través de la pantalla y puedo ver dónde está el comienzo de error. ¿Cómo puedo guardar la salida de gcc en un archivo?Cómo guardar la salida de error de gcc para presentar

me trataron trucos como

gcc> registro.txt

o grepping el resultado, pero no funcionó. Google busca rendimientos sobre todo el resultado en la explicación de cómo imprimir a presentar con C++

+0

¿Qué significa "did not work"? –

+0

La salida todavía se imprime en la pantalla – Yotam

Respuesta

16

CCG salidas de errores en la secuencia de error estándar no a la salida estándar corriente. Es necesario volver a dirigir error estándar, en lugar de la salida estándar . En bash:

gcc 2> log.txt 
+1

Y en csh o tcsh: 'gcc ...> & log.txt' (que dirige tanto stdout como stderr a' log.txt', pero gcc no escribe mucho a stdout de todas formas). –

9

Personalmente me enteré de que simplemente la salida del error a un archivo no ayudaría. De hecho, lo más fácil que podría ayudarme es evitar envolver las líneas de error que suelen ser muy largas. Entonces, decidí usar vim highlighting para ver mejor los errores.

Sin el marcador (View Larger Image)

Screenshot - Before

Con el marcador (View Larger Image)

Screenshot - After.

Y, afortunadamente, había una manera muy fácil de configurar un nuevo formato con colores en VIM. Siga estos pasos y usted será más productivo trabajar en gran medida de los códigos de plantilla de C++:

crear una nueva regla de sintaxis personalizada VIM destacando establece

tiene que definir el resaltado de sintaxis reglas. Ponga lo siguiente en un archivo llamado cerr.vim y mantenerlo por ejemplo en $HOME/vim_syntax/cerr.vim

"Set line wrapping to off to see more error lines in one page 
set nowrap     
set showmatch 
"I use stl and boost alot so it is good to remove the namespaces from the error file :) 
silent! %s/st![enter image description here][2]d:://g             
silent! %s/boost::fusion:://g             
silent! %s/boost:://g             
"Usually I am not interested in the file paths until I can locate the error so I tried to 
"hide them 
silent! %s/\/[^\.]*\// /g              
"By default syntax highlighting for each line is limited to 3000 characters  
"However, 3000 characters is not sufficient for lengthy C++ errors, so I change it to 20000 
set synmaxcol=20000                
"Now I define the keywords that I would like them to be highlighted 
syn keyword cerrInfo instantiated            
syn keyword cerrError error Error ERROR          
syn keyword cerrWarning warning Warning WARNING 

"-------------------------------------           
"In this step I would like to distinguish the prefix in each line (which shows the file name) from the rest of the line 
syn region cerrLine start=/^/ end=/\:/           
syn region cerrSeparator start=/^\.+/ end=/\./ fold oneline 

"I want to make templated type information less visible while debugging    
"You have to remember that a type can have nested types. So I define three regions 
syn region cerrTemplate1 matchgroup=xBracket1 start=/</ end=/>/ contains=cerrTemplate2 fold oneline 
syn region cerrTemplate2 matchgroup=xBracket2 start=/</ end=/>/ contains=cerrTemplate3 fold contained oneline 
syn region cerrTemplate3 start=/</ end=/>/ contains=cerrTemplate3 contained oneline fold oneline 

"Now I would like to highlight whatever is in parenthesis with a different color so I make 
"another region in here. This makes sure that function arguments can have different color    
syn region cerrPar matchgroup=xBracket start=/(/ end=/)/ contains=cerrTemplate1 oneline fold 
"GCC puts the real type information in brackets, let's group them separately 
syn region cerrBracket start=/\[/ end=/\]/ contains=cerrTemplate1,cerrPar oneline 

"Again GCC puts the error in these weird characters :) So I define a separate region here 
syn region cerrCode start=/‘/ end=/’/ contains=cerrPar,cerrBracket,cerrTemplate1 oneline 

"And finally I would like to color the line numbers differently 
syn match cerrNum "[0-9]\+[:|,]"            

"-------------------------------------------------------------------------- 
"Now the fun part is here, change the colors to match your terminal colors. 
"I Use the following colors for my white background terminal. 
"In the following we assign a color for each group that we defined earlier 

"Comment is a default VIM color group 
highlight link cerrInfo Comment  
"We use custom coloring for the rest           
highlight default cerrWarning ctermfg=red ctermbg=yellow      
highlight default cerrError ctermfg=white ctermbg=red       
highlight default cerrLine ctermfg=grey term=bold        
highlight default cerrSeparator ctermfg=darkgrey        
highlight default cerrTemplate1 ctermfg=grey term=bold       
highlight default cerrTemplate2 ctermfg=grey term=bold       
highlight default cerrTemplate3 ctermfg=grey         
highlight default cerrCode cterm=bold ctermfg=darkgrey       
highlight default cerrBracket ctermfg=darkgreen        
highlight default xBracket1 ctermfg=darkgrey term=bold       
highlight default xBracket2 ctermfg=darkgrey         
highlight default cerrPar ctermfg=yellow          
highlight default cerrNum ctermfg=red 

cambiar el archivo .vimrc

Ahora, usted tiene que decirle a vim a usar su nueva resaltado para los archivos con extensión específica . En mi caso me gustaría salida de mis archivos de error a error.ccerr, ponga lo siguiente en su .vimrc en la carpeta de inicio:

au BufRead,BufNewFile *.cerr set filetype=myerror 
au Syntax myerror source $HOME/vim_syntax/cerr.vim 

lo que digo en lo anterior es que cuando los archivos con la extensión .cerr se abren utilizando VIM, se considerarán de tipo myerror. En la segunda línea, estoy diciendo que VIM debería usar mi conjunto de reglas de resaltado de sintaxis que definí en el paso anterior para todos los archivos myerror.

Envíe su salida de error en un archivo .cerr y abrirlo con VIM

Este paso es el más fácil, enviamos todos los errores y advertencia a error.cerr y si hay algún error en el archivo de inmediato abierto el archivo .cerr usando VIM.

g++ failing.cc &> error.cerr || vim error.cerr 
+0

Mi solución más nueva es usar '' sublime_text''. He escrito un tutorial rápido sobre cómo configurarlo en [aquí] (http://stackoverflow.com/questions/13674223/how-do-you-get-vim-to-highlight-c-syntax-errors-like -visual-studio/21895852 # 21895852) –

Cuestiones relacionadas