Here is my Common
library CMakeLists.txt
file:
add_library(
Common
SHARED
Config.cpp
Config.h
Logger.cpp
Logger.h
Database/DatabaseLoader.cpp
Database/DatabaseLoader.h
Database/MySQLConnection.h
Database/MySQLConnection.cpp
Database/MySQLTable.h
Database/MySQLTable.cpp
)
if(WIN32)
# Add the MySQL include directories to this target.
target_include_directories(Common PUBLIC
${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/jdbc
)
target_include_directories(Common PUBLIC
${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/jdbc/cppconn
)
# Link the MySQL library to your executable.
target_link_libraries(Common PUBLIC
${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64/vs14/mysqlcppconn8.lib
)
else()
target_link_libraries(Common LINK_PUBLIC ${MYSQL_LIBRARY} mysqlcppconn)
endif()
target_include_directories(Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Here is the function which triggers the error:
void MySQLConnection::Connect(MySQLConnectionInfo &mySqlConnectionInfo) {
const sql::SQLString hostname = "tcp://" + mySqlConnectionInfo.host + ":" + mySqlConnectionInfo.mysqlPort;
try {
//* Create a connection *//*
_driver = get_driver_instance();
_mySQLConn = _driver->connect(hostname, mySqlConnectionInfo.mysqlUser, mySqlConnectionInfo.mysqlPassword);
//* Connect to the MySQL test database *//*
_mySQLConn->setSchema(mySqlConnectionInfo.mysqlDatabase);
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
}
When I try to build I get the following error:
[100%] Linking CXX shared library ..\..\bin\Common.dll
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.1.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1424~1.283\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\Common.dir\objects1.rsp /out:..\..\bin\Common.dll /implib:..\..\bin\lib\Common.lib /pdb:E:\Vibranium-Core\cmake-build-debug\bin\Common.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL C:\Program Files\MySQL\Connector C++ 8.0\lib64\vs14\mysqlcppconn8.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\Common.dir/intermediate.manifest CMakeFiles\Common.dir/manifest.res" failed (exit code 1120) with the following output:
MySQLConnection.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QEAA@XZ) referenced in function "private: void __cdecl Vibranium::MySQLConnection::Connect(struct Vibranium::MySQLConnectionInfo &)" (?Connect@MySQLConnection@Vibranium@@AEAAXAEAUMySQLConnectionInfo@2@@Z)
MySQLTable.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QEAA@XZ)
MySQLConnection.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sql::SQLString::SQLString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0SQLString@sql@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: void __cdecl Vibranium::MySQLConnection::Connect(struct Vibranium::MySQLConnectionInfo &)" (?Connect@MySQLConnection@Vibranium@@AEAAXAEAUMySQLConnectionInfo@2@@Z)
MySQLTable.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sql::SQLString::SQLString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0SQLString@sql@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
MySQLConnection.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$?Connect@MySQLConnection@Vibranium@@AEAAXAEAUMySQLConnectionInfo@2@@Z$0
MySQLTable.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
MySQLConnection.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QEBAHXZ) referenced in function __catch$?Connect@MySQLConnection@Vibranium@@AEAAXAEAUMySQLConnectionInfo@2@@Z$0
MySQLTable.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __cdecl sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QEBAHXZ)
MySQLConnection.cpp.obj : error LNK2019: unresolved external symbol __imp_get_driver_instance referenced in function "private: void __cdecl Vibranium::MySQLConnection::Connect(struct Vibranium::MySQLConnectionInfo &)" (?Connect@MySQLConnection@Vibranium@@AEAAXAEAUMySQLConnectionInfo@2@@Z)
..\..\bin\Common.dll : fatal error LNK1120: 5 unresolved externals
Note that I receive this build error only on Windows. On Linux it builds fine. By my understanding I have a problem with the mysql connector. I have installed the connector and I have the files. Take a look:
Where is my mistake and how can I solve it?
The linker didnt find the correct symbols for mysqlconnector library.
Either you didn't setup the library path correctly
or
you are using the libraries compiled with different options or with different compiler.
User contributions licensed under CC BY-SA 3.0