Upload
leo-valentine
View
705
Download
0
Embed Size (px)
DESCRIPTION
c++ - Eclipse CDT
Citation preview
8/1/2014 c++ - Eclipse CDT C++11/C++0x support - Stack Overflow
http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support 1/6
Takethe2minutetour
Nick2,281 1 13 28
10Answers
Kazark2,453 3 14 44
CarstenGreiner1,401 1 6 14
Eclipse3.7.1CDT1.4.1GCC4.6.2
ThisisanexampleofapieceofC++11code:
autotext=std::unique_ptr(newchar[len])
TheEclipseeditorcomplainsabout:
Function'unique_ptr'couldnotberesolved
TheMakefilecompilationworksfine.HowtomakeEclipsestopcomplainingaboutthesesortoferrors?
c++ eclipse c++11 cdt
editedFeb6'12at7:44 askedFeb3'12at16:13
9 Attheveryleast,itshouldbe std::unique_ptrCubbiFeb3'12at16:16
Notsurethatiscorrectchar[]isconvertibletochar*andunique_ptrisapointertochar,likechar*Nick Feb3'12at16:24
1 Wouldn't unique_ptrcall delete,whichiswrongsinceitwascreatedwith new[]?DietrichEppFeb3'12at17:44
4 @Nick:No,he'sright.Thewayyouwroteitwillcause deletetobecalled,whenyouneed delete[]called.The unique_ptrassumesthatit'sgettingapointer,whichgetsdeletedwith delete.unique_ptrexpectsanarray,whichgetsdeletedwith delete[]correctly.NicolBolasFeb3'12at17:47
Related:stackoverflow.com/q/8889260/636019,stackoverflow.com/q/8763937/636019,stackoverflow.com/q/8564544/636019,stackoverflow.com/q/8312854/636019ildjarnFeb3'12at19:04
show3morecomments
IfoundthisarticleintheEclipseforum,justfollowedthosestepsanditworksforme.IamusingEclipseIndigo201106150604onWindowswithaCygwinsetup.
MakeanewC++projectDefaultoptionsforeverythingOncecreated,rightclicktheprojectandgoto"Properties"C/C++Build>Settings>ToolSettings>GCCC++Compiler>Miscellaneous>OtherFlags.Putstd=c++0xattheend....insteadofGCCC++CompilerIhavealsoCygwincompilerC/C++General>PathsandSymbols>Symbols>GNUC++.Click"Add..."andpaste__GXX_EXPERIMENTAL_CXX0X__(ensuretoappendandprependtwounderscores)into"Name"andleave"Value"blank.HitApply,dowhateveritasksyoutodo,thenhitOK.
ThereisadescriptionofthisintheEclipseFAQnowaswell:EclipseFAQ/C++11Features.
editedDec19'12at23:16 answeredFeb3'12at20:33
2 @EdHnottrue.CDThasitsownc++parser.thanksgodJohannesSchaublitbFeb4'12at21:53
2 Yey,itworked!But,makesuretoprepend&appendtwounderscorestoGXX_EXPERIMENTAL_CXX0XI
StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.It's100%free,noregistrationrequired.
EclipseCDTC++11/C++0xsupport
signup
login
tour
help
careers2.0
8/1/2014 c++ - Eclipse CDT C++11/C++0x support - Stack Overflow
http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support 2/6
communitywiki14revsJohanLundberg
willacceptthisinthemeantime Nick Feb6'12at7:49
3 Didthisremovespuriouseditorerrors?Ihavenoproblemwithcompiling,andnewstdtypesarerecognised,butIcan'tgetridofeditorsyntaxerrorsforrangebasedforloopsandrvaluereferences &&.juanchopanzaMay3'12at13:09
3 Thenaturalfollowupquestionnowbecomes:canweoptimizeourworkflowbysavingthesespecificC++ProjectSettingsintoanewEclipseProjecttemplatesay"C++11Project"?NordlwMay21'12at21:34
19 Note:foranyonelookingfortheanswerforJuno,thisdoesnotwork .ChristopherDec31'12at16:37
show10morecomments
There'snowanewwaytosolvethiswithouttheGXX_EXPERIMENTALhack.
Formostrecentversions:(CurrentlyJunoandKepler):
UndernewerversionsofJunothesettingsarelocatedat Projectpropierties>C/C++General>PreprocessorIncludePaths,Macrosetc.>tabProviders>CDTGCCBuiltinCompilerSettings().
Olderversions2012/2013:
1. UnderC/C++Build(atprojectsettings),findthePreprocessorInclude PathandgototheProvidersTab.DeselectallexceptCDTGCCBuiltinCompilerSettings.ThenuntagSharesettingsentries.Addtheoptionstd=c++11tothetextboxcalledCommandtogetcompilerspecs.
2. Gotopathsandsymbols.UnderSymbols,clickrestoredefaults,andthenapply.
Notes:
Eclipseispickyabouthittingapply,youneedtodoiteverytimeyouleaveasettingstab.
[Selfpromotion]:Iwrotemyownmoredetailedinstructionsbasedontheabove.http://scrupulousabstractions.tumblr.com/post/36441490955/eclipsemingwbuilds
Thankstotheuser Nobodyathttp://stackoverflow.com/a/13635080/1149664
editedNov29'13at19:24
2 Thankyoubutitdidn'thelpmetosolvec++11references.Programcompilescorrectly,buteclipsecannotresolvethem.WhenIcheck"array", #ifndef__GXX_EXPERIMENTAL_CXX0X__returnstrueandcodebelowitisnotparsed.WhenIadd __GXX_EXPERIMENTAL_CXX0X__toprojectsymbols,arraygetsresolvedbutmyproject'sreferencesgetsmessedup.Whatmightbetheproblemhere?HalilKaskavalciDec20'12at16:10
Notsurewhatyoumeanbycheckarray.Didyoutrytofollowtheinstructionsonmyblog?JohanLundbergDec20'12at16:22
1 Ithinkitisabug.Ireproduceditlikethis:Opennewproject.Enablec++11features.Addarandomclasswithapublicvariable.Createvectorofthisrandomclass.Gettheiterator.Trytoaccesspublicvariable.EithermyworkspaceiscorruptedorthereisabuginEclipsethatcannotparsethis.HalilKaskavalciDec20'12at17:00
1 @HalilKaskavalciIfoundthissamebug.IfIsettheeditorforc++11,iteratorscan'tresolve.IfIdon't,std::unique_ptrcan'tresolve.Reallyannoying,sinceIuseboth.KianDec20'12at22:24
1 @KianIreportedthebug.bugs.eclipse.org/bugs/show_bug.cgi?id=397027.ItisquiteannoyingandIstartedtouseboostlibraries,theydon'tproducetheerror:)HalilKaskavalciDec20'12at23:19
show7morecomments
Forthelatest(Juno)eclipsecdtthefollowingworkedforme,noneedtodeclare__GXX_EXPERIMENTAL_CXX0X__onmyself.ThisworksforthetheCDTindexerandasparameterforthecompiler:
"yourprojectname">rightclick>properties:
C/C++General>PreprocessorIncludePaths,Macrosetc.>switchtothetabnamed"Providers":
for"Configuration"select"Release"(andafterwards"debug")
8/1/2014 c++ - Eclipse CDT C++11/C++0x support - Stack Overflow
http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support 3/6
Andreas160 1 6
ravwojdyla465 4 6
switchoffallprovidersandjustselect"CDTGCCBuiltinCompilerSettings"
uncheck"Sharesettingentriesbetweenprojects(globalprovider)"
inthe"Commandtogetcompilerspecs:"add"std=c++11"withoutthequotes(mayworkwithquotestoo)
hitapplyandclosetheoptions
rebuildtheindex
Nowallthec++11relatedstuffshouldberesolvedcorrectlybytheindexer.
win7x64,latestofficialeclipsewithcdtmingww64gcc4.7.2fromthemingwbuildsprojectonsourceforge
answeredMar10'13at11:34
stillgettingsameerroneouseditorwarnings,asinType'std::thread'couldnotberesolvedeventhoughitcompilesandexecutesOKScottStenslandMay31'13at11:27
uneedtocompileoncewiththenewsettings,sotheparserwill"learn"thatthestd=c++11flagissetAndreasJun11'13at9:16
Ican'tyetcommentsoamwritingmyownanswer:
It'srelatedto __GXX_EXPERIMENTAL_CXX0X__andit'svalidforEclipseJunoandCDT8.x.
SomepartsofthisanswerarealreadycoveredinotheranswersbutIwantittobecoherent.
Tomakeitpossibletobuildusingstdc++11,onehavetoaddspecificflagforcompiler.Youcandothatviaprojectproperties.Tomodifyprojectproperties RMBand Projectpropertiesor ALT+ENTER.ThenC/C++Build>Settings>ToolSettings>GCCC++Compiler>Miscellaneous>OtherFlags.Putstd=c++11attheendofline,forGCCitwilllooksomethinglike: cfmessagelength=0std=c++11.Byaddingstdc++11flagcompiler(GCC)willdeclare __GXX_EXPERIMENTAL_CXX0X__byitself.
AtthispointyoucanbuildprojectusingallthegoodnessofC++11.
TheproblemisthatEclipsehasit'sownparsertocheckforerrorsthat'swhyyou'restillgettingallthenastyerrorsinEclipseeditor,whileatthesametimeyoucanbuildandrunprojectwithoutany.Thereisawaytosolvethisproblembyexplicitlydeclaring __GXX_EXPERIMENTAL_CXX0X__flagfortheproject,onecandothat(justlikeCarstenGreinersaid):C/C++General>PathsandSymbols>Symbols>GNUC++.Click"Add..."andpast __GXX_EXPERIMENTAL_CXX0X__(ensuretoappendandprependtwounderscores)into"Name"andleave"Value"blank.AndnowistheextrapartIwantedtocoverincommenttothefirstanswer,goto:C/C++General>PreprocessorIncludePathMacrosetc.>Providers,andSelect CDTManagedBuildSettingEntriesthenclickAPPLYandgobacktoEntriestab,underGNUC++thereshouldbenowCDTManagedBuildSettingEntriescheckifinsidethereisdefined __GXX_EXPERIMENTAL_CXX0X__ifitis>APPLYandrebuildindexyoushouldbefineatthispoint.
answeredFeb26'13at20:23
ForEclipseCDTKeplerwhatworkedformetogetridofstd::threadunresolvedsymbolis:
1. GotoPreferences>C/C++>Build>Settings
2. SelecttheDiscoverytab
3. SelectCDTGCCBuiltinCompilerSettings[Shared]
4. Addthestd=c++11tothe"Commandtogetthecompilerspecs:"fieldsuchas:
${COMMAND}EPvdDstd=c++11${INPUTS}
1. OkandRebuildIndexfortheproject.
Addingstd=c++11toprojectProperties/C/C++Build>Settings>ToolSettings>GCCC++Compiler>Miscellaneous>OtherFlagswasn'tenoughforKepler,howeveritwasenoughforolderversionssuchasHelios.
answeredFeb24at23:33
addacomment
addacomment
8/1/2014 c++ - Eclipse CDT C++11/C++0x support - Stack Overflow
http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support 4/6
user334891551 1 1
Trismegistos588 3 12
InstructionForEclipseCDT4.4Luna
First,beforecreatingproject,configureEclipsesyntaxparser:
Window> Preferences> C/C++> Settings> Discovery> CDTGCCBuildinCompilerSettings
inthetextboxentitled Commandtogetcompilerspecsappend std=c++11
Nowyoucancreateproject,configurationdependsonwhatkindofprojectyoucreated:
Forprojectcreatedas:File>New>Project>C/C++>C++Project
Rightclickoncreatedprojectandopen
Properties> Settings> ToolSettings> GCCC++Compiler> Dialect
put std=c++11intotextboxentitled otherdialectflags
ForCMakeproject
Generateeclipseprojectfiles
cmakeG"EclipseCDT4UnixMakefiles"DCMAKE_BUILD_TYPE=Debug..
Thenimportgenerateddirectorytoeclipseasstandardeclipseproject.Rightclickprojectandopen
Properties> C/C++General> PreprocessorIncludePaths,Marcosetc.>Providers
enable CDTGCCBuildinCompilerSettingsandmoveithigherthen ContributedPathEntryContainers(Thisisimportant)
LastCommonStep
recompile,reganerate Project> C/C++IndexandrestartEclipse.
editedJul3at20:20 answeredJul3at19:12
Ihadseveralissuestoo(Ubuntu13.0464bit,g++4.8,eclipseJuno3.8.1,CDT6.0.0).Alotofthingsarementionedabove,sorrytorepeatthose,butadditionallyIhadproblemsutilizing
std::thread
aspartofc++11(addingpthreadforthelinkersolvesthatissue).Anyway,finallythesesettingsworkedfine:
Project>Properties>C/C++Build>Settings>Miscellaneous.Addthe
std=c++11
flagfortheGCCandG++compilers.ClickApply.
Forthelinker,samewindow,Miscellaneous,Linkerflags,addedthe
pthread
flag.Sharedlibrarysettings,Sharedobjectname,addthe
Wl,noasneeded
flagtoo.ClickApply.
C/C++General>Pathsandsymbols>SymbolsTAB,GNUC++selected,Addthe
addacomment
addacomment
8/1/2014 c++ - Eclipse CDT C++11/C++0x support - Stack Overflow
http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support 5/6
OlaAronsson21 2
Jerk3199 8
SameeraChanaka1
__GXX_EXPERIMENTAL_CXX0X__
(novalue)
flag.ClickApply.
C/C++General>PreprocessorIncludepaths..>Providerstab:check
CDTGCCbuiltinCompilerSettings
andfor"Commandtogetcompilerspecs",addthe
std=c++11
flag.UncheckShare.ClickApply.
CDTManagagesBuildSettingEntries,checkthistoo.Uncheckthetwoothers.ClickApply.
GoingbacktotheEntriestab,GNUC++CDTManagagesBuildSettingEntries,youshouldnowseeyouradded
__GXX_EXPERIMENTAL_CXX0X__
entry.
That'sit.Whencoding,typing
std::
cannowautocompletethethreadclassforinstance,buildsshouldworkfineandthereshouldbeno
std::system_error'what():Enablemultithreadingtousestd::thread:Operationnotpermitted
atruntime.
editedJan25at22:52 answeredJan25at22:42
Itwasthe Project>Properties>C/C++Build>Settings>Miscellaneousstepthatworkedforme.Thanksabunch:DJake88Feb14at16:19
IhadthesameproblemonmyEclipseJuno.Thesestepssolvedtheproblem:
Goto Project>Properties>C/C++General>PathandSymbols>Tab[Symbols].Addthesymbol:__cpluspluswiththevalue201103L
answeredMar8at17:21
rightclicktheprojectandgoto"Properties"C/C++Build>Settings>ToolSettings>GCCC++Compiler>Miscellaneous>OtherFlags.PutlmattheendofotherflagstextboxandOK.
answeredJul25'13at1:21
WhatversionofEclipseisthis?BraiamJul25'13at1:45
NeitherthehacknorthecleanerversionworkforIndigo.Thehackisignored,andtherequiredconfigurationoptionsaremissing.Fornoapparentreason,buildstartedworkingafternotworkingandnotprovidinganyusefulreasonwhy.Atleastfromthecommandline,Igetreproducibleresults.
addacomment
addacomment
addacomment
8/1/2014 c++ - Eclipse CDT C++11/C++0x support - Stack Overflow
http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support 6/6
JerryMiller109 1 5
answeredMay5at16:36
Nottheansweryou'relookingfor?Browseotherquestionstagged c++ eclipse
c++11 cdt oraskyourownquestion.
addacomment