I am trying to run the MariaDB firmware (i.e., not connecting to a running server), but I cannot get any of the examples that I find to work.
The most recent example from this post: stack overflow
When the application starts, it produces: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Documents https://mariadb.com/kb/en/library/embedded-mariadb-interface/ help a lot with this.
For convenience, the code from this StackOverflow post:
#include <my_global.h> #include <mysql.h> int main(int argc, char **argv) { static char *server_options[] = { "mysql_test", // An unused string "--datadir=/tmp/mysql_embedded_data", // Your data dir NULL }; int num_elements = (sizeof(server_options) / sizeof(char *)) - 1; static char *server_groups[] = { "libmysqld_server", "libmysqld_client", NULL }; // Init MySQL lib and connection mysql_library_init(num_elements, server_options, server_groups); MYSQL *con = mysql_init(NULL); if (con == NULL) { fprintf(stderr, "%s\n", mysql_error(con)); exit(1); } mysql_options(con, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client"); mysql_options(con, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL); // Connect to no host/port -> Embedded mode if (mysql_real_connect(con, NULL, NULL, NULL, NULL, 0, NULL, 0) == NULL) { fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } // Create a sample empty DB, named "aNewDatabase" if (mysql_query(con, "CREATE DATABASE aNewDatabase")) { fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } // Close connection mysql_close(con); exit(0); }
I had a quick look at https://github.com/MariaDB/server , but he didn’t know where to really look ... or actually what I was looking for. How do you go about getting a built-in mariad? I work on Mac OS High Sierra, MariaDB was installed with brew install mariadb --with-embedded .
UPDATE:
I am sure that I am attached to the correct library.
ls /usr/local/lib | grep maria

FIND_LIBRARY(mariadb mariadb) MESSAGE(FATAL_ERROR "BOOM ${mariadb}")
Output: BOOM /usr/local/lib/libmariadb.dylib
UPDATE 2
Now I refer to the following. Note that I started with libmysqld and added libraries until all the link errors went away. The problem here is that I may not have all the correct libraries or versions.
TARGET_LINK_LIBRARIES(sql_fn /usr/local/lib/libmysqld.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/openssl/lib/libcrypto.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/openssl/lib/libssl.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/bzip2/lib/libbz2.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/lib/liblz4.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/zlib/lib/libz.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/xz/lib/liblzma.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/lib/libsnappy.a)
Now it compiles, but exits with code 6 
Process finished with exit code 6 If you look at https://stackoverflow.com/a/16665/ ... if it points to the same / is still true, then exit code 6 means EX_ILLEGAL_TABLE 6 , unfortunately I don't know which the table would be The mysql_test strings mysql_test and datadir are valid / path identifiers.