Thread: compiling c prog with outb function

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    6

    compiling c prog with outb function

    Hi there,

    i'm trying to write an extremely simple program that writes to the parallel port:

    Code:
    #ifdef HAVE_CONFIG_H
    #include <config.h>
    #endif
    
    #include <fcntl.h>
    #include <sys/ioctl.h>
    #include <linux/parport.h>
    #include <linux/ppdev.h>
    
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
      int addr = 0x378;
      int result = ioperm(addr,5,1);
    
      outb(0xff, addr);
    
      return EXIT_SUCCESS;
    }
    The problem is when i compile it it tells me i have a undefined reference to the outb function. The man pages tell me that i need to include option -O# to compile my program. I use:

    Code:
    gcc -O2 ./main.c -o main.o -lm
    which spits out:

    Code:
    /tmp/ccW9TX56.o: In function `main':
    main.c:(.text+0x31): undefined reference to `outb'
    collect2: ld returned 1 exit status
    what am i doing wrong, am i missing an include file or something?

    thanks

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You are at linux right? Googling I found this http://ou800doc.caldera.com/en/man/html.D3/outb.D3.html which have some header files to include

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    yup linux, opensuse 11 x86-64 platform. i'll check out the link.

    thanks
    Last edited by itchy8me; 11-16-2008 at 06:30 AM.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    i've allready been to that site, adding the includes adds some new errors:

    Code:
    ./main.c:11:21: error: sys/ddi.h: No such file or directory
    ./main.c:12:23: error: sys/f_ddi.h: No such file or directory
    once again i was compiling with:

    Code:
    gcc -O2 ./main.c -o main.o -lm

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    doing a search on my computer for these 2 files returns nothing, as far as i know i have all the development libraries installed, are there any specific ones i should know about. Also running outb() from my terminal works.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    http://www.progsoc.uts.edu.au/lists/.../msg00486.html apparently you shouldn't be using it :\

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    what should i be using then?

    thanks.

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    okay i added the sys/io.h header file and it now works.

    thanks for your help guys
    Last edited by itchy8me; 11-16-2008 at 09:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Replies: 2
    Last Post: 12-07-2004, 02:31 AM