Linker issues only in QT Creator using MinGw64
-
Hi there!
Houston, I have a problem with my Linker.
Things i did:
I wrote a library for Windows in VS and compiled in the IDE, obtaining the .lib and .h files. Tested the library in a new project in VS (console application). The library works as expected. Copied the .lib and .h files in library/lib and library/include directories inside the QT proj. Imported the library in QTCreator using the import library tool.After these steps, the compiler reports no errors but the linker reports "undefined reference" for every symbol of the library i use in the main of the QTCreator app.
My question is: why i cannot include and use a library in QTC while that library works perfectly on other IDEs? I will try on more environments and give updates here.
Inside the library there's a single class declared in the .h and defined in the .cpp as usual.
-
Hi and welcome to devnet,
It's because you can't mix and match C++ libraries built with Visual Studio and MinGW.
Also, Visual Studio started to have backward compatibility only since the 2017 release.
-
Hello and thank you.
The problem is:
I have to use some windows system calls that are compilable only by linking windows sdk, which is in .lib format.I was not able to build those calls using QTCreator and MinGw, so i thought i could build a library (which make use of those calls) in visual studio, and then export that library to QT Creator for being compiled with MinGW.
So if you say there's no possibility to make mixes, i have no idea how to solve this problem than.
Let me know if some sort of solution exists.
-
Which system calls do you need ?
-
I need IPropertyStorageInterface sys calls, to manage COM object and modify/read file details like "Author" or "Tag" and others..
I didn't find anyone who used those, the only one way to accomplish this was using those libraries, taken from Windows SDK installation, and using Visual Studio, because MinGw apparently doesn't like Windows libraries. -
Hello and thank you.
The problem is:
I have to use some windows system calls that are compilable only by linking windows sdk, which is in .lib format.I was not able to build those calls using QTCreator and MinGw, so i thought i could build a library (which make use of those calls) in visual studio, and then export that library to QT Creator for being compiled with MinGW.
So if you say there's no possibility to make mixes, i have no idea how to solve this problem than.
Let me know if some sort of solution exists.
@Mr-Calogero said in Linker issues only in QT Creator using MinGw64:
i have no idea how to solve this problem than.
You can use MSVC++ compiler instead of MinFW (of course you have also to install MSVC++ Qt build).
-
@Mr-Calogero said in Linker issues only in QT Creator using MinGw64:
i have no idea how to solve this problem than.
You can use MSVC++ compiler instead of MinFW (of course you have also to install MSVC++ Qt build).
@jsulm Thank you, i managed to solve my problem.
moral of the story: If you want to use windows apis which are part of the windows sdk and are inside a .lib file, you have to use MSVC.
I recompiled my factotum library i developed for years in MSVC, and now i am able to compile softwares for windows and use my library at the same time, with the difference that now i can compile windows api .lib files with no problem (i'm not sure if mingw supports them, i read somewhere it only supports 32bit libraries, not sure if it's true).
-
MinGW supports both 32 and 64 bits.
-
@SGaist Btw, for some reason it cannot link some Microsoft libraries in .lib file
-
Are these static or dynamic librairies ?
If the later, did you properly export the symbols of your library ? -
I tried both static and dynamic libraries.
I would rather dynamic ones. I have a library that i use in all my softwares and when i compile i can find the .dll file only. I take that and all the headers files and copy them to the project that uses this library, but it cannot resolve symbols because it requires an import library (.lib), so it compiles because it finds all the headers but it does not link and so it fails. -
Then the important point: are you properly exporting you libraries symbol ?
-
What do you mean? With MinGw i used to simply compile and deploy the library. I setted up the IDE with install argument and all the install paths so it used to export in /dist all the header (copied) and the .a and .dll files, and it used to work like a charm. I don't know how to do it with MSVC neither where to find infos on how to do it. I'm just compiling and getting the .dll (or .lib if i configure for static library) and that's it...I'm probably forgetting something.
-
-
I've never find such a page.. although i looked for it for a lot.
I managed to compile my library but it does not work on the client side. It's because i have some classes such:class Q_DECL_EXPORT myClass : std::exception { //blablabla }and so, it doesn't work because while there's not problem with "myClass", base class "exception" of C++ must be "exportable", and it's not.
How can i export in the dll exporting table a symbol of the C++ system libraries?
-
You did not follow the example correctly. You are not supposed to use the two Qt macros directly.
Create your own that will use them both like shown in the documentation I linked.
-
I did everything correctly. I created my own macro and used it, i wrote "Q_DECL_EXPORT" in the example to clarify. I don't even have a class called "myClass" for that matter.
-
Symbol exportation does not apply only to classes.
Can you show your actual code ?
-
Thank you, i solved the problem! Now everything works fine, there was an unhandled exception in my code and i thought it was a link issue but it wasn't. The library builds and links with no problem now, thanks again!