Issue regarding the overloading of SQLite::Statement::bind
Using nm -gC libSQLiteCpp.a | grep SQLite::Statement::bind to get the result. U SQLite::Statement::bind(int, char const*) U SQLite::Statement::bind(int, std::string const&) 0000000000000594 T SQLite::Statement::bindNoCopy(int, char const*) 00000000000005e6 T SQLite::Statement::bindNoCopy(int, void const*, int) 000000000000051c T SQLite::Statement::bindNoCopy(int, std::string const&) 000000000000063a T SQLite::Statement::bind(int) 0000000000000474 T SQLite::Statement::bind(int, char const*) 00000000000004c8 T SQLite::Statement::bind(int, void const*, int) 00000000000003fc T SQLite::Statement::bind(int, std::string const&) 00000000000003ac T SQLite::Statement::bind(int, double) 00000000000002c8 T SQLite::Statement::bind(int, int) 0000000000000310 T SQLite::Statement::bind(int, unsigned int) 0000000000000362 T SQLite::Statement::bind(int, long)
my code↓ const std::string &softId is a formal parameter.
try
{
SQLite::Statement query(SQLITE_DB, "UPDATE local_softs SET install_status = ? WHERE soft_id = ?");
query.bind(1, installResult != 0 ? 2 : 1);
query.bind(2, softId);
query.exec();
}
catch (const std::exception &e)
{
spdlog::error("InstallError: {}", e.what());
}
libSQLiteCpp.a|libsqlite3.a was compiled in Scenario 2 environment.
target_link_libraries(xp-tasks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/libSQLiteCpp.a)
target_link_libraries(xp-tasks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/libsqlite3.a)
Scenario 1
os version:g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
sqlite version:3.31.1
error:/usr/bin/ld: CMakeFiles/xp-tasks.dir/src/task/task.cpp.o: in function Task::Install(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/pya789/project/xp-tasks/src/task/task.cpp:172: undefined reference to SQLite::Statement::bind(int, std::__cxx11::basic_string<char, std::char_traits
tips Using softId.c_str() is normal in this case because it conforms to the signature of SQLite::Statement::bind(int, char const*). This means that the char const* type returned by softId.c_str() can be passed as a parameter to the bind function, allowing it to be used normally in this situation.
Scenario 2 os version:g++ (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2) sqlite version:3.7.17 Everything is normal
My English is not good, using translation, sorry.😂