Page 1 of 1

No type size_t?

Posted: Fri Jun 24, 2011 1:49 pm
by Lionel
Hello OS Developers, I'm Lionel, and I'm new to the forums.
I was following the Bran's Kernel Development Tutorial, and I got the first part of the tutorial done.(Creating start.asm and compiling it into kernel.bin). I build a cross compiler(i586-elf). The problem is when I try to compile the kernel with the file build.sh(start.asm is renamed boot.asm)...

Code: Select all

echo "Building Kernel..."
echo "Assembling..."
nasm -f aout -o boot.o boot.asm
echo "Compiling..."
i586-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c -o main.o main.c
echo "Linking output to kernel.bin"
ld -T link.ld -o kernel.bin boot.o main.o
echo "Finished Building Kernel!"
I get this:

Code: Select all

corwin@vinneticus:~/Desktop/iKatos$ ./build.sh
Building Kernel...
Assembling...
Compiling...
main.c:2:43: error: unknown type name 'size_t'
main.c:10:36: error: unknown type name 'size_t'
main.c:17:67: error: unknown type name 'size_t'
main.c:24:1: error: unknown type name 'size_t'
main.c: In function 'strlen':
main.c:26:5: error: unknown type name 'size_t'
main.c: At top level:
main.c:42:6: warning: return type of 'main' is not 'int' [-Wmain]
Linking output to kernel.bin
ld: cannot find main.o: No such file or directory
Finished Building Kernel!
I found size_t is in the file stddef.h , but gcc can't find it.
I don't know what to do, Could someone help me please?
~Lionel

Re: No type size_t?

Posted: Fri Jun 24, 2011 2:09 pm
by Tobba
Define it yourself, or possibly include stddef.h

When building your kernel, files arent automaticly included (because they would probably cause lots of issues)

Re: No type size_t?

Posted: Fri Jun 24, 2011 2:26 pm
by Lionel
I can't include stddef.h because it complains about there being duplicates of memcpy and other functions.

Re: No type size_t?

Posted: Fri Jun 24, 2011 2:44 pm
by Lionel
Yes, to Avoid Startup Code and os-dependent functions.
Edit: Now there is a new error that happens:

Code: Select all

main.c:2:7: error: conflicting types for 'memcpy'
system.h:5:23: note: previous declaration of 'memcpy' was here
main.c:10:7: error: conflicting types for 'memset'
system.h:6:23: note: previous declaration of 'memset' was here
main.c:17:17: error: conflicting types for 'memsetw'
system.h:7:24: note: previous declaration of 'memsetw' was here
main.c:24:14: error: conflicting types for 'strlen'
system.h:8:12: note: previous declaration of 'strlen' was here
main.c:42:6: warning: return type of 'main' is not 'int' [-Wmain]

Re: No type size_t?

Posted: Fri Jun 24, 2011 3:17 pm
by Solar
So? The error messages are pretty clear, aren't they?

One, what is this system.h?

Two, why do the types differ?

(Rethorical question warning.)

Re: No type size_t?

Posted: Fri Jun 24, 2011 3:26 pm
by bluemoon
If you ever want to work with gcc builtins you should define:

Code: Select all

typedef long unsigned int size_t;
This works on 32bit, using unsigned int you may get warning for incompatible memcpy and such.
I'm not sure for 64-bit size_t, perhaps unsigned long long..

Re: No type size_t?

Posted: Fri Jun 24, 2011 3:36 pm
by Lionel
Thanks bluemoon! I figured it out,. The tutorial code has differing types, and ubuntu doesn't like that. I made it work. Thank you everyone!

Re: No type size_t?

Posted: Fri Jun 24, 2011 3:54 pm
by Solar
berkus wrote:Do you know why you have built a cross-compiler?
Lionel wrote:The tutorial code has differing types, and ubuntu doesn't like that.
I.e., "no".

Re: No type size_t?

Posted: Fri Jun 24, 2011 4:01 pm
by bluemoon
Lionel wrote:Thanks bluemoon! I figured it out,. The tutorial code has differing types, and ubuntu doesn't like that. I made it work. Thank you everyone!
The blame is not to ubuntu.

gcc provide some useful built-ins like memcpy, when generate code it optimize and decided emit the build-in code, or to emit a library call.
so your fall-back version of the memcpy, etc should have exactly same prototype with the built-ins, otherwise gcc tell you a warning for such case.

So, to solve the problem you may:
1. write the function and types so they match exactly the builtin functions.
2. disable gcc builtin by -fno-builtin-memcpy or -fno-builtin (disable all builtin)
3. ignore the warnings and take your own risk.

Re: No type size_t?

Posted: Sat Jun 25, 2011 12:54 am
by Chandra
Lionel wrote:Yes, to Avoid Startup Code and os-dependent functions.
Edit: Now there is a new error that happens:

Code: Select all

main.c:2:7: error: conflicting types for 'memcpy'
system.h:5:23: note: previous declaration of 'memcpy' was here
main.c:10:7: error: conflicting types for 'memset'
system.h:6:23: note: previous declaration of 'memset' was here
main.c:17:17: error: conflicting types for 'memsetw'
system.h:7:24: note: previous declaration of 'memsetw' was here
main.c:24:14: error: conflicting types for 'strlen'
system.h:8:12: note: previous declaration of 'strlen' was here
main.c:42:6: warning: return type of 'main' is not 'int' [-Wmain]
I'm sure gcc generates a warning 'incompatible implicit declaration of built-in function '.....', if you try to use built-in functions without including the corresponding header files. So I believe the problem here is, either the function is being used without first declaring the function prototypes or, the function prototypes have been declared twice with incompatible types.