Using MySQL Connector/C++ in Xcode: -libmysqlcppconn library not found - c++

I'm trying to use MySQL Connector/C++ within Xcode. I have installed MySQL server. I also installed MySQL Connector/C++ and Boost using brew. I believe all files are where they should be.
I've included library search paths:
1) /usr/local/mysql-5.6.24-osx10.8-x86_64/lib
2) /usr/local/mysql/lib
I am just trying to get simple code to run before I dive a little deeper:
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
using namespace std;
int main(int argc, const char * argv[]) {
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
delete con;
return 0;
}
The error I'm getting is: ld: library not found for -libmysqlcppconn
Any help would be greatly appreciated!

If you are using the Static MySQL Connector/C++ Library, did you link both library files: libmysqlcppconn-static.a and libmysqlclient.a? Do that in Xcode in the "Build Phases" tab under "Link Binary With Libraries" section. After you add those files make sure that the library search paths you provided point to the file locations.
For Dynamic Library instead you link the libmysqlcppconn.so file.

Related

C++ MySQL Header files not found (Linux Application)

I am trying to connect to my local MySQL database hosted via XAMPP.
I downloaded this .zip file https://cdn.mysql.com//Downloads/Connector-C++/mysql-connector-c++-8.0.20-winx64.zip and I added the include folder to the field in C/C++->General/Additional Includes and of course the lib64 folder to the field in Linker->Input->Additional dependencies + Linker->General->Additional Library Directories.
Shall I download the MySQL Server (I have only installed XAMPP with MySQL)?
This is a Linux Console Application and I am running this with gdb on my WSL and I am running it in release x64 mode!
Code:
#include <cstdio>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
int main()
{
try
{
sql::Driver* driver;
sql::Connection* con;
driver = get_driver_instance();
con = driver->connect("tcp://localhost:3306", "root", "");
con->setSchema("botcaptcha");
}
catch (sql::SQLException& err)
{
printf(err.what());
}
return 0;
}
Error:
1>C:\Users\JanDerZocker05\Desktop\ConsoleApplication2\ConsoleApplication2\main.cpp(2,10): error : mysql_connection.h: No such file or directory
1>C:\Users\JanDerZocker05\Desktop\ConsoleApplication2\ConsoleApplication2\main.cpp(2,10): error : 2 | #include "mysql_connection.h"
1>C:\Users\JanDerZocker05\Desktop\ConsoleApplication2\ConsoleApplication2\main.cpp(2,10): error : | ^~~~~~~~~~~~~~~~~~~~
1>C:\Users\JanDerZocker05\Desktop\ConsoleApplication2\ConsoleApplication2\main.cpp(2,10): error : compilation terminated.
1>Die Erstellung des Projekts "ConsoleApplication2.vcxproj" ist abgeschlossen -- FEHLER
includes:
library directories:
libraries:

c++ mysql connection bad_alloc using c++ connector

Trying to build a simple mysql connection, but getting a bad_alloc and I can't figure out how to solve this, even looking at similar posts
here is my code
#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
#include "mysql_connection.h"
#include "cppconn\driver.h"
#include "cppconn\statement.h"
#include "cppconn\connection.h"
#include "cppconn\exception.h"
#include "cppconn\prepared_statement.h"
#include "cppconn\statement.h"
using namespace std;
using namespace sql;
int main()
{
Driver *driver;
Connection *conn;
Statement *stmt;
driver = get_driver_instance();
conn = driver->connect("127.0.0.1:3306", "root", "root"); // breaks here
stmt = conn->createStatement();
stmt->execute("USE mydb");
return 0;
}
I'm using mysql-connector-c++-1.1.7
mysqlcppconn.lib is used as a dependencies
mysqlcppconn.dll is located in the same dir as the .exe is.
Here is the error Exception thrown at 0x000007FEFD39A06D in MysqlConn.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000000014F5D0.
Thanks
I also had this error. In my case I am compiling using VS2015 in Windows.
First time I choose compile static version of the MySQL lib. Then later I decided to compile the dynamic version. This time the error bad_alloc at memory went off.
The solution is rolling back the CPPCONN_PUBLIC_FUNC= configuration.
Go to project Property Pages, under C++ > Preprocessor > Preprocessor Definitions and remove the item CPPCONN_PUBLIC_FUNC=".
I had the same error on linux.
The error was : I was using g++-4.8 to build the project
The issue lies on the version of the build tools (gcc,msvs,clang) used to build the project

Connecting VS Express 2013 to MySQL with Connector C++ 1.1.3 - error LNK2019: unresolved external symbol

Scroll down for (part of) the solution that I found:
I'm on a Windows 8.1, 64 bit laptop
It is my first time trying to connect C++ to MySQL using the mentioned connector.
The error is as follow:
Error 1 error LNK2019: unresolved external symbol "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (?get_driver_instance#mysql#sql##YAPAVMySQL_Driver#12#XZ) referenced in function _main C:\Users\user\documents\visual studio 2013\Projects\Profile\Profile\Profile.obj Profile
This is my main code:
// Profile.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#define dbHOST "tcp://127.0.0.1:3306"
#define dbUSER "root"
#define dbPASS "root"
#define dbDB "db_test"
using namespace std;
using namespace sql;
int main()
{
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_driver_instance();
con = driver->connect(dbHOST, dbUSER, dbPASS);
delete con;
system("pause");
return 0;
}
I have followed the instructions from this mysql site for the static installation.
I have also Google quite a lot with the error.
Some suggested it could be the connector files different for 64bit and 32bits - I've tried downloading both (they are installed in Program Files and Program Files (x86) accorindgly. but the error persists.
One thing to note, when I link it with the 32bit connector files, it will have a huge load more of errors.
Makes me wonder after all the search, is it that VS Express 2013 is not compatible to connect with MySQL thus far?
I heard ppl saying using the Qt would be easier, but I still want to try this out.
Please let me know if my question is vague or if you need more information.
Thanks in advance!
SOLUTION I FOUND
I don't want to add it as an answer because it does not remedy the question I asked.
Anyway, I found a link which gives fairly simple instructions which has got it to work. Would still appreciate if anyone is willing to look into my original issue.
:)

Error fatal: libssh.h: No such file or directory NETBEANS

#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <libssh.h>
#include <stdlib.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv)
I have that code, and when compiling the error fatal of no Libssh.h is appearing, but when i SHIFT+CLICK over the libssh.h include instruction i jump to the file that already exist and is installed.
I have include it on Netabeans options for C++ compiling.
Any ideas?
Regards.
The search path of Netbeans is probably different than search path of the compiler. On my machine libssh.h is in /usr/include/libssh/libssh.h. You can try to change your include:
#include <libssh/libssh.h>
Or change compiler options to add /usr/include/libssh/ to its search path.

Static linking of MySQL in C/C++

I am trying to develop an application that uses MySQL using C++. I downloaded the library from their website and I have attempted to compile the following code:
#include <iostream>
#include <windows.h>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
mysql_init(&mysql);
}
The line that has mysql_init(&mysql); gives me a compilation error
undefined reference to `mysql_init#4'
I am guessing this is due to a library error. I am linking mysqlclient.lib and libmysql.lib in that order. What do I need to do to make this compile without requiring a dll file? Is that possible? Thank you.
Note: I am using mingw32 on Windows 7 x64 to develop an application for Windows.
Maybe this link will help. It states that mysqlclient.lib is the static library and libmysql.lib is the dynamic library, so I don't think you should be linking both.
http://dev.mysql.com/doc/refman/5.0/en/building-clients.html