FedoraForum.org - Fedora Support Forums and Community
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2007
    Posts
    42

    io.h > DRIVING ME INSANE!

    OK, Lately I've taken interest in computer control technology and want to be able to make input/output calls to things like the parallel port and the game port on a sound card. I found a nifty lill' website that gave an example C source code, and when I went to compile it, gcc returned a "io.h: File not found" error. So I went to the internet to find this io.h and dump it in my /usr/include/asm folder, and when I go to compile it I get this:

    Code:
    [redxine@server computer control technology]$ gcc -O outputtest.c -o outputtest
    In file included from outputtest.c:4:
    /usr/include/asm/io.h:35:30: error: crtdll/sys/types.h: No such file or directory
    /usr/include/asm/io.h:37:29: error: crtdll/sys/stat.h: No such file or directory
    /usr/include/asm/io.h:41:26: error: crtdll/stdio.h: No such file or directory
    /usr/include/asm/io.h:46:24: error: crtdll/dir.h: No such file or directory
    Is there a certain io.h i'm supposed to get, or do I have to manually get all these files?

  2. #2
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    5,073
    Linux is a protected-mode operating system, you can't normally directly access I/O ports from an user-mode program. Example software written for DOS won't work even if you drop a header file from DOS in some directory.
    The Linux version of io.h is in the glibc-headers package. If your program example is actually for Linux, remove the io.h file you downloaded and install glibc-headers.
    Last edited by markkuk; 29th May 2008 at 09:38 AM.

  3. #3
    Join Date
    Nov 2007
    Posts
    42
    That's just it: I do have glibc-headers 2.7-2, just no io.h. Here's the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <asm/io.h>
    
    #define base 0x378           /* printer port base address */
    #define value 255            /* numeric value to send to printer port */
    
    main(int argc, char **argv)
    {
       if (ioperm(base,1,1))
        fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);
    
       outb(value, base);
    }
    I'm pretty sure that i'm looking for the file in the wrong directory, or i'm just using the wrong file all together. What do I need to substitute?

  4. #4
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    5,073
    Code:
    #include <sys/io.h>
    See "man ioperm".

  5. #5
    Join Date
    Jan 2009
    Posts
    17
    I have been struggling with the same thing. Now I don't know what to do. It gives me even more errors:
    gcc -Wall -o lptout lptout.c
    lptout.c:16:20: error: asm/io.h: No such file or directory
    lptout.c:21: warning: return type defaults to ‘int’
    lptout.c: In function ‘main’:
    lptout.c:30: warning: implicit declaration of function ‘ioperm’
    lptout.c:33: warning: implicit declaration of function ‘outb’
    lptout.c:34: warning: control reaches end of non-void function
    What should I do?

  6. #6
    stevea Guest
    First off /usr/include/asm is from your kernel build and you should NEVER pollute it with foreign files. You'll be building stuff that has no relation to your kernel and it will cause breakage.

    <asm/io.h> disappeared with the dinosaurs, <sys/io.h> has been the correct file for a long time.

    You will need privilege to execute those programs. Once you get them working as root you may want to
    setcap cap_sys_rawio=ep ./ioprog

  7. #7
    Join Date
    Jan 2009
    Posts
    17
    This is the code that I got:
    Code:
    /*
     * Simple parallel port output control program for Linux
     * Written and copyright by Tomi Engdahl 1998
     * (e-mail: tomi.engdahl@hut.fi)
     *
     * The program output the data value to PC parallel port data pins
     * (default lpt1 I/O address 0x378). The data values are given as the
     * command line parameter to the program. The number can be
     * in decimal (0..255) or hexadecimal format (0x00..0xFF).
     *
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <asm/io.h>
    
    #define base 0x378           /* printer port base address */
    
    main(int argc, char **argv)
    {                    
      int value;
    
      if (argc!=2)
        fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n"), exit(1);
      if (sscanf(argv[1],"%i",&value)!=1)
        fprintf(stderr, "Error: Parameter is not a number.\n"), exit(1);
      if ((value<0) || (value>255))
        fprintf(stderr, "Error: Invalid numeric value. The parameter number must be between 0 and 255\n"), exit(1);
      if (ioperm(base,1,1))
        fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);
    
      outb((unsigned char)value, base);
    }
    So, if I understood correctly, instead of using:
    Code:
    #include <asm/io.h>
    , I should just insert:
    Code:
    <sys/io.h>
    Other than that, if I understood correctly, this code is "polluted with foreign files" What files could these be, and how could I replace them with the right ones?

    P.S: I should just add that this is the first program ever that I am compiling (at least first ever that I do intentionally)

  8. #8
    stevea Guest
    Quote Originally Posted by agapetos
    This is the code that I got:
    [SNIP]
    So, if I understood correctly, instead of using:
    Code:
    #include <asm/io.h>
    , I should just insert:
    Code:
    <sys/io.h>
    Correct.


    Other than that, if I understood correctly, this code is "polluted with foreign files" What files could these be, and how could I replace them with the right ones?
    Wrong.

    THe OP, zacharys, added files to /usr/include/asm. You should never do this unless you are changing kernels.

  9. #9
    Join Date
    Jan 2009
    Posts
    17
    Thanks. This partially solved the problem. This is the error that I got:
    Code:
    [root@localhost Elektronika]# gcc -Wall -o lptout lptout.c
    lptout.c:21: warning: return type defaults to ‘int’
    lptout.c: In function ‘main’:
    lptout.c:34: warning: control reaches end of non-void function
    However, it managed to make a file in the same folder - I guess that it is the program. I am still unsure if I should run that program, before I don't get any more error messages

  10. #10
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    5,073
    Warnings aren't errors. Your listing doesn't show any error messages.

  11. #11
    Join Date
    Jan 2009
    Posts
    17
    EUREKA - this thing works. Thank you all for your advices. I took a LED and checked, and it really works Think of all the possibilities, think of all the uses Muhahaha I'm making a computer controlled house
    Again, thank you all for solution for this software problem

Similar Threads

  1. SSH driving me insane!
    By Vector in forum Servers & Networking
    Replies: 33
    Last Post: 25th August 2009, 11:07 AM
  2. ebay slow down is driving me insane!
    By Dr.Diesel in forum Using Fedora
    Replies: 3
    Last Post: 3rd January 2006, 12:06 AM
  3. NFS problem driving me insane
    By Wishartz in forum Servers & Networking
    Replies: 8
    Last Post: 24th October 2005, 10:33 PM
  4. Gnome Theme Manager is driving me insane
    By Bloodbat in forum Using Fedora
    Replies: 3
    Last Post: 29th December 2004, 07:56 PM
  5. Nautilus CD/DVD Creator is driving me insane!!
    By DRLski in forum Using Fedora
    Replies: 1
    Last Post: 20th November 2004, 12:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •