werid problem gcc?

Programming, for all ages and all languages.
Post Reply
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

werid problem gcc?

Post by Sam111 »

I am compiling this sound file sound.c
with

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c
but I am getting this

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c
In file included from <command line>:1:
c:/djgpp/lib/gcc-lib/djgpp/3.1/djgpp.ver:1:25: no include path in which to find
sys/version.h
sound.c: In function `play_sound':
sound.c:25: warning: implicit declaration of function `outb'
sound.c:30: warning: implicit declaration of function `inb'
sound.c:50:1: warning: no newline at end of file
when I don't include this -nostdinc It works fine an generates the .o file.

What I don't get is what this sys/version.h is and why I need it
This is for a kernel so I don't want to include any libraries that depend on anything just me own.

The sound file is this

Code: Select all


void sound();
static void play_sound(long int) ;
static void nosound();
void beep() ;

void sound()
{
int i = 1 ;
while( i == 1 )
{
beep() ;
}

}


 //Play sound using built in speaker
 static void play_sound(long int nFrequence) {
 	long int Div;
 	unsigned char tmp;
 
        //Set the PIT to the desired frequency
 	Div = 1193180 / nFrequence;
 	outb(0x43, 0xb6);
 	outb(0x42, (unsigned char) (Div) );
 	outb(0x42, (unsigned char) (Div >> 8));
 
        //And play the sound using the PC speaker
 	tmp = inb(0x61);
  	if (tmp != (tmp | 3)) {
 		outb(0x61, tmp | 3);
 	}
 }
 
 //make it shutup
 static void nosound() {
 	unsigned char tmp = (inb(0x61) & 0xFC);
 
 	outb(0x61, tmp);
 }
 
 //Make a beep
 void beep() {
 	 play_sound(1000);
 	 //timer_wait(10);
 	 nosound();
          //set_PIT_2(old_frequency);
 }
 
User avatar
KotuxGuy
Member
Member
Posts: 96
Joined: Wed Nov 25, 2009 1:28 pm
Location: Somewhere within 10ft of my favorite chubby penguin!

Re: werid problem gcc?

Post by KotuxGuy »

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c
Well, first of all, you did not give an #include for GCC to search for the outb and inb function prototypes.
Secondly, I think you should add the -nostartfiles option, as that should eliminate the sys/version.h stuff.

Thirdly, I don't mean to be mean ( :D ) or anything, but if you don't know what those options are, you need to study GCC's options, not copy-paste wiki code.
Give a man Linux, you feed the nearest optician ( Been staring at the PC too long again? ).
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory :D )
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: werid problem gcc?

Post by Sam111 »

Well the nostartfiles option didn't work?

And My problem is I don't know why I need to include this file it is not one of my includes?
And I don't know why the compiler would even complain about this.

Second I know how to include libraries and files using gcc ,...etc that is not my problem....

third of all I cleared up the inb, outb implicity stuff that wasn't my problem
This is
no include path in which to find
sys/version.h
I am sure I can include it but I really don't want to if I don't have to because if it depends on something else I am screwed.
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: werid problem gcc?

Post by Sam111 »

This doesn't seem to work either

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -I C:\djgpp\include\sys\version.h -c sound.c
it gives me this

Code: Select all

The system cannot execute the specified program.
So I must be typing something in wrong but the path is C:\djgpp\include\sys\version.h
but I am in C:\KERNEL~1 if I have to use ..\ before or something #-o

I mean I can get rid of all this be using gcc -c sound.c
however I would like to use the switches -nostdlib ,...etc if possible and just include that one include if I even need it.

Or maybe their is a way to tell djpgg not to need the sys/version
User avatar
KotuxGuy
Member
Member
Posts: 96
Joined: Wed Nov 25, 2009 1:28 pm
Location: Somewhere within 10ft of my favorite chubby penguin!

Re: werid problem gcc?

Post by KotuxGuy »

you wrote: I don't know why the compiler would even complain about this.
Because it cannot find the function prototypes. Honestly, you should know this..
you also wrote:This doesn't seem to work either

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -I C:\djgpp\include\sys\version.h -c sound.c
That's because the -I option adds a directory, not a file. Look at the GCC manual!
Plus, look at that version.h file and see what it has in it.
Give a man Linux, you feed the nearest optician ( Been staring at the PC too long again? ).
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory :D )
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: werid problem gcc?

Post by Combuster »

djgpp/3.1
Seriously, get rid of that. That's meant for DOS and that version is nearly a decade old. Use a GCC Cross-Compiler instead.
"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
KotuxGuy
Member
Member
Posts: 96
Joined: Wed Nov 25, 2009 1:28 pm
Location: Somewhere within 10ft of my favorite chubby penguin!

Re: werid problem gcc?

Post by KotuxGuy »

Well, maybe he's using DOSBox, or something. Why would he do that, I dunno.
But we'll never know if he doesn't tell us, will we? :lol:
Give a man Linux, you feed the nearest optician ( Been staring at the PC too long again? ).
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory :D )
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: werid problem gcc?

Post by Sam111 »

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -I C:\djgpp\include\sys\version.h -c sound.c
I changed it to -I C:\djgpp\include\sys\ not working anyway I have even tried the -L switch that didn't work.

version.h has this in it

Code: Select all

/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */

#undef DJGPP
#undef __DJGPP
#undef __DJGPP__

#define DJGPP 2
#define __DJGPP 2
#define __DJGPP__ 2

#undef DJGPP_MINOR
#undef __DJGPP_MINOR
#undef __DJGPP_MINOR__

#define DJGPP_MINOR 3
#define __DJGPP_MINOR 3
#define __DJGPP_MINOR__ 3

That is all their is in it
when I temporary copy the version.h to my folder it works.

But then when I link
ld -T link.ld sound.o load2.o
I get this error

Code: Select all

load2.o(.text+0x48): relocation truncated to fit: 16 .text
my link.ld is this

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(main)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
I just don't see where this error is occuring and why it is exceeding the space .....
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: werid problem gcc?

Post by Brynet-Inc »

As you've been told repeatedly, you're using the functions inb/outb() without providing your own implementation.. djgpp generously provides inline versions in that header file.

This is quite obvious, clearly you do not have the required knowledge.. or the ability to apply some common sense.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: werid problem gcc?

Post by Sam111 »

no that is not my problem in my sound.c
I have

Code: Select all

unsigned char inb (unsigned short _port)
{
    unsigned char rv;
    __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
    return rv;
}

void outb (unsigned short _port, unsigned char _data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

My problem is I cann't get rid of the requirement of sys\version.h
And if I compile with gcc -c sound.c => when I try to link with my linker script I get this truncation error.
So I don't understand 2 thing where in the linker script it is doing truncation and why.
And how to get rid of this header file thing?
Also I don't want to do just gcc -c filename.c because I know it will probably include stuff I cann't use in the kernel.

I am sorry but I am learning and need a little help
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: werid problem gcc?

Post by Sam111 »

Ok , this did it

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c -I../djgpp/include
turns out I didn't know the correct way to do up a directory
your not supposed to have ../C: just ../djgpp

but I am still getting
this

Code: Select all

C:\KERNEL~1>ld -T link.ld sound.o load2.o
load2.o(.text+0x48): relocation truncated to fit: 16 .text
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: werid problem gcc?

Post by Sam111 »

Never mind I cleared that up as well.
thanks for the help
Post Reply