Results 1 to 6 of 6

Thread: Library architecture i386 ist not compatible with target architecture i386:x86-64

  1. #1
    Join Date
    Apr 2021
    Posts
    3
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Library architecture i386 ist not compatible with target architecture i386:x86-64

    Hello,

    I would like to link my dll into my QT-Project (dynamic). I am using the QT5.15.2 MinGW 64-bit Kit.

    The error, when debugging following code is:

    Shared library architecture i386 is not compatible with target architecture i386:x86-64.
    "Cannot load library GP_MUC.dll: Unknown error 0x000000c1."
    After researching I found out that a i386 architecture means that my dll is a 32 bit dll. And since I am running my project with a 64-bit compiler I am not wondering anymore. But I could just not find a solution on the internet for this. Do I need to run my QT-Project with a 32bit Compiler or is there a chance using this 32 Bit Dll in my 64bit compiled QT-Project.

    I am using this code for loading my dll into my project.

    main.cpp:
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QApplication>
    4. #include <QLibrary>
    5. #include <QDebug>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. if (QLibrary::isLibrary("GP_MUC.dll")) {
    12. QLibrary lib("GP_MUC.dll");
    13. lib.load();
    14. if (!lib.isLoaded()) {
    15. qDebug() << lib.errorString();
    16. }
    17.  
    18. if (lib.isLoaded()) {
    19. qDebug() << "success";
    20.  
    21. // Resolves symbol to
    22. // void the_function_name()
    23. typedef int (*FunctionPrototype)();
    24. auto function1 = (FunctionPrototype)lib.resolve("MUX_Version");
    25.  
    26.  
    27. // if null means the symbol was not loaded
    28. if (function1) function1();
    29. }
    30. }
    31.  
    32. MainWindow w;
    33. w.show();
    34. return a.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 


    Maybe you can help me with giving me a hint or even giving me an example of how to do it.

    Kind regards
    Tim

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Library architecture i386 ist not compatible with target architecture i386:x86-64

    Is the DLL yours or something from an external source? If it is yours and you have the source code, just add a 64-bit configuration to the project if it isn't already there and build that configuration. If it is not yours and you only have a 32-bit binary version, then you are probably stuck with making your program 32 bits as well. See this Stackoverflow article for workarounds.

    Typically, you don't use LoadLibrary to load a DLL at run time. Instead you link the executable with the .lib export library that is produced along with the DLL and let Windows take care of loading it. The major exception is if you are developing some sort of plug-in architecture where you do not know the DLLs you will be loading at build time and must load them dynamically at run time.

    By the way, all 64-bit compilers I know of can also produce 32-bit binaries with the right compile and link flags.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    tim5 (3rd April 2021)

  4. #3
    Join Date
    Apr 2021
    Posts
    3
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Library architecture i386 ist not compatible with target architecture i386:x86-64

    [QUOTE=d_stranz;309698]Is the DLL yours or something from an external source? If it is yours and you have the source code, just add a 64-bit configuration to the project if it isn't already there and build that configuration. If it is not yours and you only have a 32-bit binary version, then you are probably stuck with making your program 32 bits as well. See this Stackoverflow article for workarounds.

    The DLL is from an external source/ company. I am creating a program for this company. I think I can ask them to add a 64bit Configuration.

    I've already tried making my program 32 bit. Now I have a LNK1107 Error - invalid or damaged file: reading at 0x2E0 not possible.

    I will have a try with the workarounds.

    Typically, you don't use LoadLibrary to load a DLL at run time. Instead you link the executable with the .lib export library that is produced along with the DLL and let Windows take care of loading it. The major exception is if you are developing some sort of plug-in architecture where you do not know the DLLs you will be loading at build time and must load them dynamically at run time.

    But I only have the DLL (and know about the functions within) I do not have .lib .h or .a files. I read that because of that I have to use LoadLibrary.
    By the way, all 64-bit compilers I know of can also produce 32-bit binaries with the right compile and link flags.


    Thanks a lot for you support.

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Library architecture i386 ist not compatible with target architecture i386:x86-64

    The DLL is from an external source/ company. I am creating a program for this company. I think I can ask them to add a 64bit Configuration.
    Then also ask them to provide you with the corresponding .lib file -and- the header files that define the exports from the library. Seems sort of ridiculous that a company would contract you to write code and then tie your hands behind your back. If they are creating the DLL, then they should certainly know enough to understand what is required to write code that uses it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    tim5 (3rd April 2021)

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,708
    Thanks
    13
    Thanked 1,603 Times in 1,530 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Library architecture i386 ist not compatible with target architecture i386:x86-64

    In some circumstances you can generate the link library (blah.lib) to match a DLL (blah.dll):
    GenerateLibFromDll
    This uses the Microsoft tools.
    You will still need the matching headers.

    The OP indicates that MingW is being used as the tool chain in this thread, but provides a linker error message that looks to be coming from a Microsoft tool chain in the other thread on this same topic.

  8. The following user says thank you to ChrisW67 for this useful post:

    tim5 (3rd April 2021)

  9. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Library architecture i386 ist not compatible with target architecture i386:x86-64

    The OP indicates that MingW is being used as the tool chain in this thread, but provides a linker error message that looks to be coming from a Microsoft tool chain in the other thread on this same topic.
    I think DLLs should be compatible no matter what build tool chain is used. It's the export libraries and other binary things that may not be. I believe that each compiler mangles names differently, so you will get linker errors if you try to link a binary from MingW with another produced by Microsoft if one uses definitions from the other.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Could not determine the target architecture!
    By sivakumar in forum Newbie
    Replies: 6
    Last Post: 26th May 2014, 17:13
  2. Replies: 8
    Last Post: 27th December 2013, 02:47
  3. compiling Qt on i386 to x86_64
    By plesken in forum Installation and Deployment
    Replies: 1
    Last Post: 6th October 2011, 13:12
  4. Test FrameBUffer On Ubuntu 10.10 i386 Cant Display ?
    By Thành Viên Mới in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 17th November 2010, 03:10
  5. Precompiled libs - Cocoa - ppc/i386/x86_64 ??
    By n9yty in forum Installation and Deployment
    Replies: 0
    Last Post: 29th July 2010, 16:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.