Eclipse

From MukeWiki
<entry excluding="tmva|roofit|README|man|macros|icons|fonts|etc|documentation|doc|interpreter|config|cmake|builtins|build|bindings" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>

Eclipse IDE for C/C++ Developers

The CDT is Eclipse's C/C++ Development Tooling project.

Simultaneous Release

Eclipse Helios (3.6) - previous (June 2010)
Eclipse CDT - C/C++ Development Tools (7.0)
Eclipse Indigo (3.7) - current (June 2011)
Eclipse CDT - C/C++ Development Tools (8.0)
Eclipse Juno (4.2) - planned (June 2012)
Eclipse CDT - C/C++ Development Tools (9.0)

Install

  • Stiahnuty eclipse tarball subor extrahovat do potrebnej directory, bud do user home dir, alebo skor do dir nezavislej od user-a /opt
$ su -
$ tar -xzf eclipse-cpp-indigo-*-linux-gtk-x86_64.tar.gz -C /opt/
$ chmod -R +r /opt/eclipse/
$ chown -R root:root /opt/eclipse/
  • Aplikaciu pridame do menu vytvorenim suboru /usr/share/applications/eclipse.desktop
[Desktop Entry]
Type=Application
Name=Eclipse
Comment=Eclipse IDE
Exec=/opt/eclipse/eclipse
# Exec=env GTK_THEME=Adwaita:dark /opt/eclipse/eclipse
Icon=/opt/eclipse/icon.xpm
Terminal=false
Categories=Development;IDE;
StartupNotify=true
  • V pripade ak instalujem Eclipse do nie user home dir, tak bug-om - bug 249133 vsetky linky z Available Software Sites (odkial sa potom instaluju pluginy, updates) su nepristupne/neviditelne. V pripade ak je nainstalovany v user home dir tak linky su pristupne. Preto si docasne Eclipse nainstalujem (jednoducho rozpakujem tarball) do home dir. Spustim ho z home dir (~/eclipse/eclipse). Linky su teraz pristupne. Window -> Preferences => Install/Update -> Available Software Sites oznacim vsetky Location a exportujem do suboru bookmarks.xml. Mazem docasne nainstalovany Eclipse z home dir, a spustam ho z user-a nezavislej dir (/opt/eclipse/eclipse). Importujem nedavno vytvoreny subor bookmarks.xml. Update: po nainstalovani akehokolvek plugin-a (pomocou Eclipse mechanizmu Help -> Install New Software) sa linky, ktore boli pred tym nepristupne/neviditelne, automaticky spristupnia, t.j. nic z vyssie uvedeneho uz nie je potrebne robit.
  • Eclipse CDT je nainstalovany nezavisle od user-a (cista distribucia), vsetky potrebne subory (pluginy a pod.) sa budu ukladat v home dir ~/.eclipse
  • Stale je tu moznost instalacie priamo z Fedora repository
$ yum install eclipse-cdt
  • Pre spustenie Eclipse je potrebne Java runtime environment (JRE)

Eclipse and ROOT

simple CERN ROOT project

  • Jednoduchy priklad, ktory ukazuje ako v Eclipse pracovat (editacia, kompilacia, ...) napr. so suborom $ROOTSYS/test/hworld.cxx
  • Najprv musim vytvorit novy projekt File -> New -> C++ Project => Executable -> Empty Project (pripadne Hello World C++ Project). V polozke Project Name zadam meno, napr. test, nastavim Location, kde sa budu vsetky subory projektu ukladat. V polozke Select Configuration staci vybrat len Release
  • V existujucom projekte mozem bud vytvorit novy subor, alebo jednoducho importujem uz existujuci subor(y). File -> Import => General -> File System vyberiem dir, kde sa nachadza nas testovy subor hworld.cxx a oznacim len tento jeden subor na importovanie
  • Subor/program hworld.cxx sa kompiluje (a linkuje) nasledovne
