2016-11-19 2 views
-1

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 비트 데비안 시스템의 라이브러리 모두의 build logs입니다 있습니다.

답변

1

마지막으로, 나는 해결책을 찾아 냈습니다.

g ++ 버전에서 문제가 발생했습니다. 최근 버전 g++-5g++-6에는 이러한 문제가 있습니다. 그러나 이전 버전 인 g++ 버전 4.9.2로 돌아 가면 모든 것이 원활하게 실행됩니다.

+1

libsqlpp-mysql이 라이브러리를 사용하려고했던 컴파일러와 다른 컴파일러로 빌드되고 있음을 강력하게 암시합니다. 나는 당신이 CMake에게 시스템 디폴트가 아닌'g ++ - 5' 또는'g ++ - 6' 라이브러리를 빌드하라고 말하면 문제가 사라질 것이라고 맹세합니다. – ildjarn

0

"정의되지 않은 참조"는 대개 링커에서 필요한 라이브러리를 찾을 수 없음을 의미합니다. PATH 환경에 해당 범위의 sqlpp-mysql mysqlclient 라이브러리가 있는지 확인하십시오.

+1

사용자가 지정한 라이브러리를 찾을 수없는 경우 링커에서 오류를 발생시키지 않았습니까? – ildjarn

+0

음. 사용자가 여러 버전의 라이브러리를 설치했을 수 있으며 링커를 혼동시키는 내용 (경로, .so 이름 등)이있을 수 있습니다. – Ripi2

관련 문제