2011-08-02 23 views
5

Kiedy kompiluję mój kod, dostaję mnóstwo błędów, które przeniosłem przez ekran i widzę, gdzie zaczyna się błąd. Jak mogę zapisać wyjście pliku gcc do pliku?Jak zapisać wyjście błędów gcc do pliku

Próbowałem sztuczki jak

gcc> log.txt

lub grepping wynik, ale to nie działa. Wyszukiwanie w Google plony wynikają głównie na wyjaśnianiu, jak drukować do pliku z C++

+0

Co masz na myśli "nie działa"? –

+0

Dane wyjściowe są nadal drukowane na ekranie – Yotam

Odpowiedz

16

GCC wyjścia błędów do strumienia błąd standardowy nie do standardowe wyjście strumienia. Musisz przekierować standardowy błąd zamiast standardowego wyjścia . W bash:

gcc 2> log.txt 
+1

W csh lub tcsh: 'gcc ...> & log.txt' (który kieruje stdout i stderr do' log.txt', ale gcc nie zapisuje zbyt wiele w stdout tak czy inaczej). –

9

Osobiście dowiedziałem się, że samo wyświetlenie błędu w pliku nie pomogłoby. W rzeczywistości najłatwiej mi pomóc uniknąć owijania linii błędu, które zwykle są bardzo długie. Postanowiłem więc użyć podświetlania vim, aby lepiej widzieć błędy.

Bez markerem (View Larger Image)

Screenshot - Before

Wraz z markerem (View Larger Image)

Screenshot - After.

I na szczęście był bardzo łatwy sposób na ustawienie nowego wyróżniania składni w VIM. Wykonaj kroki i będzie bardziej produktywne ciężko pracuje na C++ na matrycy kodów:

utworzyć nową regułę VIM zwyczaj podświetlanie składni ustawić

trzeba zdefiniować podświetlanie składni reguł. Umieścić następujące informacje w pliku o nazwie cerr.vim i zachować ją na przykład w $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 

Zmień swój plik .vimrc

Teraz trzeba powiedzieć vim do korzystania z nowego Podświetlanie plików z konkretnym rozszerzeniem . W moim przypadku chciałbym wyjście moje pliki błędach error.ccerr, umieścić następujące w Twojej .vimrc w katalogu domowym:

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

Co mówię w powyżej jest to, że gdy pliki z rozszerzeniem .cerr są otwierane przy użyciu VIM, będą one traktowane jako typ myerror. W drugim wierszu mówię, że VIM powinien używać mojego zestawu reguł podświetlania składni, który zdefiniowałem w poprzednim kroku dla wszystkich plików myerror.

Wyślij wyjście błędu do pliku .cerr i otwórz go z VIM

Ten krok jest najłatwiejszy, wysyłamy wszystkie błędy i ostrzeżenia error.cerr i czy jest jakiś błąd w pliku natychmiast otwarte plik .cerr za pomocą VIM.

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

Moim nowszym rozwiązaniem jest użycie '' wzniosłego_tekstu''. Napisałem szybki tutorial, jak skonfigurować go w [tutaj] (http://stackoverflow.com/questions/13674223/how-do-you-get-vim-to-highlight-c-syntax-errors-like -visual-studio/21895852 # 21895852) –

Powiązane problemy