g++ -I$ROOTSYS/include -L/cern/root/lib -lCore -lCint -lRIO -lHist -lGraf -lGpad -lMatrix -lMathCore -lThread -o hworld.exe $ROOTSYS/test/hworld.cxx
alebo pomocou root-config utility
g++ -c $ROOTSYS/test/hworld.cxx `root-config --cflags`
g++ -o hworld.exe hworld.o `root-config --glibs`
  • V Eclipse je potrebne nastavit kompilator a linker pre spolupracu s ROOT framework-om. Project -> Properties, resp. vyberieme nas (test) projekt v okne Project Explorer a stlacime Template:KeyPress, dalej:
    • C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous | Other flags pridat $(shell root-config --cflags)
    • C/C++ Build -> Settings -> Tool Settings -> GCC C++ Linker -> Miscellaneous | Linker flags pridat $(shell root-config --glibs)
    • C/C++ Build -> Settings -> Tool Settings jednotlive premenne, napr. Inlcude paths (-I), Libraries (-l), Library path (-L), atd mozem nastavit aj manualne, t.j. kompilovat bez utility root-config
  • Pre spravne fungovanie C/C++ Indexer (v Eclipse sa spusta Run C/C++ Code Analysis)
    • C/C++ General -> Path and Symbols -> Includes -> GNU C++ | Include directories pridat ${ROOTSYS}/include
  • V pripade, ak nastavim napr. premennu Inlcude paths (-I) v C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler manualne, tak Eclipse si ju automaticky dopise aj do C/C++ General -> Path and Symbols -> Includes -> GNU C++ a naopak, to iste plati aj aj pre ostatne premenne
  • Project -> Build All ( Template:KeyPress ) vytvorime projekt (Eclipse vytvori potrebny Makefile), ktory sa nasledovne aj skompiluje, alebo projekt priamo spustime Run -> Run ( Template:KeyPress )

project STRELA

  • Priklad kedy uz kod existuje, zdrojove subory projektu STRELA sa nachadzaju v GitHub repository https://github.com/musinsky/strela
  • Vytvorenie projektu zo suborov, ktore su
    1. na lokalnom disku.
      File -> Import => C/C++ -> Existing Code as Makefile Project (alebo File -> New -> Makefile Project with Existing Code). V polozke Existing Code Location vyberiem directory, kde sa nachadzaju zdrojove subory (vratane Makefile). Nastavim C++ ako Languages a Linux GCC ako Toolchain for Indexer Settings
    2. v GitHub repository. Potrebne nainstalovat EGit plugin pre podporu Git (analogicky mozno pouzit aj SVN, resp. CVS)
      File -> Import => Git -> Projects from Git. Najprv si vytvorim Git Repository kliknutim na Clone, v polozke Location nastavim URI projektu git://github.com/musinsky/strela.git. Vyberiem potrebny branch (master) a cestu, kde sa projekt naklonuje. Teraz si uz mozem vyberat prave naklonovany Git Repository. V Wizard for project import vyberam Use the New Projects Wizard a postupujem analogicky ako v pripade, ked su subory na lokalnom disku.
  • Kedze uz pouzivam existujuci Makefile, tak v C/C++ Build -> Settings nie je potrebne (a ani nie je mozne) nic nastavovat, aj samotne polozky v menu su uz odlisne ako napr. v pripade simple ROOT project (Empty Project)
  • C/C++ General -> Path and Symbols -> Includes -> GNU C++ | Include directories pridat ${ROOTSYS}/include
  • C/C++ Build -> Behaviour v polozke Clean nastavit distclean, resp. pozriet do Makefile projektu STRELA, mozno taktiez nastavit potrebnu hodnotu Use parallel jobs
  • C/C++ General -> Path and Symbols -> Source Location kliknutim na Edit Filter mozem priamo nastavit Source Folder Exclusion Patterns, pre STRELA projekt napr.: tmp, lib, sql. Kedykolvek neskor mozem presne to iste urobit v okne Project Explorer, kliknutim myskou na potrebnu directory a nasledovne Resource Configurations -> Exclude From Build

GTK Theme

~/.gtkrc-2.0 spolocny pre vsetky progrmay, ktore vyuzivaju GTK2 theme (Firefox, Chrome, LibreOffice, Eclipse ...)

~/.gtkrc-eclipse-simple

style "eclipse-simple" {
       font_name = "Sans 9"
}
class "GtkWidget" style "eclipse-simple"
$ GTK2_RC_FILES=/usr/share/themes/Adwaita/gtk-2.0/gtkrc:~/.gtkrc-eclipse-simple /opt/eclipse/eclipse
$ GTK2_RC_FILES=~/.gtkrc-eclipse-simple /opt/eclipse/eclipse

create launcher

env GTK2_RC_FILES=/usr/share/themes/Adwaita/gtk-2.0/gtkrc:~/.gtkrc-eclipse-simple '/opt/eclipse/eclipse'

Eclipse CSS


/opt/eclipse-cpp-juno-M6/plugins/org.eclipse.platform_4.2.0.v20120315-1300/css/e4_default_gtk.css

.MPartStack {
       font-size: 11;
       swt-simple: false;
       swt-mru-visible: false;
}

Preferences

