Problem compiling projects within solutions in MSVC 2017
-
Hi all
After several days trying, I've had to come to the forum, just to know if anyone has suffered anything similar and solved it.
I am developing a personal project where I make an extensive use of some boost capabilities. After making a simple console application to check that the libraries I had implemented worked as expected, I decided to take a step further and use QT to create GUIs exploiting those capabilities. I used to use QT at university, but in a completely different environment. I remembered though that you could easily integrate it within your IDE. My whole project has been implemented in Visual Studio Community 2017, so, why change? I downloaded the online installer, installed QT 5.12.3, following the instructions, etc.
First thing I realized was that creating a simple GUI from QT Creator was possible, but if I run this app directly, errors about finding the proper dll were shown. I could solve this in a very short time, either by using the deployment tool or by adding QT to PATH.
Next step, try the QT VS Tools plugin. Again, after adding the proper version of QT, I am able to create a project within the solution I was using for my project so far. First problem: even though QT folder was added to the path when launching the exe from VS, I still got sometimes the dll error. But worse yet, when the dll was found (i.e. building and the using the qt deployment tool), I got a weirder error:
"The procedure entry point NetApiBufferFree could not be located in the dynamic library..."
After several attempts with different QT versions, I got to a "solution" (compiling release version of QT 5.12.2 from sources as shared libraries) where:
1- If I create a project with QT Creator I can launch it from there without any problem from QT Creator and no problems externally if manual deployment performed (only compiled qtbase). Good.
2- If I create an isolated project in Visual Studio (default GUI Application), I can run it from VS without any problem. Again, I can run it from explorer after manual deployment. So far, so good. I thought I got it.
3- If I create a project in Visual Studio, exactly like the previous one, within the previous Solution, the same error appears again, no matter if executed from VS or externally, no matter if I make the deployment or not:
"The procedure entry point NetApiBufferFree could not be located in the dynamic library..."Any idea on how to solve it? I know I could remake the solution again and try, but it is a large one with many crossed dependencies... Anyway, I would like to know what the problem is, in order to avoid it in the future. Thanks a lot!
-
Hi @MateoAero, and welcome!
@MateoAero said in Problem compiling projects within solutions in MSVC 2017:
I could solve this... by adding QT to PATH.
Please don't add Qt to your PATH. This can break other programs that use Qt.
Remove Qt from your PATH and always use the deployment tool.
"The procedure entry point NetApiBufferFree could not be located in the dynamic library..."
What is the last bit of this message? What is the name of the dynamic library? (I'm expecting it to be "Netapi32.dll": https://docs.microsoft.com/en-us/windows/desktop/api/lmapibuf/nf-lmapibuf-netapibufferfree )
The error message means that your application loaded the expected DLL, but it couldn't find the function
NetApiBufferFree()
in the DLL.So, you need to investigate:
- Which copy of this DLL is the application using? (Use a tool like Dependency Walker to see which DLLs are being loaded)
- Is this DLL valid?
You can also transfer your application to a different PC and see if it runs there. If it runs on your other PC, that means your current PC is corrupted.
-
Hi
Thanks for the quick response. I know adding Qt to path is not good, I just tried once to see if it was the problem, then quickly removed.
The missing part of the error message is the path to qt5core DLL. It either points to deployed DLL within the exe folder, or to the path of my generated DLL files. So it seems it finds a problem with the DLL (no matter if I compiled it from sources or installed directly the binaries) when the project is part of a larger solution. I have checked several times and the options of both projects, the one isolated and the one within the solution, are identical.
Thanks again.
-
@MateoAero said in Problem compiling projects within solutions in MSVC 2017:
The missing part of the error message is the path to qt5core DLL.
This sounds very odd.
NetApiBufferFree()
is definitely not part of Qt5Core.dll...!It either points to deployed DLL within the exe folder, or to the path of my generated DLL files. So it seems it finds a problem with the DLL (no matter if I compiled it from sources or installed directly the binaries) when the project is part of a larger solution. I have checked several times and the options of both projects, the one isolated and the one within the solution, are identical.
Can you reproduce this issue in a small test project?
(Alternatively, back up your project and gradually remove large chunks of code from it until the issue disappears)
-
I just created the default GUI application in visual studio. When it's done within a solution, this happens. When I create it as a standalone project, it works. I only compiled this project, not the whole solution, for it's a simple empty window with no controls or interaction with other code. I don't know if there might be some differences in VS regarding compilation within a solution or standalone (AFAIK there aren't). I will try later with other solutions and will let you know the outcome, if lucky.
Here the proof:
-
I think I got something. I just created a new solution. I started adding one by one my previous projects (cloned, just in case I broke anything). I then add a new default QT GUI Application and, weird as it is, it happens again, the very same error. I know that function is not implemented in that DLL, but the error says what it says. Something suddenly lights on my head: the only actual difference I have between cases where it is working fine and where it fails is that there are other files within the output folder. So I clean my solution, compile the QT project and voila! Should this happen this way? I think that in this case I am gonna have trouble integrating my own dlls with QT... Any ideas?
-
You are not gonna believe it... By chance, I was generating a separate DLL called "NetUtils.dll". Guess what: there is a DLL named exactly the same as part of windows. Therefore, it seems that during the DLL lookup, whenever qt5core.dll called the NetApiBufferFree function, in the end it was trying to find it in my DLL instead of in the one located in Windows files... So, many thanks, @JKSH, for your incredibly quick help, I didn't expect to get some before next week, really.
-
@MateoAero said in Problem compiling projects within solutions in MSVC 2017:
I was generating a separate DLL called "NetUtils.dll". Guess what: there is a DLL named exactly the same as part of windows. Therefore, it seems that during the DLL lookup, whenever qt5core.dll called the NetApiBufferFree function, in the end it was trying to find it in my DLL instead of in the one located in Windows files...
I gotta say, this is the first time I've seen DLL Hell happen this way :-D
Anyway, I'm glad you've resolved your issue. Happy coding!