I've spent about two days now trying to get this to work but I still keep getting the same error with every method I do. I'm new to connecting MySQL to C++ so I'm a bit lost and every time I try to compile it, the thing spits out LNK2019 error. I'm using Visual Studio 2022.
#include <iostream>
#include <mysql.h>
using namespace std;
// DATABASE STUFF
struct connection_details {
const char* server, * user, * password, * database;
};
MYSQL* mysql_connection_setup(struct connection_details mysql_details) {
MYSQL* connection = mysql_init(NULL);
if (!(mysql_real_connect(connection, mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0))) {
cout << "Connection Error: " << mysql_error(connection) << endl;
exit(1);
}
return connection;
}
MYSQL_RES* mysql_execute_query(MYSQL* connection, const char* sql_query) {
if (mysql_query(connection, sql_query)) {
cout << "MYSQL Query Error: " << mysql_error(connection) << endl;
exit(1);
}
return mysql_use_result(connection);
}
// MAIN FUNCTION
int main(int argc, char const* argv[]) {
MYSQL* con;
MYSQL_RES* res;
MYSQL_ROW row;
struct connection_details mysql_db;
mysql_db.server = "localhost";
mysql_db.user = "root";
mysql_db.password = "tAblE4wTe3";
mysql_db.database = "test";
con = mysql_connection_setup(mysql_db);
res = mysql_execute_query(con, "select * from table1");
cout << "Displaying Database:\n" << endl;
while ((row = mysql_fetch_row(res)) != NULL) {
cout << row[0] << " | " << row[1] << " | " << row[2] << endl;
}
mysql_free_result(res);
mysql_close(con);
return 0;
}
Errors it shows:
1>------ Build started: Project: Test, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol mysql_error referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_init referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_real_connect referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_query referenced in function "struct MYSQL_RES * __cdecl mysql_execute_query(struct MYSQL *,char const *)" (?mysql_execute_query##YAPEAUMYSQL_RES##PEAUMYSQL##PEBD#Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_use_result referenced in function "struct MYSQL_RES * __cdecl mysql_execute_query(struct MYSQL *,char const *)" (?mysql_execute_query##YAPEAUMYSQL_RES##PEAUMYSQL##PEBD#Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_free_result referenced in function main
1>main.obj : error LNK2019: unresolved external symbol mysql_fetch_row referenced in function main
1>main.obj : error LNK2019: unresolved external symbol mysql_close referenced in function main
1>C:\Users\Administrator\Documents\Visual Studio 2022\C++ Projects\Test\x64\Debug\Test.exe : fatal error LNK1120: 8 unresolved externals
1>Done building project "Test.vcxproj" -- FAILED.
These are the include/library folder locations:
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libbinlogevents
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libbinlogstandalone
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libchangestreams
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libmysql
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libservices
C:\Program Files\MySQL\Connector C++ 8.0\lib64\vs14
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\include
C:\Program Files\MySQL\Connector C++ 8.0\include
I've tried looking it up, and every forum, video, etc. that I try using to resolve doesn't work. I'm not sure if it's a 32-bit or 64-bit issue, though I don't think it is since all files point to 64-bit folders. I'm thinking it's something in my code but I'm very new to this so I can't really pinpoint it. Any help would be appreciated.
EDIT: I managed to solve it, just started the project from scratch and followed the visual studio docs and this video.
Related
I want to use the Eclipse Paho MQTT C library in a simple C++ program. For the library i used the the pre-build binaries for windows - see https://projects.eclipse.org/projects/technology.paho/downloads
C client for Windows 1.3.0 - 64 bit
I found the exact same issue in this talk LNK2019 error when compiling a Visual C++ Win32 project with Eclipse Paho MQTT.
For linkage in include I have the following setting:
C/C++ - Additional include: xxx\paho\eclipse-paho-mqtt-c-win64-1.3.0\include
Linker - additional Additional Library Directories
Linker - input - additional dependencies:
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3cs.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3c.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3a.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3as.lib
My code is as follows:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern "C" {
#include <MQTTClient.h>
#include <MQTTClientPersistence.h>
}
#define ADDRESS "xxx"
#define CLIENTID "ExampleClientSub"
#define TOPIC "xxx"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
int main()
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
int rc;
int ch;
MQTTClient_create(&client, ADDRESS, CLIENTID,
MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.username = "roman.busse";
conn_opts.password = "VojUriLKhOsmzUJQ1lld";
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
printf("Subscribing to topic %s\nfor client %s using QoS%d\n\n"
"Press Q<Enter> to quit\n\n", TOPIC, CLIENTID, QOS);
MQTTClient_subscribe(client, TOPIC, QOS);
do
{
ch = getchar();
} while (ch != 'Q' && ch != 'q');
MQTTClient_unsubscribe(client, TOPIC);
MQTTClient_disconnect(client, 10000);
MQTTClient_destroy(&client);
return 0;
}
So like you can see i said to the compiler: "Yes this is a C lib". But all in all I get the same LNK2019 errors...
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _MQTTClient_setCallbacks
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_create referenced
in function _main paho_test C:\Users\rtreiber\documents\visual studio
2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_connect
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_disconnect
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_subscribe
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_unsubscribe
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_freeMessage
referenced in function "int __cdecl msgarrvd(void *,char *,int,struct
MQTTClient_message *)"
(?msgarrvd##YAHPAXPADHPAUMQTTClient_message###Z) paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_free referenced
in function "int __cdecl msgarrvd(void *,char *,int,struct
MQTTClient_message *)"
(?msgarrvd##YAHPAXPADHPAUMQTTClient_message###Z) paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_destroy
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1 Error LNK1120 9
unresolved externals paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\Debug\paho_test.exe 1
So any ideas?
I'm trying to use cpp-netlib with Visual Studio 2010.
I've built cpp-netlib and add .lib files to my project, but I can't compile them.
--Environment
Windows 7 x64
cpp-netlib 0.11.0
boost 1.55.0
Win32 OpenSSL v1.0.1f
My code is here.
#include <boost/network/protocol/http/client.hpp>
#include <iostream>
int main(int argc, char *argv[]) {
using namespace boost::network;
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " [url]" << std::endl;
return 1;
}
http::client client;
http::client::request request(argv[1]);
request << header("Connection", "close");
http::client::response response = client.get(request);
std::cout << body(response) << std::endl;
return 0;
}
I added the cpp-netlib library path and the cpp-netlib include path to the project.
Boost and openssl paths were also added.
I added the libs to the project.
libboost_system-vc100-mt-gd-1_55.lib
libboost_date_time-vc100-mt-gd-1_55.lib
libboost_regex-vc100-mt-gd-1_55.lib
cppnetlib-client-connections.lib
cppnetlib-uri.lib
I think the errors come from something related OpenSSL.
Error 55 error LNK2019: unresolved external symbol - function _BIO_ctrl ...
Actually, I have Japanese one so it's like below.
エラー 55 error LNK2019: 未解決の外部シンボル _BIO_ctrl が関数 "public: class boost::system::error_code const & __thiscall boost::asio::ssl::detail::engine::map_error_code(class boost::system::error_code &)const " (?map_error_code#engine#detail#ssl#asio#boost##QBEABVerror_code#system#5#AAV675##Z) で参照されました。 cppnetlib-client-connections.lib(client.obj)
エラー 57 error LNK2019: 未解決の外部シンボル _BIO_ctrl_pending が関数 "private: enum boost::asio::ssl::detail::engine::want __thiscall boost::asio::ssl::detail::engine::perform(int (__thiscall boost::asio::ssl::detail::engine::*)(void *,unsigned int),void *,unsigned int,class boost::system::error_code &,unsigned int *)" (?perform#engine#detail#ssl#asio#boost##AAE?AW4want#12345#P812345#AEHPAXI#Z0IAAVerror_code#system#5#PAI#Z) で参照されました。 cppnetlib-client-connections.lib(client.obj)
エラー 43 error LNK2019: 未解決の外部シンボル _BIO_free が関数 "public: __thiscall boost::asio::ssl::detail::engine::~engine(void)" (??1engine#detail#ssl#asio#boost##QAE#XZ) で参照されました。 cppnetlib-client-connections.lib(client.obj)
Could you tell me what I'm missing?
I tried to add more libs to the project, but it still didn't work.
I should've got to add these two library.
libeay32.lib
ssleay32.lib
I ran into the same problem, except i fixed it by using the WIN32 version of SSL instead of the X64 version.
I am using opencv 2.4.8 with visual studio 2013. I have been trying to get my application to run. I know for sure the code works, but I am having linker issues I believe...
here is the error I get:
Error 1 error LNK2019: unresolved external symbol _cvCreateImage referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 2 error LNK2019: unresolved external symbol _cvInRangeS referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 3 error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cv::format(char const *,...)" (?format#cv##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##PBDZZ) referenced in function __catch$?getFace##YAXXZ$0 C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 4 error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPAX#Z) referenced in function "public: __thiscall cv::Mat::~Mat(void)" (??1Mat#cv##QAE#XZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 5 error LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray#cv##QAE#ABVMat#1##Z) referenced in function __catch$?getFace##YAXXZ$0 C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 6 error LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > const &)" (??0_InputArray#cv##QAE#ABV?$vector#VMat#cv##V?$allocator#VMat#cv###std###std###Z) referenced in function __catch$?getFace##YAXXZ$0 C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 7 error LNK2001: unresolved external symbol "public: virtual class cv::Mat __thiscall cv::_InputArray::getMat(int)const " (?getMat#_InputArray#cv##UBE?AVMat#2#H#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 8 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::_InputArray::getMatVector(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &)const " (?getMatVector#_InputArray#cv##UBEXAAV?$vector#VMat#cv##V?$allocator#VMat#cv###std###std###Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 9 error LNK2001: unresolved external symbol "public: virtual class cv::GlBuffer __thiscall cv::_InputArray::getGlBuffer(void)const " (?getGlBuffer#_InputArray#cv##UBE?AVGlBuffer#2#XZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 10 error LNK2001: unresolved external symbol "public: virtual class cv::GlTexture __thiscall cv::_InputArray::getGlTexture(void)const " (?getGlTexture#_InputArray#cv##UBE?AVGlTexture#2#XZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 11 error LNK2001: unresolved external symbol "public: virtual class cv::gpu::GpuMat __thiscall cv::_InputArray::getGpuMat(void)const " (?getGpuMat#_InputArray#cv##UBE?AVGpuMat#gpu#2#XZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 12 error LNK2001: unresolved external symbol "public: virtual int __thiscall cv::_InputArray::kind(void)const " (?kind#_InputArray#cv##UBEHXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 13 error LNK2001: unresolved external symbol "public: virtual class cv::Size_<int> __thiscall cv::_InputArray::size(int)const " (?size#_InputArray#cv##UBE?AV?$Size_#H#2#H#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 14 error LNK2001: unresolved external symbol "public: virtual unsigned int __thiscall cv::_InputArray::total(int)const " (?total#_InputArray#cv##UBEIH#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 15 error LNK2001: unresolved external symbol "public: virtual int __thiscall cv::_InputArray::type(int)const " (?type#_InputArray#cv##UBEHH#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 16 error LNK2001: unresolved external symbol "public: virtual int __thiscall cv::_InputArray::depth(int)const " (?depth#_InputArray#cv##UBEHH#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 17 error LNK2001: unresolved external symbol "public: virtual int __thiscall cv::_InputArray::channels(int)const " (?channels#_InputArray#cv##UBEHH#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 18 error LNK2001: unresolved external symbol "public: virtual bool __thiscall cv::_InputArray::empty(void)const " (?empty#_InputArray#cv##UBE_NXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 19 error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release#Mat#cv##QAEXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 20 error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize#Mat#cv##QAEXABV12##Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &)" (??0Mat#cv##QAE#ABV01##Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 21 error LNK2019: unresolved external symbol "public: void __thiscall cv::Algorithm::set(char const *,double)" (?set#Algorithm#cv##QAEXPBDN#Z) referenced in function __catch$?getFace##YAXXZ$0 C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 22 error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd#cv##YAHPAHH#Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &)" (??0Mat#cv##QAE#ABV01##Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 23 error LNK2019: unresolved external symbol _cvCvtColor referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 24 error LNK2019: unresolved external symbol _cvShowImage referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 25 error LNK2019: unresolved external symbol _cvLoadImage referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 26 error LNK2019: unresolved external symbol _cvSaveImage referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 27 error LNK2019: unresolved external symbol _cvWaitKey referenced in function "void __cdecl getBinaryImage(void)" (?getBinaryImage##YAXXZ) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 28 error LNK2019: unresolved external symbol _cvCreateCameraCapture referenced in function _main C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 29 error LNK2019: unresolved external symbol _cvQueryFrame referenced in function _main C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 30 error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function "void __cdecl read_csv(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &,class std::vector<int,class std::allocator<int> > &,char)" (?read_csv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAV?$vector#VMat#cv##V?$allocator#VMat#cv###std###2#AAV?$vector#HV?$allocator#H#std###2#D#Z) C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 31 error LNK2019: unresolved external symbol "class cv::Ptr<class cv::FaceRecognizer> __cdecl cv::createLBPHFaceRecognizer(int,int,int,int,double)" (?createLBPHFaceRecognizer#cv##YA?AV?$Ptr#VFaceRecognizer#cv###1#HHHHN#Z) referenced in function __catch$?getFace##YAXXZ$0 C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\PAD_visualEngine\Source.obj PAD_visualEngine
Error 32 error LNK1120: 31 unresolved externals C:\Users\Parker\documents\visual studio 2013\Projects\PAD_visualEngine\Debug\PAD_visualEngine.exe PAD_visualEngine
I had a 2012 vs application of this project and it worked just fine, The steps I have done is setting the Additional library Directories as "C:\opencv\build\x86\vc12\lib" and the additional Include Directories as "C:\opencv\build\include". For safe measures I also set the path as C:\opencv. I don't really know what I am forgetting? I thank you in advance for the help!
here is the code:
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
using namespace cv;
#define CV_IMWRITE_JPEG_QUALITY 1
#define CV_IMWRITE_PNG_COMPRESSION 16
#define CV_IMWRITE_PXM_BINARY 32
vector<Mat> images;
vector<int> labels;
void getBinaryImage()
{
IplImage *gray, *binary, *dest, *a;
a = cvLoadImage("out2.jpg");
gray = cvCreateImage(cvSize(a->width, a->height), IPL_DEPTH_8U, 1);
//binary=cvCreateImage(cvSize(a->width,a->height), IPL_DEPTH_8U,1);
dest = cvCreateImage(cvSize(a->width, a->height), IPL_DEPTH_8U, 1);
cvCvtColor(a, gray, CV_BGR2GRAY);
//cvThreshold(gray,binary,30,255,THRESH_BINARY);
cvInRangeS(a, cvScalar(1, 1, 1), cvScalar(120, 100, 300), dest);
cvSaveImage("out2_gray.jpg", dest);
cvShowImage("inrangGray", dest);
cvWaitKey(0);
}
void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';')
{
std::ifstream file(filename.c_str(), ifstream::in);
if (!file){
string error = "no valid input csv file";
cout << error;
}
string line, path, classlabel;
while (getline(file, line)){
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
if (!path.empty() && !classlabel.empty()){
images.push_back(imread(path, 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
}
void getFace()
{
try{
read_csv("file.csv", images, labels);
}
catch (cv::Exception& e){
cerr << "error opening file info.csv";
exit(1);
}
try{
if (images.size() <= 1){
string error = "this app needs at leaset 2 images";
cout << error;
}
int height = images[0].rows;
Mat testImage = images[images.size() - 1];
int testLab = labels[labels.size() - 1];
images.pop_back();
labels.pop_back();
Ptr<FaceRecognizer>model = createLBPHFaceRecognizer();
model->train(images, labels);
int predictedlabel = model->predict(testImage);
string result = format("predicted=%d/ actual=%d", predictedlabel, testLab);
cout << result << endl;
model->set("threshold", 0.0);
predictedlabel = model->predict(testImage);
cout << "predicted class = " << predictedlabel << endl;
}
catch (cv::Exception& e){
cerr << "overall error";
}
}
int main(int argc, char** argv)
{
/*VideoCapture cap;
// open the default camera, use something different from 0 otherwise;
// Check VideoCapture documentation.
if(!cap.open(0))
return 0;
for(;;)
{
Mat frame;
cap >> frame;
if( frame.empty() ) break; // end of video stream
imshow("capture", frame);
if( (waitKey() & 255) == 27 ) break; // stop capturing by pressing ESC
}
// the camera will be closed automatically upon exit
// cap.close();
return 0; */
int p[3];
CvCapture *pCapturedImage = cvCreateCameraCapture(-1);
IplImage *pSaveImg = cvQueryFrame(pCapturedImage);
pSaveImg = cvQueryFrame(pCapturedImage);
p[0] = CV_IMWRITE_JPEG_QUALITY;
p[1] = 100;
p[2] = 0;
//cvSaveImage("out2.jpg", pSaveImg, p);
//getBinaryImage();
getFace();
return 0;
}
You are getting those errors because the linker doesn't know in which library to look for the used methods. You can try adding the names of those libraries (depending on the methods you are using, try adding opencv_core248.lib, etc.) in Project properties->Linker->Input->Additional dependencies.
The second method is by adding the additional dependencies before the main function via pragma comments, as follows:
#pragma comment (lib, "opencv_core248d.lib")
#pragma comment (lib, "opencv_highgui248d.lib")
#pragma comment (lib, "opencv_imgproc248d.lib")
#pragma comment (lib, "opencv_video248d.lib")
#pragma comment (lib, "opencv_features2d248d.lib")
If you are building a release version, remove the "d" letter before the extension (opencv_core248.lib, etc.)
Let me know if that works for you!
Best regards
Check if your platform is win32 or x64(Solution Properties-->Configuration -->Platform column). I faced similar issue when my platform was win32 and the linker was trying to link using x64.
EDITED:
My Problem is the errors at the bottom of this post.
Heres my additional include directories
C:\Program Files\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include
Additional Library Directories
C:\Program Files\MySQL\MySQL Server 5.6\lib
C:\Program Files\MySQL\Connector C++ 1.1.2\lib\opt
Additional Dependencies
libmysql.lib
mysqlcppconn-static.lib
Heres my code
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#include <stdlib.h>
#include <Windows.h>
#include <mysql.h>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#define host "localhost"
#define username "root"
#define password "root"
#define database "tests"
int main()
{
MYSQL* conn;
conn = mysql_init( NULL );
if( conn )
{
mysql_real_connect( conn, host, username, password, database, 0, NULL, 0 );
}
MYSQL_RES* res_set;
MYSQL_ROW row;
unsigned int i;
mysql_query( conn, "SELECT * FROM tbl_clients WHERE id = 1" );
res_set = mysql_store_result( conn );
unsigned int numrows = mysql_num_rows( res_set );
if( numrows )
{
row = mysql_fetch_row( res_set );
if( row != NULL )
{
cout << "Client ID : " << row[0] << endl;
cout << "Client Name: " << row[1] << endl;
}
}
if( res_set )
{
mysql_free_result( res_set );
}
if( conn )
{
mysql_close( conn );
}
return 0;
}
These are the errors I get
1>------ Build started: Project: okay, Configuration: Debug Win32 ------
1>welp.obj : error LNK2019: unresolved external symbol _mysql_num_rows#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_init#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_real_connect#32 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_query#8 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_store_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_free_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_fetch_row#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_close#4 referenced in function _main
1>C:\Users\Damian\documents\visual studio 2012\Projects\okay\Debug\okay.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help, This project is due in about 48 hours for my class, and I've spent so much time trying to figure this out.
Thanks
respectfully, your last two questions are compiler/linker questions. I understand your frustration, as I knew how to code early but knew nothing about compilers/linkers. When you get a moment take some time to read about:
headers
binary vs object file
libraries / shared object
compiler
linker
function mangling (C vs C++)
To answer your question, I am guessing you're doing this in Microsoft Visual Studio:
You need to go to Project Properties and set Additional Library Paths (i see you did that from your last post)
You need to specify the library, I'm going out on a limb here and assuming it will mysql.lib ... There's an "Additional Library" input somewhere in the Linker section, you'll be able to identify it because kernel32.lib will be int it. Add the mysql.lib to that section. Confirm the name by going to the mysql folder which holds the binaries.
Make sure you're using the static library, the .dll will give you new issues that you don't need to worry about. This is usually achieved by setting the correct library directory. Many c++ libraries will ship with precompiled "Static" and "Dynamic" folders containing the correct libraries.
This is error is happening due to linker problem. The linker is not able to find the required static or dynamic libraries (mysql.lib,mysqlcppconn-static.lib,libmysql.dll and libmysql.lib). The additional lib setting is wrong. Check this site give the path correctly Building MySQL Connector/C++ Windows Applications with Microsoft Visual Studio
I've installed OpenSSL to Windows 8, and did the necessary modifications to the OpenSSL library, without installing it as a native library. But I've a specific error message that I couldn't find it on internet.
1>------ Build started: Project: CryptoProject, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _BN_new referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_bn2dec referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_generate_prime referenced in function _main
1>C:\Users\...\...\...\Debug\EXAMPLE.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hope you guys find something. So here it goes:
#include <iostream>
#include <string>
#include "openssl/bn.h"
using namespace std;
int main()
{
BIGNUM * q = BN_new();
BIGNUM * two = BN_new();
long int num_bits_q = 160;
long int num_bits_p = 1024;
BN_generate_prime(q, num_bits_q, 0, two, NULL,NULL,NULL);
cout << "q is: " << BN_bn2dec(q) << endl;
return 0;
}
I ran that code and it compiled successfully in visual studio 2012, I used OpenSSL-Win32. If OpenSSL-Win64 does not work use OpenSSL-Win32, I also had the same problem. Don't forget to include ssleay32.lib, I hope you know how to configure OpenSSl in visual studio.