/home/musinsky/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings

  • Preferences su workspace specificke, t.j. ak vytvorim iny workspace, tak nastavenia sa zmenia, moznost Import/Export vsetkych (vratane plugin-ovskych) nastaveni: File -> Import/Export => General -> Preferences
  • Restore Defaults v preferences okne sa vztahuje ku konkretnemu typu nastavenia (len pre konkretne okno) a nie pre vsetky nastavenia
General
Appearance -> Label Decorations
C/C++ Indexed Files - zapnut
Compare/Patch | Text Compare
Connect ranges with single line - lepsie asi vypnut
Editors -> Text Editors
Insert spaces for tabs - neskor aj tak bude prepisane nastaveniami profilu (Tab policy: Spaces only)
Show print margin - zapnut a nastavit Print margin column na 120
Show line numbers - lepsie asi zapnut
C/C++ Code style/format
Editors -> Text Editors -> Quick Diff
Show differences in overview ruler - zapnut
Use this reference source - podla potreby Version on Disk pripadne A Git Revision
Editors -> Text Editors -> Spelling
Enable spell checking - vypnut
Workspace
Build automatically - pri vacsich projektoch lepsie asi vypnut
C/C++
Code Style
C/C++ Code style/format
Code Style -> Code Templates
TODO
Editor -> Folding
Enable folding when opening a new editor - zlucovanie/zoskupovanie macros/functions a pod. v editore zdrojoveho kodu
Header Comments - vypnut
Editor -> Templates
TODO


wget https://raw.github.com/gist/1095765/eclipse_custom.ini

wget https://raw.github.com/gist/1095765/profile_AliRoot.xml
# replace all "=" by "\="
sed 's/=/\\=/g' profile_AliRoot.xml > profile_AliRoot.tmp
# replace all 'end of line' by "\n"
sed -i ':a;N;$!ba;s/\n/\\n/g' profile_AliRoot.tmp
# append "...formatterprofiles"
echo "org.eclipse.cdt.ui/org.eclipse.cdt.ui.formatterprofiles="`cat profile_AliRoot.tmp` > profile_AliRoot.tmp

# insert 'profile_AliRoot.tmp' file in 'eclipse_custom.ini' file (after "formatter_profile" word)
sed -i '/formatter_profile/ r profile_AliRoot.tmp' eclipse_custom.ini

now start eclipse

$ eclipse -plugincustomization /opt/eclipse/eclipse_custom.ini

or add to eclipse.ini file

-Declipse.pluginCustomization=/opt/eclipse/eclipse_custom.ini
-showlocation

C/C++ Code style/format

It is now possible to format source code without starting the Eclipse UI using the new headless formatter application. The command line formatter works as a standard Eclipse application. The following command will format the source files in the folder src with the options specified in the org.eclipse.cdt.core.prefs file:

eclipse -nosplash -application org.eclipse.cdt.core.CodeFormatter -consoleLog \
        -verbose -config .settings/org.eclipse.cdt.core.prefs src/

Format ( Template:KeyPress ) zdrojoveho kodu je podstatny zasah da struktury textu, hrubo povedane sa upravuje "slovo za slovom" podla prednastavenych pravidiel. Correct Indentation ( Template:KeyPress ) v podstate iba zarovnava/osadzuje kazdy riadok zdrojoveho kodu, takisto podla prednastavenych pravidiel, ale zmeny v kode uz nie su na tolko rozsiahle.

Eclipse ma uz vstavany vlastny Code Style s roznymi profilmi (K&R, GNU, ...), avsak ten zasadne moze menit formu, strukturu zdrojoveho kodu. Aby sa priblizit k ROOT C++ Coding Conventions, resp. AliRoot Coding Conventions bolo by potrebne takyto profil zasadne zmenit, resp. ho vypnut, co vsak nie je (asi) mozne, preto potrebna zamena na Astyle Eclipse C/C++ formatter. Treba vsak priznat, ze ROOT C++ Coding Conventions pouziva znacne nestandardne formatovanie, vela C++ projektov (napr. Google C++ Style Guide alebo Geant 4) pouziva formatovanie, ktore ma podstatne blizsie k Eclipse Code Style - K&R profile.

  • Eclipse Code Style (K&R built-in profile)
+ : silny nastroj, detailne nastavenia roznych moznosti, je sucastou samotneho Eclipse
- : moze zasadne zmenit formatovanie zdrojoveho kodu (ak je v nesulade s vybranym profilom), nemoznost nastavenia ROOT C++ Coding Conventions
  • Astyle Eclipse C/C++ formatter
