C++ / mysql Connector - undefined reference to get_driver_instance - already tried the easy stuff

后端 未结 4 907
后悔当初
后悔当初 2020-12-08 10:37

Yes this question has been asked before ... I\'ve tried everything mentioned in the previous answers. My setup is really straightforward so this shouldn\'t be so hard.

4条回答
  •  再見小時候
    2020-12-08 11:37

    So I have now had this problem for a week now and I became very frustrated with it as well. I just now was able to finally build a program that does nothing except login to mysql and I literally squealed with joy. Here is what I have and I hope it helps.

    I first compiled the c++ connector library from source but after a while I thought maybe I did something wrong so I then just used apt to get it with:

    sudo apt-get install  libmysqlcppconn-dev
    

    And here is my simple tester source file "tester.cpp"

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    using namespace sql;
    int main(void){
      sql::Driver *driver;
      sql::Connection *con;
    
      driver = get_driver_instance();
      con = driver->connect("tcp://127.0.0.1:3306","root","YOURPASSWORD");
    
      return 0;
    }
    

    And finally g++ compile command:

    sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn
    

    This worked for me and I hope it helps you solve your problem!

提交回复
热议问题