link error...need help

This is a discussion on link error...need help within the C Programming forums, part of the General Programming Boards category; Can someone tell me why I am getting two linker errors and what I can do to resolve them when ...

  1. #1
    Unregistered
    Guest

    Smile link error...need help

    Can someone tell me why I am getting two linker errors and what I can do to resolve them when the code below is compiled and linked. I am using MS C++ Developer Studio. The linker errors are:
    "unresolved external symbol _inportb"
    "unresolved external symbol _outportb"
    Thanks in advance!
    Gigi



    #include <dos.h>
    #include <stdio.h>
    #include <conio.h>

    #define PORT1 0x3F8 /* Port Address Goes Here */

    void main(void)
    {
    int c;
    int ch;
    void outportb(int portid, unsigned int value);
    unsigned inportb(int portid);

    outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */

    /* PORT 1 - Communication Settings */

    outportb(PORT1 + 3 , 0x80); /* SET DLAB ON */
    outportb(PORT1 + 0 , 0x03); /* Set Baud rate - Divisor Latch Low Byte */
    /* Default 0x03 = 38,400 BPS */
    /* 0x01 = 115,200 BPS */
    /* 0x02 = 57,600 BPS */
    /* 0x06 = 19,200 BPS */
    /* 0x0C = 9,600 BPS */
    /* 0x18 = 4,800 BPS */
    /* 0x30 = 2,400 BPS */
    outportb(PORT1 + 1 , 0x00); /* Set Baud rate - Divisor Latch High Byte */
    outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
    outportb(PORT1 + 2 , 0xC7); /* FIFO Control Register */
    outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */

    printf("\nSample Comm's Program. Press ESC to quit \n");

    do { c = inportb(PORT1 + 5); /* Check to see if char has been */
    /* received. */
    if (c & 1) {ch = inportb(PORT1); /* If so, then get Char */
    printf("%c",ch);} /* Print Char to Screen */

    if (kbhit()){ch = getch(); /* If key pressed, get Char */
    outportb(PORT1, ch);} /* Send Char to Serial Port */

    } while (ch !=27); /* Quit when ESC (ASC 27) is pressed */
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Try using outp and inp instead of outportb and inportb.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest

    Question

    Prelude,
    Can you explain why? I tried that but it didn't work.
    Gigi

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >void outportb(int portid, unsigned int value);
    >unsigned inportb(int portid);

    You have put this in your main function? Why? It seems unnecessary to me. Perhaps it causes problems.

    Note that outportb and inportb is not ANSI C. Functions outp and inp are other non-ANSI C functions which are sometimes used. Probably MSVC++ doesn't know the functions outportb and inportb. Or you have not included the correct header files. For more information search msdn.microsoft.com for Microsoft specific info on this topic.

    [edit]
    You have put those two functions in your main. You have not declared them as extern, so the compiler assumes these functions are implemented in the current file. Remove this:

    >void outportb(int portid, unsigned int value);
    >unsigned inportb(int portid);

    from your main-function.
    [/edit]
    Last edited by Shiro; 06-20-2002 at 01:02 PM.

  5. #5
    Unregistered
    Guest

    Wink

    Shiro,
    I tried that and it didn't help.
    Gigi

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    If you're not writing for DOS, using a DOS compiler, then you're out of luck

    Most operating systems make direct access to the hardware a privilege granted only to the OS and device drivers.

    It really doesn't matter what you call those functions, or how you prototype them.

    The solution is find out which device manages the port you're interested in, and use that.

  7. #7
    Unregistered
    Guest

    Question

    Salem,
    Is the compiler that I'm using a problem such as you have described? I really need to know what I need to do to resolve these linker errors.
    Gigi

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    According to the MSDN library, you should be able to use _outp and _inp. It also says that this works in Windows 95, don't know if it works on your OS.

    #include <conio.h>

    int _outp(unsigned short port, int out_byte); // sends out_byte to port
    int _inp(unsigned short port); // returns the byte at port

  9. #9
    Unregistered
    Guest

    Wink

    Shiro,
    I am a fool. I only needed to change the function names to "_inp" and "_outp". Now it compiles and links. There is a run time problem however that may be what Salem was talking about. The error is a "Priviledged Instruction" error. I am going to try to debug it.
    Thanks everyone for your help!
    Gigi

  10. #10
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >I am a fool. I only needed to change the function names
    >to "_inp" and "_outp".

    You're is not a fool if you don't know something.

    The problem with these non-standard things is that each library has different functions for (almost) the same things. Some use _inp, others use inp and others use inportb.

  11. #11
    Unregistered
    Guest

    Smile

    Shiro,
    Thanks! Another question. I have this run time error "Priviledge Instruction". Does this mean that I am attempting to take control of a device (in this case a serial port) and I don't have priviledge to do so? If this is the case how can I disable the serial port, run my driver, and then re-enable the port when I'm finished?
    Thanks!
    Gigi

  12. #12
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Sorry, don't know much of the Windows OS. But MSDN has some info on it:

    The Intel architecture defines "privileged" instructions and "sensitive" instructions. The privileged instructions may only be executed when the Current Privilege Level is zero (CPL = 0). Attempting to execute a privileged instruction when CPL != 0 will generate a general protection (GP) exception. Windows traps GP exceptions caused by executing privileged instructions and usually generates an application error.
    Probably you need to change the CPL, but I don't know how to change the CPL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List, Please Help!
    By CodeMonkeyZ in forum C Programming
    Replies: 5
    Last Post: 02-17-2009, 05:23 AM
  2. I'm confused about link lists (again)
    By JFonseka in forum C Programming
    Replies: 4
    Last Post: 06-13-2008, 08:13 PM
  3. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM
  4. Link Error
    By Luigi in forum C++ Programming
    Replies: 1
    Last Post: 04-12-2004, 07:12 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21