cannot compile c code or use ld

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
sainsbm
Posts: 3
Joined: Sun Aug 09, 2009 7:26 am

cannot compile c code or use ld

Post by sainsbm »

Hi,
I am pretty new to microcoding, but I cant seem to get c code to compile using mingw. i am using the command line

Code: Select all

gcc (filename)
, but it always returns some sort of error, for example " 'u32int' undeclared" with the line:

Code: Select all

static void play_sound(u32int nFrequence) {
.
Also, I can't use the ld command in any way, it always returns: (filename).o unrecognised file format.
Thanks for any help!
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: cannot compile c code or use ld

Post by ru2aqare »

sainsbm wrote:Hi,
I am pretty new to microcoding, but I cant seem to get c code to compile using mingw. i am using the command line

Code: Select all

gcc (filename)
, but it always returns some sort of error, for example " 'u32int' undeclared" with the line:

Code: Select all

static void play_sound(u32int nFrequence) {
.
Also, I can't use the ld command in any way, it always returns: (filename).o unrecognised file format.
Thanks for any help!
Your C compiler reports an error because the identifier "u32int" has not been declared when it reaches the offending line. You need to provide a definition for it, for example

Code: Select all

# for msvc
typedef unsigned __int32 u32int;
# for gcc - i'm not sure
typedef unsigned int u32int;
sainsbm
Posts: 3
Joined: Sun Aug 09, 2009 7:26 am

Re: cannot compile c code or use ld

Post by sainsbm »

ru2aqare wrote:Your C compiler reports an error because the identifier "u32int" has not been declared when it reaches the offending line. You need to provide a definition for it, for example

Code: Select all

# for msvc
typedef unsigned __int32 u32int;
# for gcc - i'm not sure
typedef unsigned int u32int;
thanks, ill try that, but its a code sample from the wiki, i assumed they would define the datatypes they use...
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: cannot compile c code or use ld

Post by ru2aqare »

sainsbm wrote: thanks, ill try that, but its a code sample from the wiki, i assumed they would define the datatypes they use...
I don't think you're supposed to copy-paste code from any wiki and expect it to magically work...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: cannot compile c code or use ld

Post by Combuster »

I also think you are supposed to know the language you program in
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: cannot compile c code or use ld

Post by gravaera »

sainsbm wrote:
ru2aqare wrote:Your C compiler reports an error because the identifier "u32int" has not been declared when it reaches the offending line. You need to provide a definition for it, for example

Code: Select all

# for msvc
typedef unsigned __int32 u32int;
# for gcc - i'm not sure
typedef unsigned int u32int;
thanks, ill try that, but its a code sample from the wiki, i assumed they would define the datatypes they use...
This maybe a little off, but I think that sounded a little presumptious. You should be glad that something like an Operating System Development Wiki even exists. We're not exactly completely out of the dark ages of people sitting in dark, damp corners in basements chewing hard on pencils and tapping away at frustrating code without any support whatsoever.

It's interesting how people take stuff for granted. I remember being more than extraordinarily surprised to find a whole community of people offering resources to OSDevers.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Kitsune
Posts: 20
Joined: Wed Aug 05, 2009 7:13 pm

Re: cannot compile c code or use ld

Post by Kitsune »

sainsbm wrote:
ru2aqare wrote:Your C compiler reports an error because the identifier "u32int" has not been declared when it reaches the offending line. You need to provide a definition for it, for example

Code: Select all

# for msvc
typedef unsigned __int32 u32int;
# for gcc - i'm not sure
typedef unsigned int u32int;
thanks, ill try that, but its a code sample from the wiki, i assumed they would define the datatypes they use...
The code on the wiki is generally always just a snippet, given in a context to help you better understand the concept it's trying to convey, not in a context to be able to be simply dropped into a project.

Some of the tutorials will hold your hand the entire way, but a lot of them will make assumptions about what you already know.


(and for GCC it is indeed typdef unsigned int u32int;... you can simply drop that in a common header file and be fine)
sainsbm
Posts: 3
Joined: Sun Aug 09, 2009 7:26 am

Re: cannot compile c code or use ld

Post by sainsbm »

Kitsune wrote: Some of the tutorials will hold your hand the entire way, but a lot of them will make assumptions about what you already know.
(and for GCC it is indeed typdef unsigned int u32int;... you can simply drop that in a common header file and be fine)
Regarding the others first, Im sorry if I presumed too much of that code sample.
You see, I've gon through all the beginner tutorial's here, including the baby steps one, but I always get stuck after the "Hello World!" bootloaders when you start to integrate c code. gcc reports errors for anything I try to compile with the tutorials, and then ld always doesnt recognise .o files. It's just getting kinda frustrating cause Hello world is the limit I am able to compile!
To someone else: I used to do c++ and assumed that the syntax would be pretty similar (as long as you dont use advanced c++ things)

Sorry if I'm being dumb, and thanks for your help :)
Post Reply