Can't compile Qt project with QtSQL (linker errors) - c++

I'm trying to compile a qt project (within Qt Creator 2.7.0 on Qt 5.0.2) and I keep getting linker errors that have to do with the QtSQL library (KioskBridge is the file/class that I am using sql in):
kioskbridge.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlDatabase::QSqlDatabase(void)" (__imp_??0QSqlDatabase##QEAA#XZ) referenced in function "public: __cdecl KioskBridge::KioskBridge(class Html5ApplicationViewer *)" (??0KioskBridge##QEAA#PEAVHtml5ApplicationViewer###Z)
My pro file includes QT += sql, but that doesn't seem to make it link with the appropriate libraries.
Any ideas?

After you modify the .pro file you will need to run qmake (that will re-generate the makefiles with the right dependencies) and only after that you can successfully link your application with the newly added modules.

Related

C++ - Unable to link in libyaml using Visual Studio 2019/CMake

Attempting to link in libyaml (0.2.5) using Visual Studio 2019 Enterprise and CMake, as I have a cross-platform (Linux/Windows) project that uses this library. According to the documentation, this library should work in Windows 10. It links in just fine on Linux (64-bit machine).
I'm compiling it as a static lib, and it has no issue generating the .lib file. I've copied it to the appropriate location that I'm linking in from my CMakelists.txt, as well as the header.
When I link it in from my project on Windows:
ts.lib(yamlparser.cxx.obj) : error LNK2019: unresolved external symbol __imp_yaml_parser_initialize referenced in function "public: bool __cdecl YAMLParser::parse_cfg(void)" (?parse_cfg#YAMLParser##QEAA_NXZ)
ts.lib(yamlparser.cxx.obj) : error LNK2019: unresolved external symbol __imp_yaml_parser_set_input_file referenced in function "public: bool __cdecl YAMLParser::parse_cfg(void)" (?parse_cfg#YAMLParser##QEAA_NXZ)
ts.lib(yamlparser.cxx.obj) : error LNK2019: unresolved external symbol __imp_yaml_parser_scan referenced in function "public: bool __cdecl YAMLParser::parse_cfg(void)" (?parse_cfg#YAMLParser##QEAA_NXZ)
This is what I'm doing on the CMake side - the very same thing I'm doing to link in my GoogleTest libraries on both Linux and Windows:
if (UNIX)
...
...
else()
set (MY_LIB_DIR "C:/mylib/lib")
set (MY_INCLUDE "C:/mylib/include")
set (YAML_LIB "${MY_LIB_DIR}/yaml.lib")
set (VCPKG_LIBRARY_LINKAGE static)
endif()
include_directories(${MY_INCLUDE})
add_library(ts
...
...
)
add_executable(myexec main.cxx)
target_link_libraries(myexec ts ${YAML_LIB})
VS isn't giving me many clues here except that there's a linkage problem that I can't quite figure out.
Any advice on how I can debug this or what the problem may be?
The __imp was the clue that my code was trying to include the library dynamically... Opening up yaml.h, I noticed that it tries to export from DLL unless YAML_DECLARE_STATIC is defined. Defined this in CMake and my issue is resolved.

Including Lua in VS2015 C++ Project

I would like to integrate Lua into my current C++ application I build with VisualStudio 2015 (x64 mode).
I grabbed a simple Lua wrapper from here, and the Lua binaries for windows x64 from here (the lua-5.1.5_Win32_dll14_lib.zip one).
Next, I added the include and library path to the project preferences. Works so far in the IDE. However, when I try to compile the code it throws 24 errors (like these first two):
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_close" referenced in function ""public: __cdecl LuaScript::~LuaScript(void)" (??1LuaScript##QEAA#XZ)".
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_gettop" referenced in function ""public: void __cdecl LuaScript::clean(void)" (?clean#LuaScript##QEAAXXZ)".
which tells me next to nothing. Seems that the linker is unable to find the library but the includes are working and the path to library is set, too. Any suggestions what I might have missed or should look into? Any hint would be appreciated!

How to build a static Clucene library to avoid any linker errors

I work with Windovs and I need to build a static CLucene library. I downloaded the latest source code and build them into Visual Studio 2010 Project through CMake-gui 3.4.3. When building I used a flag BUILD_STATIC_LIBRARIES = true. I successfully built two libraries: clucene-core-statics and clucene-shared-static. However, when I run the test project cl-test-static occurs a lot of linker errors. The same thing happens when I add these libraries in another test project.
Error Example:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: static wchar_t * __cdecl
lucene::queryParser::QueryParser::escape(wchar_t const *)"
(__imp_?escape#QueryParser#queryParser#lucene##SAPA_WPB_W#Z)
referenced in function "public: void __thiscall Main::Start(void)"
(?Start#Main##QAEXXZ) c:\Users\user\documents\visual studio
2010\Projects\TestClucene\TestClucene\Main.obj TestClucene
Does anyone have any experience in building static CLucene libraries?

Problems with SOCI

I'm trying to use the SOCI library for easy MySQL access but I'm stuck at installing the library.
What I've done so far is :
Made the project and compiled it with CMake
Linked my project to the lib/release directoy that's created after compilation.
Linked my project to the MySQL C Connector lib directory
and here are my additional include directories :
http://puu.sh/6qGNP.png
But somehow, when I compile the example program, I get a bunch of linker errors like these :
1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall soci::details::standard_into_type::~standard_into_type(void)" (??1standard_into_type#details#soci##UAE#XZ) referenced in function "public: virtual __thiscall soci::details::into_type::~into_type(void)" (??1?$into_type#H#details#soci##UAE#XZ)
1>main.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall soci::details::standard_into_type::post_fetch(bool,bool)" (?post_fetch#standard_into_type#details#soci##MAEX_N0#Z)
Where did I mess up?
From the documentation:
Required Client Libraries
The SOCI MySQL backend requires MySQL's libmysqlclient client library.
Note that the SOCI library itself depends also on libdl, so the minimum set of libraries needed to compile a basic client program is:
-lsoci_core -lsoci_mysql -ldl -lmysqlclient
This has always worked for me. If you want to link them from the build location a -L switch with the path to the libraries will need to be passed to the compiler.

Building a minimal Qt Console Project fails with a cryptic Linker Error LNK2001: Unresolved external Symbol

I am trying to compile a minimal Qt Console application with event loop and a custom class with inline definition of its constructor like https://stackoverflow.com/a/4182144/1619432 and get three cryptic linker errors (using Qt 4.8.1 and MSVC 2010 Express C++):
main.obj:-1: error: LNK2001: Unresolved external symbol ""public: virtual struct QMetaObject const * __thiscall ....
with ::metaObject, ::qt_metacast, ::qt_metacall.
#include "main.moc"
just above the int main(...) is critical. If the file is not found, try cleaning the project / deleting the build directories, running qmake, restarting Qt Creator or even the whole system.
This may have to do with paths in environment variables (maybe set previously by a different project).
Another common reason seems to be a forgotten Q_OBJECT macro in the class declaration, or as above, run qmake after including it.
Good luck!