No type size_t?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

No type size_t?

Post 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
User avatar
Tobba
Posts: 21
Joined: Fri Mar 18, 2011 3:24 pm

Re: No type size_t?

Post 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)
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: No type size_t?

Post by Lionel »

I can't include stddef.h because it complains about there being duplicates of memcpy and other functions.
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: No type size_t?

Post 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]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: No type size_t?

Post 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.)
Every good solution is obvious once you've found it.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: No type size_t?

Post 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..
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: No type size_t?

Post 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!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: No type size_t?

Post 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".
Every good solution is obvious once you've found it.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: No type size_t?

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: No type size_t?

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Post Reply