g++faq.texi

来自「GCC编译器源代码」· TEXI 代码 · 共 1,691 行 · 第 1/5 页

TEXI
1,691
字号
@node repository, repo bugs, shared libraries, installation@section How do I use the new repository code?@cindex repo patchBecause there is some disagreement about the details of the templaterepository mechanism, you'll need to obtain a patch from Cygnus Supportto enable the 2.7.2 repository code.  You can obtain the patch byanonymous FTP: @file{ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz}.There are patches for 2.7.0 and 2.7.1 in the same directory, thoughif you're going to rebuild the compiler you should use the latest one.@cindex repo patch for BSDIf you're running NetBSD or BSDI, the Cygnus repo patch is not quitecorrect.  Tim Liddelow has made an alternate version available at@file{ftp://ftp.cst.com.au/pub/gcc-2.7.2-repo-bsd.gz}.After you've applied the patch, the @code{-frepo} flag will enable therepository mechanism.  The flag works much like the existing@code{-fno-implicit-templates} flag, except that auxiliary files, withan @file{.rpo} extension, are built that specify what templateexpansions are needed.  At link time, the (patched) collect programdetects missing templates and recompiles some of the object filesso that the required templates are expanded.Note that the mechanism differs from that of cfront in that templatedefinitions still must be visible at the point where they are to beexpanded.  No assumption is made that @file{foo.C} contains templatedefinitions corresponding to template declarations in @file{foo.h}.@cindex closure with repo@cindex template closureJason Merrill writes: ``To perform closure on a set of objects, just tryto link them together.  It will fail, but as a side effect all neededinstances will be generated in the objects.''@node repo bugs, Use GNU C library?, repository, installation@section Known bugs and problems with the repo patch``The @code{-frepo} won't expand templated friend functions!''This is a known bug; currently you'll have to explicitly instantiatefriend functions when using @code{-frepo} due to this bug (in 2.7.0through 2.7.2 at least).With earlier versions of the repo patch, there was a bug that happenswhen you have given a quoted command line switch, something like@example-D'MESSAGE="hello there"'@end exampleThe repo code tries to recompile files using the same flags youoriginally specified, but doesn't quote arguments that need quoting,resulting in failures in some cases.  This is no longer a problemwith the 2.7.2 patch.@node Use GNU C library?, Global constructor problems, repo bugs, installation@section Should I use the GNU C library?@cindex GNU C library@cindex libg++At this point in time, no (unless you are running Linux or the GNU Hurdsystem).  The GNU C library is still very young, andlibg++ still conflicts with it in some places.  Use your native C libraryunless you know a lot about the gory details of libg++ and gnu-libc.  Thiswill probably change in the future.@node Global constructor problems, Strange assembler errors, Use GNU C library?, installation@section Global constructors aren't being called@cindex global constructors``I've installed gcc and it almost works, but constructors anddestructors for global objects and objects at file scope aren't beingcalled.  What did I do wrong?''@cindex collect programIt appears that you are running on a platform that requires you toinstall either "collect2" or the GNU linker, and you have done neither.For more information, see the section discussing the GNU linker(@pxref{use GNU linker?}).@cindex constructor problems on Solaris@cindex Solaris, constructor problemsOn Solaris 2.x, you shouldn't need a collect program and GNU ld doesn't run.If your global constructors aren't being called, you may need to installa patch, available from Sun, to fix your linker.  The number of the``jumbo patch'' that applies is 101409-03.  Thanks to Russell Street(r.street@@auckland.ac.nz) for this info.@cindex IRIX, installing collectIt appears that on IRIX, the collect2 program is not being installedby default during the installation process, though it is required;you can install it manually by executing@examplemake install-collect2@end examplefrom the gcc source directory after installing the compiler.  (I'mnot certain for which versions of gcc this problem occurs, and whetherit is still present).@node Strange assembler errors, Other problems building libg++, Global constructor problems, installation@section Strange assembler errors when linking C++ programs``I've installed gcc and it seemed to go OK, but when I attempt to linkany C++ program, I'm getting strange errors from the assembler!  Howcan that be?''The messages in question might look something like@exampleas: "/usr/tmp/cca14605.s", line 8: error: statement syntaxas: "/usr/tmp/cca14605.s", line 14: error: statement syntax@end example(on a Sun, different on other platforms).  The important thing is thatthe errors come out at the link step, @emph{not} when a C++ file isbeing compiled.@cindex nm program@cindex GNU nm programHere's what's going on: the collect2 program uses the Unix ``nm''program to obtain a list of symbols for the global constructors anddestructors, and it builds a little assembly language module thatwill permit them all to be called.  If you're seeing this symptom,you have an old version of GNU nm somewhere on your path.  This oldversion prints out symbol names in a format that the collect2 programdoes not expect, so bad assembly code is generated.The solution is either to remove the old version of GNU nm from yourpath (and that of everyone else who uses g++), or to install a newerversion (it is part of the GNU "binutils" package).  Recent versionsof GNU nm do not have this problem.@node Other problems building libg++, More size_t problems, Strange assembler errors, installation@section Other problems building libg++@cindex libg++ on Ultrix@cindex libg++ on SunOS``I am having trouble building libg++.  Help!''On some platforms (for example, Ultrix), you may see errors complainingabout being unable to open dummy.o.  On other platforms (for example,SunOS), you may see problems having to do with the type of size_t.The fix for these problems is to make libg++ by saying "make CC=gcc".According to Per Bothner, it should no longer be necessary to specify"CC=gcc" for libg++-2.3.1 or later.``I built and installed libg++, but g++ can't find it.  Help!''The string given to @file{configure} that identifies your system mustbe the same when you install libg++ as it was when you installed gcc.Also, if you used the @code{--prefix} option to install gcc somewhereother than @file{/usr/local}, you must use the same value for@code{--prefix} when installing libg++, or else g++ will not be ableto find libg++.@cindex patch for libg++-2.6.2The toplevel Makefile in the libg++ 2.6.2 distribution is broken, whichalong with a bug in g++ 2.6.3 causes problems linking programs that use thelibstdc++ complex classes.  A patch for this is available from@file{ftp://ftp.cygnus.com//pub/g++/libg++-2.6.2-fix.gz}.@node More size_t problems, Rebuild libg++?, Other problems building libg++, installation@section But I'm @emph{still} having problems with @code{size_t}!@cindex Type of size_t``I did all that, and I'm @emph{still} having problems with disagreeingdefinitions of size_t, SIZE_TYPE, and the type of functions like@code{strlen}.''@cindex _G_config.hThe problem may be that you have an old version of @file{_G_config.h}lying around.  As of libg++ version 2.4, @file{_G_config.h}, since it isplatform-specific, is inserted into a different directory; most includefiles are in @file{$prefix/lib/g++-include}, but this file now lives in@file{$prefix/$arch/include}.  If, after upgrading your libg++, you find thatthere is an old copy of @file{_G_config.h} left around, remove it,otherwise g++ will find the old one first.@node Rebuild libg++?, co-existing versions, More size_t problems, installation@section Do I need to rebuild libg++ to go with my new g++?``After I upgraded g++ to the latest version, I'm seeing undefinedsymbols.''or``If I upgrade to a new version of g++, do I need to reinstall libg++?''@cindex Incompatibilities between g++ versionsAs a rule, the first two digits of your g++ and libg++ should be thesame.  Normally when you do an upgrade in the ``minor version number''(2.5.7 to 2.5.8, say) there isn't a need to rebuild libg++, but therehave been a couple of exceptions in the past.@node co-existing versions, Installing on Linux, Rebuild libg++?, installation@section I want several versions of g++ and libg++ to co-exist.I recommend against using the @code{-V} flag to make multiple versionsof gcc/g++ co-exist, unless they are different minor releases that can usethe same compiled version of libg++.  The reason is that all theseversions will try to use the same libg++ version, which usually willnot work.Instead, use the @code{--prefix} flag when configuring gcc.  Use adifferent value of @code{--prefix} for each gcc version.  Use thesame value of @code{--prefix} when configuring libg++.  You can thenhave any number of co-existing gcc/libg++ pairs.  Symbolic links canbe used so that users don't need to put all these different directorieson their paths.One possible system to use is to set @code{--prefix} to@file{/usr/local/gcc-2.x.y} for version 2.x.y of gcc, and to linkwhichever version of gcc you wish to be the default into@file{/usr/local/bin/gcc} and @file{/usr/local/bin/g++}.@node Installing on Linux, Linux Slackware 3.0, co-existing versions, installation@section Trouble installing g++ and libg++ on Linux``I've downloaded the latest g++ and libg++ and I'm trying to installthem on Linux, and I'm having lots of problems.''@cindex LinuxFSF releases of libg++ won't install on Linux unchanged, since Linuxuses are part of the libio library from libg++ for its standard Clibrary, only this is changed in a way that it clashes with libg++.This means that you'll need a patched version of libg++ for it towork.If you want to upgrade to a new gcc/libg++ combination, the easiestthing to do is to grab the prebuilt versions of gcc and libg++ for Linuxfrom @file{ftp://tsx-11.mit.edu/pub/linux/packages/GCC}.  Follow thedirections carefully.  If you want to build from source, you'll needa patch for libg++; the Linux developers have named the patched libg++version libg++-2.7.1.3 and there is a patch file in the above-nameddirectory.See @file{http://sunsite.unc.edu/LDP/HOWTO/GCC-HOWTO.html},the Linux GCC HOWTO, for more on gcc/g++ and Linux.Linux is in the process of switching over to the GNU C library, version2, which will become Linux libc version 6.  Once this process iscomplete, there's a good chance that the installation process on Linuxwill be smoother, but only experts should try making this new librarywork at this point.@node Linux Slackware 3.0,  , Installing on Linux, installation@section Problems with g++ on Linux Slackware 3.0@cindex Slackware@cindex Linux Slackware``When I try to compile the traditional Hello, world program on Linux,the compiler can't find @file{iostream.h}.  What's the deal?''You probably have the Slackware 3.0 release.  There's an error in thesetup.  It's easy to fix, though; log in as root, and make a symboliclink:@exampleln -s /usr/lib/g++-include /usr/include/g++@end example@node evolution, User Problems, installation, Top@chapter The Evolution of g++This chapter discusses the evolution of g++ and describes what can be expectedin the future.@menu* version 2.7.x::               What's changed in 2.7.x from earlier versions* libstdc++::                   The GNU C++ standard library* new work::                    What's been done since 2.7.x* egcs::                        The Experimental GNU Compiler System* When?::                       When can I get all this new stuff?@end menu@node version 2.7.x, libstdc++, evolution, evolution@section What's new in version 2.7.x of gcc/g++The current version of gcc/g++ is 2.7.2.2, released February 10, 1997.The only change between 2.7.2.1 and 2.7.2.2 is that support was addedfor using the GNU C library, version 2, on Linux; users not interestedin that functionality have no reason to upgrade.The previous version of gcc/g++ is 2.7.2.1, released August 14, 1996.The current version of libg++ is 2.7.2, released July 4, 1996.Note that gcc 2.7.2.1 just consists of several small patches togcc-2.7.2.  The release is mainlyintended to fix platform-specific bugs and does not affect the C++``front end'' of the compiler (the part that parses your C++ code).The 2.7.x releases represent a great deal of work on the part of the g++maintainers to fix outstanding bugs and move the compiler closer to thecurrent ANSI/ISO standards committee's working paper, includingsupporting many of the new features that have been added to thelanguage.  I recommend that everyone read the NEWS file contained in thedistribution (and that system administrators make the file available totheir users).  I've borrowed liberally from this file here.@cindex C++ working paperIf any features seem unfamiliar, you will probably want tolook at the recently-released public review copy of the C++ WorkingPaper.  A new draft, dated 2 December 1996, has been released forpublic comment.  You can find it on the web at@file{http://www.cygnus.com/misc/wp/} or@file{http://www.maths.warwick.ac.uk/c++/pub/wp/html/cd2/}.See@file{http://www.setech.com/x3.html}or@file{http://www.maths.warwick.ac.uk/c++/pub/} to download thedocument in PostScript, PDF (Adobe Acrobat), HTML, or ASCIIform.Here are the main points:@itemize @bullet@item@cindex for scopeAs described above, the scope of variables declared in theinitialization part of a for statement has been changed; such variablesare now visible only in the loop body.  Use @code{-fno-for-scope} to getthe old behavior.  You'll need this flag to build groff version 1.09,Ptolemy, and many other free software packages.@item@cindex vtable duplicationCode that does not use #pragma interface/implementation will mostlikely shrink dramatically, as g++ now only emits the vtable for aclass in the translation unit where its first non-inline, non-abstractvirtual function is defined.@item@cindex automatic template instantiationSupport for automatic template instantiation has @emph{not} been enabled

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?