Cannot link Qt libs to C++ project manually.
-
https://download.qt.io/official_releases/vsaddin/2.7.1/
download this and add it into vs. Then create your qt project.@JoeCFD links don't work
-
@JoeCFD links don't work
@Sirzhatina Have you installed any qt vs addin? If not, you have problem to compile qt code with VS. The link is for you to download it for installation. The links works fine for me.
If you still can not open the link, look for: Qt vs addin download in google. Find a place to download it. -
Well if you promise only to use the MSVC compiler, then it's easy:
#include "C:/Qt/5.15.2/msvc2019/include/QtWidgets/qapplication.h" #include "C:/Qt/5.15.2/msvc2019/include/QtWidgets/qmessagebox.h" #pragma comment( lib, "C:/Qt/5.15.2/msvc2019/lib/qt5core" ) #pragma comment( lib, "C:/Qt/5.15.2/msvc2019/lib/qt5widgets" ) int main(int argc, char* argv[]) { QApplication a(argc, argv); QMessageBox::information(nullptr,"Look Ma no Qt Creator","Hello from the command line"); return a.exec(); }
@hskoglund said in Cannot link Qt libs to C++ project manually.:
#pragma comment( lib, "C:/Qt/5.15.2/msvc2019/lib/qt5core" )
Thanks, that was the MSVC I was trying to think of when I said
which cause it to stamp generated
.obj
files with what.lib
files they reference -
@hskoglund said in Cannot link Qt libs to C++ project manually.:
#pragma comment( lib, "C:/Qt/5.15.2/msvc2019/lib/qt5core" )
Thanks, that was the MSVC I was trying to think of when I said
which cause it to stamp generated
.obj
files with what.lib
files they reference -
@JonB Haven't used that #pragma directive in a loooong time, it's probably fallen out of fashion nowadays. But it still works if you need it :-)
@hskoglund
It was just a thought. I was trying to think how come the OP claims that when he used Boost with MSVC he did not have to add anyboost....lib
onto his link line and yet it "worked". My experience/understanding is that you do have to add the.lib
s you want when using MSVC (e.g. for the Qt libraries), it is not enough to just specify/LIBPATH:...
and miraculously the linker knows to look in which files. Am I right? Please read my posts above and comment if I am, or if I have misled the OP? -
@JonB some of boost is header-only so there's nothing to link. He may have been lucky and only used these parts of boost.
@SGaist Boost is also using this (imo) crappy msvc auto-link feature. It gaves me a lot of headaches due to static linking and the fact the the sources are also build on linux.
-
@JonB some of boost is header-only so there's nothing to link. He may have been lucky and only used these parts of boost.
@SGaist said in Cannot link Qt libs to C++ project manually.:
@JonB some of boost is header-only so there's nothing to link. He may have been lucky and only used these parts of boost.
Which is why I wrote earlier
It also states that most(?) of Boost is header-only. Could your usage happen to fall under this?
But the OP replied
I meant exactly separately-compiled part:)
So, the problem isn't out yet
Hence I don't know!
@Christian-Ehrlicher said in Cannot link Qt libs to C++ project manually.:
@SGaist Boost is also using this (imo) crappy msvc auto-link feature. It gaves me a lot of headaches due to static linking and the fact the the sources are also build on linux.
Which I also suggested to the OP might be why Boost but not Qt works without specifying the
.lib
s! :) -
@JonB some of boost is header-only so there's nothing to link. He may have been lucky and only used these parts of boost.
@SGaist It's really interesting, so let's make it clear.
I build the next codeboost::asio::io_context io; boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5)); std::cout << "Hey "; t.wait(); std::cout << "lala ley ";
And without next command
/link /LIBPATH:C:\Program Files (x86)\Boost\boost_1_76_0\stage\lib
I get linker error (no date-time library and so on - it's separately-compiled).
And, of course, adding this command, I have the program built successfully. So, as you can see I have no need to link exact .lib file excplicitly. -
@SGaist It's really interesting, so let's make it clear.
I build the next codeboost::asio::io_context io; boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5)); std::cout << "Hey "; t.wait(); std::cout << "lala ley ";
And without next command
/link /LIBPATH:C:\Program Files (x86)\Boost\boost_1_76_0\stage\lib
I get linker error (no date-time library and so on - it's separately-compiled).
And, of course, adding this command, I have the program built successfully. So, as you can see I have no need to link exact .lib file excplicitly.@Sirzhatina said in Cannot link Qt libs to C++ project manually.:
So, as you can see I have no need to link exact .lib file excplicitly.
We already explained why this works... but Qt does fortunately not support this.
-
@Sirzhatina said in Cannot link Qt libs to C++ project manually.:
So, as you can see I have no need to link exact .lib file excplicitly.
We already explained why this works... but Qt does fortunately not support this.
@Christian-Ehrlicher okay, thanks. But you said that's what msvc does. And I still use msvc to compile Qt libs, so what's the mystery here? I mean why does msvc auto-link one libraries and not auto-link others
-
@Christian-Ehrlicher okay, thanks. But you said that's what msvc does. And I still use msvc to compile Qt libs, so what's the mystery here? I mean why does msvc auto-link one libraries and not auto-link others
@Sirzhatina said in Cannot link Qt libs to C++ project manually.:
I mean why does msvc auto-link one libraries and not auto-link others
see the answer from @hskoglund - this is basically what the boost libs are doing and Qt not (because it's crappy, error-prone and non-portable)