Like Tree2Likes
  • 2 Post By grumpy

I have an unresolved external error at compile time.

This is a discussion on I have an unresolved external error at compile time. within the Windows Programming forums, part of the Platform Specific Boards category; Hello I am getting the following two errors in my program. They are: Error 1 error LNK2019: unresolved external symbol ...

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    33

    I have an unresolved external error at compile time.

    Hello I am getting the following two errors in my program. They are:

    Error 1 error LNK2019: unresolved external symbol _XInputGetState@8 referenced in function _ControllerExists F:\Programs\C-flat\Joystick Key Mapper\Joystick Key Mapper\Source.obj Joystick Key Mapper

    Error 2 error LNK1120: 1 unresolved externals F:\Programs\C-flat\Joystick Key Mapper\Debug\Joystick Key Mapper.exe Joystick Key Mapper

    Here is my program:
    Code:
    #define _X86_
    #include <stdio.h>
    #include<string.h>
    #include <Xinput.h>
    #include <stdbool.h>
    #include <Windows.h>
    BYTE ControllerExists();
    int main()
    {
     char option;
     puts("Welcome to Key Mapper \n");
     puts("Program by: Jeremy Red\n");
     puts("Information:\n");
     if (ControllerExists() > FALSE);
     {
      puts("Controller Found");
     }
     puts("Program is used to map keys to a controller input\n");
     while (1 == 1)
     {
      puts("Select type in an option:\n\n");
      puts("\t 1. <L>oad a program\n");
      puts("\t 2. <S>tart a new program\n");
      puts("\t 3. <E>dit an existing program\n");
      puts("\t 4. <R>un current program\n");
      puts("\t 5. <Q>uit preogram\n");
      option = getchar();
      if (option == '1' || option == 'L' || option == 'l')
      {
       // Load an existing program
      }
      else
      if (option == '2' || option == 'S' || option == 's')
      {
       // Start a new program
      }
      else
      if (option == '3' || option == 'E' || option == 'e')
      {
       // Change an existing program
      }
      else
      if (option == '4' || option == 'R' || option == 'r')
      {
       // Run the current program and if one is not running 
       // return an error and reload options
      }
      else
      if (option == '5' || option == 'Q' || option == 'q')
      {
       return EXIT_SUCCESS;
      }
     }
    }
    BYTE ControllerExists()
    {
     for (BYTE i = 0; i < 4; i++)
     {
      XINPUT_STATE state;
      ZeroMemory(&state, sizeof(XINPUT_STATE));
      if (XInputGetState(i, &state) == TRUE)
      {
       printf("Controller was found in port %i\n", i);
       return i + 1;
      }
     }
     puts("Error no controller was found on any port");
     return 0;
    }
    I have no idea how I can fix this... I know what the error is just not how to fix it. If anyone could help I would appreciate it.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Did you link with the correct library?
    The MSDN page says
    Use xinput.lib or xinput9_1_0.lib.

    So add a switch like -lxinput

    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    33
    What do you mean by add a switch like -lxinput? what does this mean and how would I do it?

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Mods: please move

    This belongs in the Windows forum next time, it's a very Windows-specific problem (D3D, Windows.h, etc). After a previous thread got moved, your post from a few days ago said you would remember the right location next time :P.

    Generally that error message implies it can't find a particular function or variable in another object file or library -- usually because your linker options are not right: directories to look in, library names you are linking in, the order they are linked in, etc. Without more info, we can't say for sure, only guess.

    A quick Google search for "unresolved external symbol _XInputGetState" turned up several results: https://www.google.com/search?q="unresolved+external+symbol+_XInputGetSta te". There are a number of causes and solutions, like
    * using left- and right- quotes instead of straight quotes in #pragma statement
    * failing to link the lib
    * not defining all the proper macros
    * wrong bin or lib path in your project settings
    * etc
    Google should be the first thing you try. If you did that, let us know, and tell us which solutions you tried, so we don't waste time re-doing your Google search for you, so you can say "already tried that, didn't work".

    Many (all?) of the potential solutions (including Matticus' suggestion) will be specific to the compiler/implementation/development environment you are using. Some more details in that area would help.

  5. #5
    Registered User
    Join Date
    Oct 2013
    Posts
    33
    Did not know this was a windows specific question. Anyways I am using visual studio 2013 as my IDE and compiler. I will do a BING(I love everything Microsoft) search like you suggested to try and fix it

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,677
    Quote Originally Posted by Justinweq View Post
    Did not know this was a windows specific question.
    You love Microsoft, you're including a system header named <Windows.h>, using functions overtly documented by Microsoft, and using Microsoft Visual Studio. And you didn't have an inkling that your problem might be specific to Microsoft windows.

    I have a bridge I'd like to sell to you.
    stahta01 and Salem like this.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I'm wondering why it is not a game programming question. Why are you using XInput?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX9 _GUID unresolved external - compile time error.
    By arcaine01 in forum Game Programming
    Replies: 1
    Last Post: 09-16-2009, 06:37 PM
  2. Replies: 3
    Last Post: 10-02-2007, 10:12 PM
  3. Unresolved external error
    By kpp_custom in forum C++ Programming
    Replies: 5
    Last Post: 08-25-2005, 11:38 AM
  4. unresolved external error...???
    By matheo917 in forum C++ Programming
    Replies: 11
    Last Post: 04-19-2002, 08:43 PM
  5. LNK error, unresolved external...
    By Brown Drake in forum C++ Programming
    Replies: 3
    Last Post: 10-22-2001, 04:00 PM

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