Reputation: 81
I'm now trying to implement a server using c++, I try to save the information of the users into database, but I came across some problem while connecting to the database. I can't build my program because of the following errors generated by code blocks
-------------- Build: Debug in server (compiler: GNU GCC Compiler)--------------- mingw32-g++.exe -Wall -fexceptions -g -lpthread -lmysql -I"D:\Program Files\MariaDB 10.1\include\mysql" -c D:\Projects\server\main.cpp -o obj\Debug\main.o mingw32-g++.exe -L"D:\Program Files\MariaDB 10.1\lib" -o bin\Debug\server.exe obj\Debug\main.o "D:\Program Files (x86)\CodeBlocks\MinGW\lib\libwinpthread.a" "D:\Program Files (x86)\CodeBlocks\MinGW\lib\libws2_32.a" obj\Debug\main.o: In function `main': D:/Projects/server/main.cpp:13: undefined reference to `mysql_init@4' D:/Projects/server/main.cpp:14: undefined reference to `mysql_real_connect@32' collect2.exe: error: ld returned 1 exit status Process terminated with status 1 (0 minute(s), 2 second(s)) 3 error(s), 3 warning(s) (0 minute(s), 2 second(s))
I downloaded MariaDB Connector/ODBC 2.0.10 Stable from its official website and I've tried many different solutions that I found on the Internet, but it still doesn't work. Can anybody help me solve this? Any reply will be appreciated.
Upvotes: 1
Views: 482
Reputation: 6999
GNU linker is sensitive to option order. If you are using libmysql in main, option -lmysql
shall go after main.o
UPD: I noticed you even haven't libs in second linking string. In first string it is useless, add to second, where actual linking takes place.
Upvotes: 1