I’m following the example from here and my code is identical.
When I type mysql_config –libs and mysql_config –cflags into the console as he explains, I get the same output as he shows. Yet, when I try to compile using
g++ -o output-file $(mysql_config –cflags) test.cpp $(mysql_config
–libs)
I get the errors:
test.cpp:3:25: error: mysql.h: No such file or directory
test.cpp: In function âint main()â:
test.cpp:6: error: âMYSQLâ was not declared in this scope
test.cpp:6: error: âconnâ was not declared in this scope
test.cpp:7: error: âMYSQL_RESâ was not declared in this scope
test.cpp:7: error: âresâ was not declared in this scope
test.cpp:8: error: âMYSQL_ROWâ was not declared in this scope
test.cpp:8: error: expected `;’ before ârowâ
test.cpp:13: error: âmysql_initâ was not declared in this scope
test.cpp:17: error: âmysql_real_connectâ was not declared in this scope
test.cpp:18: error: âmysql_errorâ was not declared in this scope
test.cpp:19: error: âexitâ was not declared in this scope
test.cpp:22: error: âmysql_queryâ was not declared in this scope
test.cpp:23: error: âmysql_errorâ was not declared in this scope
test.cpp:24: error: âexitâ was not declared in this scope
test.cpp:27: error: âmysql_use_resultâ was not declared in this scope
test.cpp:31: error: ârowâ was not declared in this scope
test.cpp:31: error: âmysql_fetch_rowâ was not declared in this scope
test.cpp:35: error: âmysql_free_resultâ was not declared in this scope
test.cpp:36: error: âmysql_closeâ was not declared in this scope
When I try ‘whereis mysql’ it shows /usr/bin/mysql, /usr/lib/mysql and /usr/share/mysql, but I’m not sure where mysql.h is located exactly. The admin of the server I’m working on said he installed MySQL and I can indeed create/manipulate tables using phpMyAdmin.
Also, please give me suggestions about this particular problem. I’m aware of C++ wrappers for MySQL but I’m trying to just use the C API for now. Thanks!
Here the code compiles fine (I just had to include stdlib.h for exit()). MySQL headers should be in /usr/include/mysql, and since you got the same output for “mysql_config –cflags”, you probably have a missing/broken package.
Try reinstalling the packages he list on the begining of the article, or check in which package the headers are in your distro. I’m am using Ubuntu, and here the package with the headers is libmysqlclient15-dev.