Click here to Skip to main content
15,885,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello and good afternoon...
i try to create a dll file in c++ and link with mysql api

i already link mysql lib and header to visual studio

when i try to build it..
i got these error messages :

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol _mysql_init@4 referenced in function "public: void __thiscall MySQLConnector::openConnection(void)" (?openConnection@MySQLConnector@@QAEXXZ)	MySQLConnectorDLL	C:\Users\user\Desktop\MySQLConnectorDLL\MySQLConnectorDLL\MySQLConnector.obj	1	

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol _mysql_real_connect@32 referenced in function "public: void __thiscall MySQLConnector::openConnection(void)" (?openConnection@MySQLConnector@@QAEXXZ)	MySQLConnectorDLL	C:\Users\user\Desktop\MySQLConnectorDLL\MySQLConnectorDLL\MySQLConnector.obj	1	

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol _mysql_close@4 referenced in function "public: void __thiscall MySQLConnector::closeConnection(void)" (?closeConnection@MySQLConnector@@QAEXXZ)	MySQLConnectorDLL	C:\Users\user\Desktop\MySQLConnectorDLL\MySQLConnectorDLL\MySQLConnector.obj	1	

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK1120	3 unresolved externals	MySQLConnectorDLL	C:\Users\user\Desktop\MySQLConnectorDLL\Debug\MySQLConnectorDLL.dll	1	


What I have tried:

what i have did in my code is :

in my header file :
#pragma once

#include "mysql.h"

class MySQLConnector {
public :
	void openConnection();
	void closeConnection();
	bool connectionStatus();
private :
	bool _connectionStatus;
	MYSQL *_con, *_connectionString;
};


in my cpp file
#pragma once

#include "C:\BookScanner\extension\cpp files\header\CppMySQL.h"

#include <mysql.h>

void MySQLConnector::openConnection(){
	_con = mysql_init(NULL);
	_connectionString = mysql_real_connect(_con, "localhost", "root", "", "bookbardatabase", 3306, NULL, 0);

	_connectionStatus = _connectionString ? true: false;
}

void MySQLConnector::closeConnection()
{
	mysql_close(_con);
}

bool MySQLConnector::connectionStatus()
{
	return _connectionStatus;
}


and this is my dll file, i failed to build it
#include "C:\BookScanner\extension\cpp files\header\CppMySQL.h"
#include "C:\BookScanner\extension\cpp files\cpp\CppMySQL.cpp"

MySQLConnector connector;

extern "C" __declspec(dllexport) void openConnection() {
	connector.openConnection();
}

extern "C" __declspec(dllexport) void closeConnection() {
	connector.closeConnection();
}

extern "C" __declspec(dllexport) bool connectionStatus() {
	return connector.connectionStatus();
}
Posted
Updated 2-Aug-17 21:09pm
Comments
Richard MacCutchan 3-Aug-17 3:14am    
You forgot to include the MySQL library in your build process.

1 solution

You have to link your DLL with the MySQL library. This can be done in the project settings or using a #pragma comment (lib, "filename") statement (see comment (C-C++)[^]). That should solve the unresolved external symbol linker errors.

You should also read Walkthrough: Creating and Using a Dynamic Link Library (C++)[^] and implement your code according to that.

A final note: Never include source files (*.c / *.cpp) using #include statements.
 
Share this answer
 
Comments
CPallini 3-Aug-17 3:12am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900