+ : nerobi zasadne zmeny pri formatovani kodu, moznost nastavenia v sulade s ROOT C++ Coding Conventions
- : nevyvija sa uz dalej (posledna verzia z 2006 roka), a s tym je aj spojene, ze plugin pouziva stary astyle 1.14.1 engine
- : stale sa bude pouzivat Correct Indentation, ktory je spojeny s editorom (built-in Eclipse), a ten je spojeny s built-in Code Style (K&R)

Pravdepodobne docasne pouzivat Astyle Eclipse C/C++ formatter a postupne prejst na standardizovany, moderny Eclipse Code Style - K&R profile

Indentation


wget http://gist.github.com/raw/991238/K\&R_mucha.xml
*https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbSoftwareTutorials

Indigo CDT Code Style: K&R [AliRoot] screenshots

Vychadzame z K&R [built-in] profilu, kedze ho budeme menit, musime si vytvorit svoj vlastny profil K&R [mucha]. Na zarovnavanie maju vplyv nastavenia v tychto polozkach:

Indentation
Tab policy: Spaces only
Indentation size: 2
Tab Size: 4
all other items default, except Statements within 'switch' body and Declarations within 'namespace' definition set as check
Braces
default (all Brace positions set as Same line)
New Lines
default
Line Wrapping
Maximum line width: 120 (does not affect on indent)
Default indentation for wrapped lines: 2
Default indentation for initializer lists: 2
Never join already wrapped lines uncheck
items with Default indentation change Indentation policy to Indent on column
Default indentationIndent on column
Expressions (6 items) - do not to change, except Initializer list set Indent by one

Eclipse Code Style (K&R built-in profile)

TODO

Control Statements
in 'if else' section all items set as check
Comments
Preserve white space between code and line comments if possible set check

Astyle Eclipse

Astyle Eclipse is based on Astyle program, it aims to provide a C/C++ formatter for CDT plugin in eclipse, so all the supported format optional shall check astyle.

  • Nema zmysel dalej pouzivat, vystaci len Eclipse Indentation, ktore je aj tak nezavisle od Astyle formatovania
  • Manualna instalacia (pre vsetkych uzivatelov)
$ su -
$ wget http://sourceforge.net/projects/astyleclipse/files/latest/download
$ unzip -x astyleclipse*.zip -d /opt/eclipse/
  • Pomocou Eclipse mechanizmu Help -> Install New Software pridame repository s Location http://astyleclipse.sourceforge.net/update. Plugin sa nainstaluje do user home dir ~/.eclipse/plugins/
  • ~/.astylerc
--indent=spaces=2

--one-line=keep-statements
--one-line=keep-blocks

Plugins

https://github.com/wangzw/CppStyle http://www.cppstyle.com/


Local Terminal (Incubation) 0.2.300.201307231220 (general purpose tool)


  • AnyEdit - AnyEdit plugin adds several new tools to the context menu of text- based Eclipse editors, to output consoles, to Eclipse main menu and editor toolbar. AnyEdit contributes also Import/Export working sets wizards
  • Jindent - Jindent is a powerful source code formatter for Java, C and C++ (heavy and ugly)
  • EditBox - Eclipse plugin for highlighting the background of the source code (works with Java code)
  • Eclipse Color Themes - Fresh up your Eclipse with super-awesome color themes!
  • Columns4Eclipse - Columns Plug-in for Eclipse defines the concept of 'Column' and some functions of this editable component. Functions such as copy, paste, cut, fill, lowercase, uppercase, search and replace are provided.
  • cppcheclipse - cppcheclipse is an Eclipse plugin which integrates cppcheck with the CDT project.
  • Linux Tools Project - The Linux Tools project aims to bring a full-featured C and C++ IDE to Linux developers
  • CMake Editor - The CMake Editor is a plug-in to the Eclipse IDE


new (temp)

wget http://gist.github.com/raw/1095765/Indigo_profile_AliRoot.xml
wget http://gist.github.com/raw/1095765/Indigo_preferences.epf
wget http://gist.github.com/raw/1095765/Indigo_bookmarks.xml



disable scrollbar overlay

export GTK_OVERLAY_SCROLLING=0

ano takto funguje, scroll bar uz "nemizne", ale pre vsetky scroll bars, a idealne by bolo len pre hlavny vertikalny, tak ako to funguje v dark theme

V pincipe je to otazka systemu (Fedora/GNOME) a nie samotneho eclipse


eclipse.ini

-Dswt.enable.themedScrollBar=true

a pre "Dark" themu (preferences->appearance->theme: dark) su nastavenie v subore

/opt/eclipse/plugins/org.eclipse.ui.themes_1.2.100.v20180302-1806/css/dark/e4-dark_globalstyle.css

napr. tu

swt-scrollbar-width: 24px;