0

I am a self-teaching guy with a lot shortage in c programming. I do not understand why are these error messages below. I guess some system file path is not found by the compiler, but why?

c:\winproj\c\flabs>rm *.o 
c:\winproj\c\flabs>rm y.tab.* 
c:\winproj\c\flabs>rm lex.yy.* 
c:\winproj\c\flabs>bison -v -y -d flabs.y
c:\winproj\c\flabs>flex flabs.l 
c:\winproj\c\flabs>gcc -c -g  y.tab.c lex.yy.c
c:\winproj\c\flabs>gcc -g -Wall -Werror -lhid -lsetupapi y.tab.o lex.yy.o flabs.c -o flabs.exe 
C:\Users\steve\AppData\Local\Temp\ccud7BEa.o: In function `open_usb':
c:\winproj\c\flabs/win_hid.h:179: undefined reference to `_imp__HidD_GetHidGuid@4'
c:\winproj\c\flabs/win_hid.h:180: undefined reference to `_imp__SetupDiGetClassDevsA@16'
c:\winproj\c\flabs/win_hid.h:185: undefined reference to `_imp__SetupDiEnumDeviceInterfaces@20'
c:\winproj\c\flabs/win_hid.h:187: undefined reference to `_imp__SetupDiGetDeviceInterfaceDetailA@24'
c:\winproj\c\flabs/win_hid.h:193: undefined reference to `_imp__SetupDiGetDeviceInterfaceDetailA@24'
c:\winproj\c\flabs/win_hid.h:206: undefined reference to `_imp__HidD_GetAttributes@8'
c:\winproj\c\flabs/win_hid.h:209: undefined reference to `_imp__HidD_GetPreparsedData@8'
c:\winproj\c\flabs/win_hid.h:214: undefined reference to `_imp__HidP_GetCaps@8'
c:\winproj\c\flabs/win_hid.h:218: undefined reference to `_imp__HidD_FreePreparsedData@4'
c:\winproj\c\flabs/win_hid.h:222: undefined reference to `_imp__HidD_FreePreparsedData@4'
c:\winproj\c\flabs/win_hid.h:231: undefined reference to `_imp__HidD_GetProductString@12'
collect2.exe: error: ld returned 1 exit status

The referred win_hid.h is included in then main flabs.c file. The win_hid.h starts with these lines:

#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <setupapi.h>
#include <ddk/hidsdi.h>
#include <ddk/hidclass.h>
uhum2004
  • 11
  • 3
  • 1
    Your compiler might not be able to find `hid.lib`. Does the file exist? Which directory is it in? (The header files seem to be in a `ddk` subdirectory.) Try searching for it and adding that directory to the compiler’s search path with `-L`. – Davislor Oct 06 '15 at 08:06
  • There is no such file in my computer. However the same win_hid.h seems to be ok when I use from a simpler test.c file. The compiler compiles it and te result file runs properly. – uhum2004 Oct 06 '15 at 08:24
  • Does your test file call any of the functions listed in the output? You might be able to link against `hid.dll` instead. Try putting the path to that after `-L`. – Davislor Oct 06 '15 at 08:28
  • This i my test.c file. It works perfectly.... `code` #include "win_hid.h" uint8_t mytext[64] = { 0x81, 0xe0 }; char recbuffer[64]; wchar_t version[]=PRODUCT; int main() { int i; printf ("Test run for win_hid.c testing\n"); i=open_usb(); if (i==1) { wprintf (L"Found: %s\n",version); i=send_usb(mytext); printf ("send: %i\n",i); i=recv_usb(recbuffer); printf ("receive: %i\n",i); printf ("buffer: %s\n",recbuffer); close_usb(); } else { printf ("Not found\n"); } return 0; } – uhum2004 Oct 06 '15 at 08:53
  • @under_gongor Yes, that’s exactly what I said. – Davislor Oct 06 '15 at 09:00
  • @Lorehead: Sorry, no idea what I was reading and why. – undur_gongor Oct 06 '15 at 09:03
  • Try calling `HidD_GetHidGuid()`. https://msdn.microsoft.com/en-us/library/windows/hardware/ff538924(v=vs.85).aspxhttps://msdn.microsoft.com/en-us/library/windows/hardware/ff538924(v=vs.85).aspx – Davislor Oct 06 '15 at 09:05

0 Answers0