2 Replies Latest reply on Dec 24, 2015 9:48 AM by userc_38522

    g++ error on linking cyapi.lib

       I wrapped some cyapi.lib functions for my python project. I am using MinGW(3.4.5) to compile and link my files.


      But I always get g++ error as follows. Compiling of .cpp and .c files is successful. But it never succeed to link to cyapi.lib. I include all libs that I can think of, like setupapi.lib, user32.lib, kernel32.lib, etc.  I am sure cyapi.lib is accessible to my g++ compiler, and I am sure g++ accessed cyapi.lib, but somehow g++ cann't resolve the definition in cyapi.lib. 


      No matter I use gcc.exe or g++.exe to compile wrapcyapi.cpp, the error stays. 


      My question is: is cyapi.lib readable to gcc? What should I do? 


      C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\python27\include -Ic:\pytho
      n27\PC -c wrapcyapi.cpp -o build\temp.win32-2.7\Release\wrapcyapi.o
      C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\python27\include -Ic:\pytho
      n27\PC -c extension.c -o build\temp.win32-2.7\Release\extension.o
      writing build\temp.win32-2.7\Release\winusbext.def
      C:\MinGW\bin\g++.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\wrapcyapi.o build\temp.win32-2.7\Release\extension.o build\temp.win32-2.7\Release\winusbext.def -L./lib/x86 "-LC:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib" -Lc:\python27\libs -Lc:\python27\PCbuild -lCyAPI -lSetupAPI -lUser32 -lKernel32 -lgdi32 -lwinspool -lcomdlg32 -lpython27 -lmsvcr90 -o build\lib.win32-2.7\winusbext.pyd
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x95):wrapcyapi.cpp: undefined re
      ference to `CCyUSBDevice::GetDeviceDescriptor(_USB_DEVICE_DESCRIPTOR*)'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0xef):wrapcyapi.cpp: undefined re
      ference to `CCyUSBDevice::~CCyUSBDevice()'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x178):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::CCyUSBDevice(void*, _GUID, int)'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x1b7):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::EndPointCount()'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x29d):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::~CCyUSBDevice()'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x31e):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::CCyUSBDevice(void*, _GUID, int)'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x35d):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::EndPointCount()'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x3f6):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::Open(unsigned char)'
      build\temp.win32-2.7\Release\wrapcyapi.o(.text+0x41d):wrapcyapi.cpp: undefined r
      eference to `CCyUSBDevice::DeviceCount()'

      eference to `CCyUSBDevice::Close()'
      collect2: ld returned 1 exit status
      error: command 'g++' failed with exit status 1


      I tried some replies in the forum, but no lucky.


      Thanks in advance for any reply.

        • 1. Re: g++ error on linking cyapi.lib

          I'd better provide my command lines here. I tried many suggestions about link to a static lib, e.g. different orders, only compile .cpp, add different flags etc. none of them works. 


          g++ -mno-cygwin -o -c wrapcyapi.o wrapcyapi.cpp


          g++ -mno-cygwin -Wl, wrapcyapi.o -Bstatic -L./lib/x86 -lCyAPI -Wl, -Lc:\python27\libs -lpython27 -lmsvcr90 -o winusbext.pyd




          I followed quick_start_guid.pdf to build a project on vc and it worked. I know cyapi.lib can be linked w/o problem. But why using g++ will cause this wired error?  




          I have been working on this problem for 2 days. Could anybody help me?

          • 2. Re: g++ error on linking cyapi.lib

            I gave up using MinGW gcc/g++, and turn to use VC. I think cyapi.lib is only readable on VC. For those who want to link cyapi.lib in gcc/g++, I tried almost all methods I found online, but all failed. Don't waste your time trying again until Cypress provides a gcc/g++ linkable library.