Search code examples
linuxg++raspbianmariadb-connector-c

Undefined reference to mariadb::account::create()


I want to code an app by C++ and using MySQL database in it. I used mariadbclientpp library. So I cloned it and compiled it in windows vs 2019 and it worked fine. But when I want do this in Raspbian, I got below linking error:

/usr/bin/ld: /tmp/ccJjO2Jo.o: in function `main':

sqltest.cpp:(.text+0xd8): undefined reference to `mariadb::account::create(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&, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status

I'm completely new in Linux so I did search a lot and I tried some fixes but none of them help me. I tried this ways to compile my code:

1

g++ mysqltest.cpp  -I/usr/include/mariadb -L/usr/lib/arm-linux-gnueabihf/ -lmariadb -I/usr/local/include/mariadb++/ -L/usr/local/lib/libmariadbclientpp.a

2

 g++ -o mysqltest sqltest.cpp -lstdc++ -I/usr/include/mariadb/ $(mariadb_config --libs)

Any idea, Please?


Solution

  • I found out the problem. I was about static library. The static library add without -L option so I changed command to this:

    g++ mysqltest.cpp /usr/local/lib/libmariadbclientpp.a -I/usr/include/mysql
    

    and ti's done.