ZakKemble / libmcp2221

MCP2221 HID Library
https://blog.zakkemble.net/mcp2221-hid-library/
GNU General Public License v3.0
53 stars 14 forks source link

linker error using version 1.04: libmcp2221.dll: file not recognized: File format not recognized #2

Open cdwijs opened 4 years ago

cdwijs commented 4 years ago

Hi there,

I'm trying to use this precompiled dll from 30 december 2016: https://github.com/zkemble/libmcp2221/tree/54b04e4526ef786744bde26f879aa4aa3a62b101/lib/win/libmcp2221.dll

During linking of my Qt program, I get this error messages: /some/where/libmcp2221.dll: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status

Next I try to use this version: from 30 december 2016: https://github.com/zkemble/libmcp2221/blob/021bcd5973a83fb58ffa8fdf020b57157c10f456/lib/win/libmcp2221.dll Now I don't get errors during the linking of my Qt program.

My versions: Windows 7 Enterprise SP1 Qt creator 4.7.2 Qt 5.11.1 compiled with minGW 5.3.0 32 bit MinGW 5.3.0 32 bit compiler

To reproduce: Start Qt creator File->new File or Project ->Application->Qt Widgets Application->choose. Name: MCP2221 -> next Select kit: Desktop Qt 5.11.1 MinGW 32 bit-> next -> next Add to version control: git -> finish (As a sanity check, start debugging by pressing F5, an empty window called "MainWindow" should pop up)

Download libmcp2221 from here, and extract it in the same directory as the file MCP2221.pro https://github.com/zkemble/libmcp2221/archive/54b04e4526ef786744bde26f879aa4aa3a62b101.zip

Add this line to MCP2221.pro: win32:LIBS += "$$PWD/lib/win/libmcp2221.dll"

Add this line to main.cpp:

include "lib/libmcp2221.h"

Press F5 to debug. This is the resulting compile output: 12:42:03: Running steps for project MCP2221... 12:42:03: Configuration unchanged, skipping qmake step. 12:42:04: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" C:/Qt/5.11.1/mingw53_32/bin/qmake.exe -o Makefile ../MCP2221/MCP2221.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug C:/Qt/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory 'C:/Users/crldewijs/Desktop/New folder (2)/build-MCP2221-Desktop_Qt_5_11_1_MinGW_32bit-Debug' g++ -Wl,-subsystem,windows -mthreads -o debug/MCP2221.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -lmingw32 -LC:/Qt/5.11.1/mingw53_32/lib C:/Qt/5.11.1/mingw53_32/lib/libqtmaind.a -LC:/openssl/lib -LC:/Utils/my_sql/mysql-5.6.11-win32/lib -LC:/Utils/postgresql/pgsql/lib -lshell32 C:/Qt/5.11.1/mingw53_32/lib/libQt5Cored.a "C:/Users/crldewijs/Desktop/New folder (2)/MCP2221/lib/win/libmcp2221.dll" C:/Qt/5.11.1/mingw53_32/lib/libQt5Widgetsd.a C:/Qt/5.11.1/mingw53_32/lib/libQt5Guid.a C:/Qt/5.11.1/mingw53_32/lib/libQt5Cored.a C:/Users/crldewijs/Desktop/New folder (2)/MCP2221/lib/win/libmcp2221.dll: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status Makefile.Debug:67: recipe for target 'debug/MCP2221.exe' failed mingw32-make[1]: Leaving directory 'C:/Users/crldewijs/Desktop/New folder (2)/build-MCP2221-Desktop_Qt_5_11_1_MinGW_32bit-Debug' mingw32-make[1]: *** [debug/MCP2221.exe] Error 1 Makefile:36: recipe for target 'debug' failed mingw32-make: *** [debug] Error 2 12:42:09: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2. Error while building/deploying project MCP2221 (kit: Desktop Qt 5.11.1 MinGW 32bit) When executing step "Make" 12:42:09: Elapsed time: 00:05.

ZakKemble commented 4 years ago

I'm not entirely sure, but I think you may be linking the library incorrectly judging by that cmd line. Usually -lmcp2221 will link against the .dll or .a file, and -L"$$PWD/lib/win/" to tell it where it is (or put libmcp2221.dll in the compilers lib directory).

Odd that it works with the old .dll though, but I did use a different build set up for the older one.

cdwijs commented 4 years ago

Hi, Thank you for your fast reply. I've compiled the new version of your library with MinGW53_32. This works without any problems. I'll send a merge request with this .dll and the hidapi.h and hid.c files I've used.

cdwijs commented 4 years ago

Hi, I've created the pull request: https://github.com/zkemble/libmcp2221/pull/3

ZakKemble commented 4 years ago

Really, you should be linking against the .a file, not the .dll. Have you tried that?

cdwijs commented 4 years ago

I'll check to link to the .a file next week, I don't have a windows machine here.