Call to undefined function error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orked
    New Member
    • Jan 2009
    • 49

    Call to undefined function error

    hi
    i made program to control sevensegment but when i make debug
    tell me call to undefined function inportb
    Code:
    #define Data 0x378
    #define Status Data+1
    #define Control Data+2
    
    #include <dos.h>
    #include <conio.h>
    #include <stdio.h>
    #include <iostream.h>
    
    void main(int n)
    {
      int x;
      do{
         x=inportb(Status);
         x= x&& 0x80;
         }while(x!=0x80);
     //  do{
          if(kbhit()==1)
          {
           // int n;
            switch(n)
            {
             case 0:
             outportb(Data,0x40) ;
             break ;
             case 1:
             outportb(Data,0x57);
             break;
              case 2:
             outportb(Data,0x09);
             break;
              case 3:
             outportb(Data,0x03);
             break;
              case 4:
             outportb(Data,0x26);
             break;
              case 5:
             outportb(Data,0x12);
             break;
              case 6:
             outportb(Data,0x10);
             break;
              case 7:
             outportb(Data,0x47);
             break;
              case 8:
             outportb(Data,0x00);
             break;
              case 9:
             outportb(Data,0x02);
             break;
             default: cout<< "this is wrong" ;
             break;
             }
           }
         else cout<<"do nothing";
      //   }while
      }
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Header files <dos.h>, <conio.h>, and <streamio.h> are only available on certain platforms -- they are not part of Standard C. Are you sure they are available on your platform?

    Functions inportb and outportb are only available on certain platforms -- they are not part of Standard C. Are you sure they are available on your platform? Your error message suggests that at least one of them wasn't available to the linker. You may need to specify an object library on the command line. The name of the necessary object library is platform-dependent.

    By the way, what is your platform?

    Header file <stdio.h> is part of Standard C; but header file <streamio.h> might be intended to refer to <streamio>, part of Standard C++. You really don't want to mix these together. Are you using C or C++?

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      Anyway, you can't write to io ports by address from win32 program, and from dos program on win2k and later. You need to find some driver that allows you to do it ( dlportio, giveio, etc ). And most of them don't work on vista.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        and finally main should be either

        int main()

        or

        int main(int argc, char **argp)

        but not

        void main(int n)

        Comment

        • orked
          New Member
          • Jan 2009
          • 49

          #5
          I used Borland C++, so i can use iostream library
          i want to know ,if i can use kbhit in c++or not but it need stdio.h library

          Comment

          • orked
            New Member
            • Jan 2009
            • 49

            #6
            oh ,i forgot asking about dos ,my doctor told we can use it in c or c++ and two function (inportb&outpor tb) defined in it,why the program told "call to undefined function"

            Comment

            • newb16
              Contributor
              • Jul 2008
              • 687

              #7
              What part of the sentence in #6 is a question?

              Nevertheless, open dos.h that your compiler includes and look if there are these functions declared.

              Comment

              • orked
                New Member
                • Jan 2009
                • 49

                #8
                sorry ,can you tell me how i can open dos.h to show if functions defined in it or not
                my question in #6 dos.h library found in c++ or not,and why is not defined my function if it is found

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  dos.h library is not in C++ because, as stated in #2 they are not part of the C++ standard. However they may be available on your platform. Your platform is the hardware/OS combination you are using.

                  You open dos.h in the same way you open any source file, locate it on your hard drive and use a text editor to open it.

                  Comment

                  • orked
                    New Member
                    • Jan 2009
                    • 49

                    #10
                    you mean i will find information about dos in class libraries guide in the program itself

                    Comment

                    • Banfa
                      Recognized Expert Expert
                      • Feb 2006
                      • 9067

                      #11
                      No we mean open dos.h in a text editor and read it and understand what is being declared in it.

                      Comment

                      • orked
                        New Member
                        • Jan 2009
                        • 49

                        #12
                        i searched in the help of program ,i didn't find any thing about dos.h
                        where i can find this text editor

                        Comment

                        • donbock
                          Recognized Expert Top Contributor
                          • Mar 2008
                          • 2427

                          #13
                          Originally posted by orked
                          i searched in the help of program ,i didn't find any thing about dos.h where i can find this text editor
                          First, search your hard disk(s) for a file named "dos.h".
                          Second, take a look at that file. Use whatever editor you're most comfortable with -- the one you used to create fact.c, Notepad, whatever.

                          You're looking for function prototypes for inportb and outportb. Are they there at all? Are they conditionally compiled out?

                          You still haven't told us: what operating system are you using? Is it DOS or Windows or something else? What version of Windows? Are you editing and compiling on the same machine where the program is expected to run?

                          Comment

                          • orked
                            New Member
                            • Jan 2009
                            • 49

                            #14
                            i using windows xp sp2, i still test program , when the program run without error ,i will connect it with the circuit to make control on sevensegment

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by orked
                              i using windows xp sp2, i still test program , when the program run without error ,i will connect it with the circuit to make control on sevensegment
                              Windows uses a 'hal', and 'Hardware Abstraction Layer' that forbids every user program to read/write the I/O ports directy; no chance your program will every work as it is now.

                              btw, the following line from your program most certainly doesn't do what you want it to do:

                              Code:
                              x= x&& 0x80;
                              Better use the '&' operator instead.

                              kind regards,

                              Jos

                              Comment

                              Working...