对 `sqlpp::mysql::connection::~connection()' 的未定义引用

undefined reference to `sqlpp::mysql::connection::~connection()'

我正在使用 SQLPP11 for sql queries and results and SQLPP11-Connector-mysql 与数据库建立连接。

并使用

编译我的程序
g++ -std=c++1y main.cpp -I ../date -lsqlpp-mysql -lmysqlclient -lboost_system -lpthread

这是我正在使用的示例代码。

bool db_connection()
{
    auto config = std::make_shared<mysql::connection_config>();
    config->user = "root";
    config->password = "";
    config->database = "test";
    config->debug = true;
    sqlpp::mysql::connection db(config);
    try
    {
        sqlpp::mysql::connection db(config);
        std::cout << "Database connection establish...!!\n";

        std::cout << "Now executing a very simple select query in table using sqlpp11 \n";

        const auto g = changestreet::Goals{};
        for(const auto& row :  db(select(all_of(g)).from(g).unconditionally()))
        {
            std::cerr << row.goalId << "\n";
            std::cerr << row.goalName << "\n";
            std::cerr << row.goalAmount << "\n";
        }

    }
    catch (const sqlpp::exception& e)
    {
        std::cerr << "No such database exits, you'll need to create it. \n";
        std::cerr << e.what() << std::endl;
        return false;
    }

    return true;
}

错误是

/tmp/ccxRheKs.o: In function `db_connection_cs()':
main.cpp:(.text+0x39d): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)'
main.cpp:(.text+0x3c8): undefined reference to `sqlpp::mysql::connection::~connection()'
main.cpp:(.text+0x400): undefined reference to `sqlpp::mysql::connection::~connection()'
/tmp/ccxRheKs.o: In function `db_connection_nav()':
main.cpp:(.text+0x4bf): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)'
main.cpp:(.text+0x4ea): undefined reference to `sqlpp::mysql::connection::~connection()'
main.cpp:(.text+0x522): undefined reference to `sqlpp::mysql::connection::~connection()'
/tmp/ccxRheKs.o: In function `sqlpp::mysql::serializer_t::escape(std::string)':
main.cpp:(.text._ZN5sqlpp5mysql12serializer_t6escapeESs[_ZN5sqlpp5mysql12serializer_t6escapeESs]+0x2a): undefined reference to `sqlpp::mysql::connection::escape(std::string const&) const'
/tmp/ccxRheKs.o: In function `sqlpp::result_t<sqlpp::mysql::char_result_t, sqlpp::result_row_t<sqlpp::mysql::connection, sqlpp::field_spec_t<changestreet::Goals_::GoalId::_alias_t, sqlpp::integral, false, false>, sqlpp::field_spec_t<changestreet::Goals_::GoalName::_alias_t, sqlpp::text, true, false>, sqlpp::field_spec_t<changestreet::Goals_::GoalAmount::_alias_t, sqlpp::floating_point, true, false>, sqlpp::field_spec_t<changestreet::Goals_::GoalStartTime::_alias_t, sqlpp::day_point, true, false>, sqlpp::field_spec_t<changestreet::Goals_::GoalEndTime::_alias_t, sqlpp::day_point, true, false>, sqlpp::field_spec_t<changestreet::Goals_::GoalMonthlyContribution::_alias_t, sqlpp::floating_point, true, false>, sqlpp::field_spec_t<changestreet::Goals_::GoalStatus::_alias_t, sqlpp::text, true, false>, sqlpp::field_spec_t<changestreet::Goals_::UsersUserId::_alias_t, sqlpp::integral, true, false> > >::~result_t()':
main.cpp:(.text._ZN5sqlpp8result_tINS_5mysql13char_result_tENS_12result_ro

这是我的 64 位 debian 机器上两个库的 build logs

"undefined reference to"通常表示链接器找不到需要的库。确保您的 PATH 环境在范围内包含那些库 sqlpp-mysql mysqlclient。

终于找到解决方法了

是g++版本的问题。最近的版本 g++-5g++-6 有这样的问题,但是当我回到旧的 g++ 版本 4.9.2 时,一切都 运行 顺利。