0

I'd like to use this gamepad library (https://github.com/elanthis/gamepad/) written in C in my C++ application. Unfortunately I can't get it to work.

So far I've tried to create a shared library and link it using Qt's GUI. When trying to run my C++ program I still get the error "main.cpp:89: Error: undefined reference to `_imp__GamepadInit'" which seems to tell me that the library wasn't properly linked yet.

My main application looks like this:

#include "gamepad.h"

int main(int argc, char *argv[]) {
    GamepadInit();
    return 0;
}

As I'm pretty clueless my question is: what would be the basic steps to use functions of this library (given the .c & .h files) when working with Qt Creator/MinGW?

vigilanum
  • 133
  • 1
  • 5
  • use `extern C ...` – PcAF Jun 29 '16 at 14:07
  • 1
    From what I see the header of the library has `extern C` defined in line 12 (https://github.com/elanthis/gamepad/blob/master/gamepad.h#L12). Or am I missing something? – vigilanum Jun 29 '16 at 14:09
  • Maybe you forgot to link it. – PcAF Jun 29 '16 at 14:15
  • That exactly is what I need to now, like how can I link it? Do I really need to create a DLL file from the given source files or is there any other way to just include them? Even with a .dll/.a I got the same error after including the library using the Qt GUI dialog to add an existing library. – vigilanum Jun 29 '16 at 14:18
  • 1
    It looks like yes, you need to build that project to get dll (and also .lib) files, because it is distributed only in source, I can't see pre-built binaries there – mvidelgauz Jun 29 '16 at 14:40
  • @mvidelgauz Alright, I had to build the library with Visual Studio. Now it works. Thanks! – vigilanum Jun 29 '16 at 15:01

0 Answers0