C++ Bare Bones: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
m Commented out unused variable to help avoid warning. Also, s/atomic/freestanding/ in the previous change description. :)
Don't pass controversial option that actually just causes problems, or are redundant.
Line 270:
The options for g++ are slightly more numerous than when building a C kernel.
 
<source lang="bash">i586-elf-g++ -o kmain.o -c kmain.cpp -Wall -Wextra -Werror \
-nostdlib -fno-builtinexceptions -nostartfiles fno-nodefaultlibsrtti \-fno-stack-protector
-fno-exceptions -fno-rtti -fno-stack-protector
</source>
 
Note: the flags -Wall -Wextra -Werror are not exactly required, but using them will certainly help you later on. They might seem to be a pest, but remember: The compiler is your friend!
 
Note #2: You may be able to use gcc instead of the i586-elf-gcc from the cross-compiler, but this does not work out of the box on at least Windows and 64-bit linux.
 
Note #3: The reasons for the disabling of exceptions, RTTI and the stack protector is because they usually require runtime support (which you in a basic kernel don't have). For a more thorough explanation, see the [[C++]] article. There is also an article about the [[GCC_Stack_Smashing_Protector|stack smashing protector]] if you want to enable -fstack-protector.
 
Note #4: The option -nostdlib is equivalent to passing both -nodefaultlibs and -nostartfiles. You just need to pass -nostdlib.
 
Note #5: Previous versions of this tutorial suggested passing the -fno-builtin option, but this is actually harmful as you most certainly want compiler builtins (without the __builtin_ prefix) as it lets the compiler understand your code better.
 
==linker.ld==