私はSQLクエリと結果にSQLPP11、データベースに接続するにはSQLPP11-Connector-mysqlを使用しています。`sqlpp :: mysql :: connection ::〜connection() 'への未定義の参照
そして
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です。
libsqlpp-mysqlは、ライブラリを使用しようとしていたものとは別のコンパイラで構築されていることを強く示唆しています。私はあなたが 'g ++ - 5'または' g ++ - 6'を使ってライブラリをビルドするようにCMakeに指示した場合、システムのデフォルトの代わりに問題が消えるだろうと賭けています。 – ildjarn