LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-27-2013, 11:53 AM   #1
IDEASeth
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Rep: Reputation: Disabled
problems with include using gcc


I installed gcc on a Debian distribution using
apt-get install gcc.
All seemed well.

I tried to test it with Hello_world using a variety of commands. The simplest being
gcc hello_world.c

I also tried
gcc -o hello_world -ansi hello_world.c

None worked.

The code is:

#include <stdio.h>

int main()
{printf("Seth says hello\n");
}

I got the following errors

hello_world.c:1:19 error stdio.h No such file
or directory

hello_world.c:4: incompatible implicit declaration
of built-in function 'printf'

So the compiler can't fine stdio.h, apparently. My
questions are
1. Where is it?
2. How could I have found it, myself?
3. How do I tell gcc the location?
4. Why wasn't this path set up at the
installation?

OK, so I tried something else. I wrote a C program which did not use any printf's. It used a pointer to set a specific memory location so I hope the code would not get optimized away. Anyway I got the following error and no output.

crtl.o: No such file: No such file or directory
collect2: ld returned 1 exit status

I'm completely lost here. What's going on?

Last edited by IDEASeth; 02-27-2013 at 12:16 PM. Reason: Additional info
 
Old 02-27-2013, 12:06 PM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
You need to have installed the package libc6-dev. Have you done that? That's where stdio.h is found.
ciao,
jdk
 
Old 02-27-2013, 12:23 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,961

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
You need to install the kernel headers and make would be good to have too.

apt-get install make linux-headers-$(uname -r)
 
Old 02-27-2013, 01:10 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,957

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
(kernel-headers is useful, but not absolutely important for helloworld... also I'd suggest manpages-dev, binutils, make, gdb)
 
Old 02-27-2013, 01:30 PM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154
The glibc "kernel headers" are not in the package 'kernel-headers' :
'kernel-headers' provide /usr/src/linux*/<headers-for-building-kernel-modules>.

Glibc "kernel headers", used by gcc : Package name = linux-libc-dev

The proof way of having a fully working gcc :
# apt-get install g++
Or : # apt-get install build-essential


-

Last edited by knudfl; 02-27-2013 at 01:33 PM.
 
2 members found this post helpful.
Old 02-27-2013, 01:40 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,961

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
A regretfully hasty response and agree that installing build-essential will ensure a full working compiler.
 
Old 02-27-2013, 04:05 PM   #7
IDEASeth
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
I tried knudlf's suggestion first. (apt-get install g++) At first it didn't work, but the error indicated that I should run apt-get update and try again. Second time was the charm. I noted that it loaded libc, the program compiled without errors or warnings and executed. Case closed...

... not so fast. The reason I wanted to compile a C program at all was to enable the RS485 transmitters on my Manx board. The documentation and the tech support person said I should set location 0x1ad to 0x44 and this would enable the 485 drivers. So this is the program I wrote

void main()
{unsigned char p* = (unsigned char *) 0x1ad;

*p = 0x44;
}

It compiles without error or warning.
But when I run it, I get 'Segmentation Fault'

I can understand that the program is trying to write outside its assigned memory and so the fault. But from the the deep recesses of my brain I remember different kinds of pointers to handle this -- far pointers and huge pointers. I googled this and sure enough hugh pointers are designed to access the entire memory space. The problem is when I write code like

unsigned char huge *p;

gcc doesn't understand at all. So how do I do this in gcc?

Last edited by IDEASeth; 02-27-2013 at 04:07 PM.
 
Old 02-27-2013, 04:34 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Quote:
Originally Posted by IDEASeth View Post
The reason I wanted to compile a C program at all was to enable the RS485 transmitters on my Manx board. The documentation and the tech support person said I should set location 0x1ad to 0x44 and this would enable the 485 drivers. So this is the program I wrote

void main()
{unsigned char p* = (unsigned char *) 0x1ad;

*p = 0x44;
}
What exactly does the documentation and the tech person say? 0x1ad is not a global memory location...it's only 12 bits wide. Your system uses at least 32, if not 64 bits for memory addressing. Even ignoring that, you don't "enable drivers" by changing some random byte in RAM. We need the full context of the documentation to be able to help with this.
 
Old 02-27-2013, 05:10 PM   #9
IDEASeth
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
0x1ad is a global memory location. It is identical to 0x000001ad which is 32 bits wide. (Also equal to 0x00000000000001ad which is 64 bits wide.

It is not a random byte. It is a hardware register mapped into memory space. The a page from the reference manual is attached. I am trying to set bits D2 and D6 which are the COM3 and COM4 Transmit Enable respecitivley

By the way, oops, the address of the register is 0x1da, not 0x1ad as I stated in this thread. I got it right in the code; it is wrong only here.
Attached Thumbnails
Click image for larger version

Name:	ScreenHunter_26 Feb. 27 17.07.jpg
Views:	12
Size:	73.1 KB
ID:	11951  

Last edited by IDEASeth; 02-27-2013 at 05:20 PM.
 
Old 02-27-2013, 05:19 PM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
What kind of system are you running this on? The easiest way to directly access/control registers is through a memory map IMO.
 
Old 02-27-2013, 06:25 PM   #11
IDEASeth
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Well it turns out that suicidaleggroll was partially right. I should have been accessing IO space not Memory space. So the whole idea of using pointers was wrong. (But, nevertheless, how would I access an arbitrary location in Memory space should I want to someday?)

I have gotten the program to compile and execute using ioperm and outb functions referenced in the sys/io.h and unistd.h include files. (The hardware still doesn't respond, but that is another issue.)

Thanks everyone for taking the time to help.
 
Old 02-28-2013, 03:47 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,957

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
The quickest solution for near/far/huge problem: forget them. Also read some documentation about Virtual Memory
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Recursively include headers in include option for gcc kvm1983 Linux - Newbie 5 09-04-2012 04:21 PM
[SOLVED] what is gcc include path/ linux include path ghantauke Linux - Newbie 1 03-08-2011 09:34 PM
about include in gcc. totaljj Linux - Newbie 2 11-22-2006 10:38 AM
gcc include apocolpse Programming 6 11-03-2004 02:36 PM
gcc on 9.1 include problem skywarp Slackware 3 06-04-2004 11:05 PM


All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration