Linker error with get_driver_instance() MySQL C++ VS2010 - c++

I have searched through all the questions on here trying to find a solution and it just isnt happening.
Error
1>MySQLTest.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main
What I have tried
I know this is a linker error. So I have modified the include and library directory options in VS2010 to point to the MySQL Server libraries and the Connection++ libraries
Libraries:
C:\Programming\boost_1_55_0\stage\lib
C:\Program Files\MySQL\Connector C++ 1.1.3\lib
C:\Program Files\MySQL\MySQL Server 5.6\lib
Includes:
C:\Programming\boost_1_55_0
C:\Program Files\MySQL\Connector C++ 1.1.3\include
C:\Program Files\MySQL\Connector C++ 1.1.3\include\cppconn
I have read in another thread that the get_driver_instance function is only available when dynamically loading the library. It said to define mysqlcppconn_EXPORTS.
get_driver_instance() is now only available in dynamic library builds
- static builds do not have this symbol. This was done to accommodate loading the
DLL with LoadLibrary or dlopen. If you do not use CMake
for building the source code you will need to define
mysqlcppconn_EXPORTS if you are loading dynamically and want to use
the get_driver_instance() entry point.
I defined this and it still does not work. There is another define (CPPCONN_PUBLIC_FUNC) that people said to use if I wanted to statically link. I tried this too and I still get that error. Preferably I would like to just statically link everything and use a different way of accessing the driver if possible. Is there another way other than get_driver_instance()?
Note: SQLString is working fine. So I am properly linking certain things. I just do not know why this is erring out with this one function.
I have the 64 bit version of the connector installed. Along with mysql Server and workbench.
Here is the code I am trying to run:
#include "stdafx.h"
//#define CPPCONN_PUBLIC_FUNC
/* Standard C++ headers */
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
#include <Windows.h>
/* MySQL Connector/C++ specific headers */
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>
using namespace std;
using namespace sql;
int main(int argc, _TCHAR* argv[])
{
sql::mysql::MySQL_Driver *driver;
Connection *con;
/* initiate url, user, password and database variables */
const sql::SQLString url = "tcp://127.0.0.1:3306";
const sql::SQLString user = "root";
const sql::SQLString password = "admin";
const sql::SQLString database = "store";
driver = sql::mysql::get_mysql_driver_instance();
/* create a database connection using the Driver */
con = driver->connect(url, user, password);
system("PAUSE");
return 0;
}

There ended up being a slight error in one of my assumptions. I assumed visual studio defaulted its build based on the system you are running. It was building a 32 bit version of the application(on a 64 bit machine), and I am using 64 bit libraries. If you do this the linker will not look at libraries compiled using a 64 bit target.
The machine type has to be changed to 64 bit in the following area to get my build to work properly:
Project -> "project_name" Properties -> Linker -> Advanced -> Target Machine set to 'x64'
There may also be another attribute that had to be changed that is related (making sure its building for 64 bit) but I cannot remember where it was. I remember it being very obvious to find though.

I solved this problem by downloading a C++ connector from MySQL website and a libmysql.dll 32bit from dllfiles.com
Note: MySQL Installer is 32 bit, but will install both 32 bit and 64 bit binaries depend on the platform of your computer. I'm using Win8 64bit and VS2010 32bit, my target platform is 32bit. But the connector provided with MySQL is 64bit, so it will cause unresolved symbol problem.
So you have to download an independent 32bit connector and use the lib in it. Also, you must download libmySQL.dll 32bit

Related

sdk-11.1.0.7.0-linux-x86_64/instantclient_11_1/sdk/include/nzerror.h:115:11: fatal error: oratypes.h: No such file or directory

I am trying to connect oracle 11g express on my Windows 10 installed by C++ program writing in Linux Ubuntu 18.4 LTS. I set path of include to includes file given by Oracle. I set path of Directories to given shared libraries by oracle. I just set namespace oracle::occi. The main method still empty I just build project but getting error
./../../Desktop/oracle OCI/sdk-11.1.0.7.0-linux-x86_64/instantclient_11_1/sdk/include/nzerror.h:115:11: fatal error: oratypes.h: No such file or directory.
I am using Netbeans on Ubuntu for coding of C++; I want to connect Oracle database on Windows 10 over the network by just change localhost to IP.
One more thing, I created a project in Visual Studio 2019 import all library for Windows it work but fetch one record and exception caught at some thing like Myproxy Error function.
Visual Studio problem later but I want it on Linux first.
#include <cstdlib.h>
using namespace std;
using namespace oracle::occi;
void main(){
}
I just do this and set the paths which I explained.

'byte' : ambiguous symbol error when using of Crypto++ and Windows SDK

In Visual Studio 2012, I'm trying to encrypt a file with Crypto++ library with AES encryption and CBC mode as following :
#include <Windows.h>
#include "aes.h"
#include "modes.h"
#include "files.h"
#include <Shlwapi.h>
using namespace CryptoPP;
INT main(INT argc, CHAR *argv[])
{
CHAR szKey[16] = {0};
CHAR szInitVector[AES::DEFAULT_KEYLENGTH] = {0};
StrCpyA(szKey, "qqwweeff88lliioo");
StrCpyA(szInitVector, "eerrttooppkkllhh");
CBC_Mode<AES>::Encryption encryptor((byte*)szKey, AES::DEFAULT_KEYLENGTH, (byte*)szInitVector);
FileSource fs("in.txt", true, new StreamTransformationFilter(encryptor, new FileSink("out.aes")));
return 0;
}
In Qt it does work!, But here I wondered why got the following error :
error C2872: 'byte' : ambiguous symbol
could be 'c:\program files (x86)\windows kits\8.0\include\shared\rpcndr.h(164) : unsigned char byte'
or 'z:\cryptography\app_aesencryption\aes headers\config.h(237) : CryptoPP::byte'
Due to prevent of ambiguous symbol error, even I cast bellow statement with CryptoPP::byte* :
CBC_Mode<AES>::Encryption encryptor((CryptoPP::byte*)szKey, AES::DEFAULT_KEYLENGTH, (CryptoPP::byte*)szInitVector);
I didn't get any error for 'byte' : ambiguous symbol, But It give me many errors as :
error LNK 2038
By the way, I linked .lib file of Crypto++, So I think this error is Unlikely for this.
Is last error related to CryptoPP::byte*? Is there any solution?
'byte' : ambiguous symbol error when using of Crypto++
We had to move byte from global namespace to CryptoPP namespace due to C++17 and std::byte. The change occurred at Commit 00f9818b5d8e, which was part of the Crypto++ 6.0 release.
Crypto++ used to put byte in the global namespace for compatibility with Microsoft SDKs. Without the global byte then you would encounter 'byte' : ambiguous symbol error again.
The error you are seeing is because you used using namespace CryptoPP; and the Microsoft kits still put a byte in the global namespace. The error did not surface under Qt because Qt does not put a byte in the global namespace.
There are several work-arounds discussed at std::byte on the Crypto++ wiki.
Incidentally, Microsoft kit code will break when it encounters a C++17 compiler and std::byte because of Microsoft's global byte. You will encounter the same error when using the Windows kits. Ironically, Microsoft employees authored C++ std::byte. Also see PR0298R0, A byte type definition.
The first problem solved with changing byte* to CryptoPP::byte* :
CBC_Mode<AES>::Encryption encryptor((CryptoPP::byte*)szKey, AES::DEFAULT_KEYLENGTH, (CryptoPP::byte*)szInitVector);
But to solving the second problem (error LNK 2038) :
This is related to link error, Every body that using of crypto++ in Visual Studio may have this problem.
First I was download library from bellow link for visual studio in which containt .sln (VS Solution) :
https://www.cryptopp.com/#download
I build the library via Batch Build as cryptlib project in both state (Debug|Win32 and Release|Win32)
Because I used of Debug mode, I linked cryptlib.lib in cryptopp700\Win32\Output\Debug in dependencies section.
Also add dependencies for header files...
But I forgot something in project properties :
Finally, I set Runtime Library option to Multi-threaded Debug (/MTd)
This option is in :
Project Properties
Configuration Properties
C/C++
Code Generation
Runtime Library
I know this answer is not directly relating to Crypto++ & Windows SDK, but I know I found this while trying to figure out the same error when using the Nodejs addon library called Nan instead. I'm putting this answer here because it's in an accessible place for others who might run into similar issues to me.
I hadn't had too many issues compiling the project for a while but then ran into the same error as mentioned above. I wasn't using a byte symbol anywhere. There were dozens of errors pointing to libraries in the Windows SDK which also was conflicting with the cstddef header as the error addresses.
What I was able to do to fix the problem was rearranging the headers so that the Nan-related content (and any of my own header files that references it) was on top, above even the other standard C/C++ libraries. After that was done, the errors went away.
The decision is simpliest. Delete from your code 'using namespace std' and use namespace std:: before every operation instead.

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.
:)

CGAL unresolved externals when compiling/linking on Windows

I'm getting strange (for me) errors during compiling a test program which uses some parts of the CGAL library.
First, the environment:
Windows 7 64 bits
Boost 1.53
CGAL 4.3
Qt 4.8.4
CMake 2.8.10.2
Visual Studio 2010 professional
I installed all the libraries for 32 bits (if this was an option during installation).
Installation wrong?
In order to install CGAL on my computer, I followed this tutorial: http://www.cgal.org/windows_installation.html. I have to note here that this did not work out-of-the-box for me. During the configuration phase of CGAL in CMake, the boost libraries were not found (although I set the corresponding environment variables, as stated in the tutorial). After setting the incorrect variables in CMake, I was able to complete the configuration and generation phase. After that, I was able to compile both the Debug as well as the Release configurations of CGAL in Visual Studio.
In order to test whether the CGAL lib was installed successfully, I tried to compile and run both the examples and demos. These also did not work immediately. The problem was that the CGAL and Boost headers (and binaries) were not found. After setting the right paths in Project properties => Configuration properties => C/C++ => Additional Include Directories and in Project properties => Configuration properties => Linker => Additional Library Directories the examples and demos could be build. I successfully ran these examples after that.
Actual problem
Now, I'm tyring to compile a simple program, in order to be able to make a certain exercise (http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2 exercise 2.1). Here, there are two files supplied: basic_typdef.h and cgal_bootcamp.cpp
*basic_typedef.h*
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
/*******************************************************************************************
* This file contatins basic typedefs (from CGAL and more).
*******************************************************************************************/
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
typedef std::list<Polygon_with_holes> Polygon_with_holes_container;
*cgal_bootcamp.cpp*
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
return 0;
}
(For convenience I removed the comments in the file cgal_bootcamp.cpp)
With Visual Studio, I can compile the two files as above. However, when I try to create a Point (as defined in basic_typedef.h), I'm getting the (strange) errors:
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
/*
1. Point
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Point_2.html
*/
// Create Point with the coordinates (0.5, 0.6)
Point p;
return 0;
}
The errors that occur:
Error 1 error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 2 error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 3 error LNK1120: 2 unresolved externals C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\Debug\warmup-exercise.exe 1 1 warmup-exercise
4 IntelliSense: #error directive: "Mixing a dll CGAL library with a static runtime is a really bad idea..." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 364 4
5 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 397 4
I have no clue what is going wrong here (I have to note that I'm still a noob with C++). It seems that there is something wrong with the GMP library (at least the linking to this?) I found in another post that for someone there were no libgmp files build (can't find that post anymore), but that is not the case for me (I think): in CGAL-4.3/auxiliary/gmp/lib I see four files, libgmp-10.dll libgmp-10.lib libmpfr-4.dll and libmpfr-4.lib.
Also the error on line 4 points to something that might cause this error ("Mixing a dll CGAL library with a static runtime is a really bad idea..."), but I do not know what this actually means (or how I can resolve it).
Further, I tried to setup all the libraries on another computer, but I got the same errors there also.
Could anyone point me in the right direction to solve this problem? If you need more information, please let me know.
This comment answered the question: the script cgal_create_cmake_script can be used to create a CMake file that can be used to generate a correct Visual Studio project using CGAL.

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