Can build Mysql Connector C++ on vs 2017? - visual-studio-2017

I tried to build mysql-connector-c++ from source to static library.
Referring the official spec here, I generated the Visual studio solution by the following command:
cmake -DMYSQL_DIR="E:\mysql-5.7.21-winx64" -DWITH_BOOST="E:\libs\boost_1_67_0_BUILDED" -DWITH_JDBC=ON -G "Visual Studio 15 2017 Win64" ../
Then, I opened the vs solution generated by cmake.Run build, got the two libs: mysqlcppconn8-static-mt.lib, mysqlcppconn-static-mt.lib, and copied them to my project.
When I built my project (also vs2017 version), I got the error:
mysqlcppconn-static-mt.lib(net_serv.obj) : error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1800”不匹配值“1900”(ActionProcessor.obj 中)
I am confused. They're all built in vs2017, and platform toolset are all set to "Visual Studio 2017 (v141)". I can't understand where 1800_MSC_VER has come from.

Here is what I did
Specs
Visual Studio 15, (2017)
x64
Static (.lib)
With static runtime (/MT)
Tools
CMAKE
Bison (In a folder without spaces)
Perl (ActiveState or Strawberry)
OpenSSL 1.0.2q.tar.gz
Add CMAKE, Bison and pearl to your system path
Check to see if you got all setup correctly
C:\>cmake --version
cmake version 3.9.6
C:\>bison --version
bison (GNU Bison) 2.4.1
C:\>m4 --version
m4 (GNU M4) 1.4.13
C:\>perl -version
This is perl 5, version 24, subversion 3 (v5.24.3)
Step 1: Build OpenSSL 1.0.x
Note: if you want to build OpenSSL 1.1.x steps will be a bit different
Extract to: C:\mysql-8.0.15\openssl-1.0.2q
Run: x64 Native Tools Command prompt for VS 2017
cd C:\mysql-8.0.15\openssl-1.0.2q
Release
perl Configure VC-WIN64A no-shared --openssldir=.\rel64
ms\do_win64a
nmake -f ms\nt.mak
nmake -f ms\nt.mak install
Debug
nmake -f ms\nt.mak clean
perl Configure debug-VC-WIN64A no-shared --openssldir=.\dbg64
ms\do_win64a
nmake -f ms\nt.mak
nmake -f ms\nt.mak install
Step 2: Build MySQL (Yes the actual database)
Extract to: C:\mysql-8.0.15
Run: x64 Native Tools Command prompt for VS 2017
cd C:\mysql-8.0.15\
cmake . -G "Visual Studio 15 2017 Win64" ^
-DWITH_BOOST=C:/mysql-8.0.15/boost ^
-DDOWNLOAD_BOOST=1 ^
-DBUILD_CONFIG=mysql_release ^
-DWITH_SSL=C:\mysql-8.0.15\openssl-1.0.2q\rel64 ^
-DLINK_STATIC_RUNTIME_LIBRARIES=1
Copy m4.exe to C:\mysql-8.0.15\sql\ this avoids any m4.exe errors during built
Open MySQL.sln and build for release x64
Copy binary_log_funcs.h and binary_log_types.h from mysql-8.0.15\libbinlogevents\export to mysql-8.0.15\include
The library should be located at:
Static release library: C:\mysql-8.0.15\archive_output_directory\Release\mysqlclient.lib
Step 3: Build MySQL Connector C++
Copy C:\mysql-8.0.15-dbg\archive_output_directory\Debug\mysqlclient.lib
to C:\mysql-8.0.15-dbg\lib\vs14
Run CMAKE GUI
Browse to the path of the MySQL Connector Project.
Click Configure, Select Visual studio 15 2017 Win64, native compilers
Tick BUILD_STATIC
Tick STATIC_MSVCRT
TICK WITH_JDBC
remove WIN_SSL_YASL from CONFIG_VARS
WITH_SSL = C:\mysql-8.0.15\openssl-1.0.2q\rel64
WITH_BOOST= C:\mysql-8.0.15\boost\boost_1_66_0
MYSQL_DIR=C:\mysql-8.0.15
Open MySQL_CONCPP.sln build for Release x64
The library is located at:
C:\mysql-connector-c++-8.0.15\jdbc\install\lib\mysqlcppconn-static-mt.lib
C:\mysql-connector-c++-8.0.15\Release\mysqlcppconn8-static-mt.lib
Step 4: Test it
Note: This test is for the JDBC style API. If you are not maintaining an existing application, use the new xdevapi API.
Create a new project and put the following in main.cpp
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#define STATIC_CONCPP
#define CONCPP_BUILD_STATIC
#define CPPCONN_PUBLIC_FUNC
#include <driver.h>
#include <connection.h>
#include <statement.h>
#include <exception.h>
sql::Driver *mDriver;
sql::Connection *mConnection;
int main() {
mDriver = get_driver_instance(); //or use: new MySQL_Driver()
try {
mConnection = mDriver->connect("host", "username", "password");
mConnection->close();
}catch(sql::SQLException& ex) {
std::cout << ex.what();
}
delete mConnection;
return 0;
}
Set: Linker > Input > Additional Dependecies:
libeay32.lib;mysqlclient.lib;mysqlcppconn8-static-mt.lib;mysqlcppconn-static-mt.lib;ssleay32.lib;%(AdditionalDependencies)
Set: Configuration Properties > VC++ Directories
Include Directories.
Library Directories.

I don't even know where to start explaining to be honest. Building this was a massive pain.
Before you begin to read this, please ensure you have the following:
C:\boost
C:\OpenSSL-Win32
C:\OpenSSL-Win64
Because I was writing my own "wrapper" and trying to make UNICODE work properly, I was getting weird exceptions, and I was unable to debug anything because I downloaded the latest package which is built without debug information (https://dev.mysql.com/downloads/connector/cpp/)
This is the first time I try to build this, so I went to their Github repository and grabbed the latest "master": https://github.com/mysql/mysql-connector-cpp
BUT! This does not contain the "JDBC" sources, which is by the way the "native" connector as they call it. So I grabbed it from the branch: https://github.com/mysql/mysql-connector-cpp/tree/jdbc and then copied the files into "mysql-connector-cpp-master\jdbc".
OK. I opened "x64 Native Tools Command Prompt for VS 2017" and navigated to "mysql-connector-cpp-master". At this point I still had no idea what I am doing and how to build it, all I could understand from the docs and different articles here is to run:
cmake -DWITH_JDBC=ON --build .
This started to configure things and build OK, but it stopped here:
-- Searching for static libraries with the base name(s) "mysqlclient"
CMake Error at FindMySQL.cmake:524 (message):
Could not find "mysql.h" from searching "/usr/include/mysql
/usr/local/include/mysql /opt/mysql/mysql/include
/opt/mysql/mysql/include/mysql /usr/local/mysql/include
/usr/local/mysql/include/mysql C:\Program Files/MySQL/*/include
C:/MySQL/*/include"
Call Stack (most recent call first):
CMakeLists.txt:332 (INCLUDE)
OK. So what now... where is "mysql.h" ?! After searching... and searching, I found this: Missing mysql.h and trying to find mysql-devel
And I quote:
Grab the MySQL Community Server and install it on your system. It
contains a directory called include in which you find the mysql.h.
Ok, great we need more stuff. So I download: https://dev.mysql.com/downloads/mysql/ and run the command again.
Happy days, something happened but no libs yet. I did get however a VS 2017 solution called: "MYSQLCPPCONN.sln".
This contains VS 2017 configuration to build the library for Win32. And of course trying to build with this solution will give you A LOT of unresolved external symbols.
So I run again the cmake but with static option added:
cmake -DWITH_JDBC=ON -DBUILD_STATIC=ON --build .
This time when I open "MYSQLCPPCONN.sln" I can see another project "mysqlcppconn-static" and this builds fine without issues.
However, in my case I need x64. I just created a new configuration for x64 by copying the exiting configuration fron Win32.
So that's it, I have both Win32 and x64 "mysqlcppconn-static.lib".
Overall Conclusion at this time:
Quite hard to build, without experience you will spend some time...
time.
No proper documentation, their existing documentation is poorly
written and very confusing.
No UNICODE support, yes the projects compile as Multi-Byte
Character Set.
I will see if I can debug and find out why am I getting exceptions in the library when using this (from their documentation):
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"] = "";
connection_properties["port"] = "";
connection_properties["userName"] = "";
connection_properties["password"] = "";
connection_properties["schema"] = "";
connection_properties["OPT_CONNECT_TIMEOUT"] = 10;
connection_properties["CLIENT_MULTI_STATEMENTS"] = (true);
connection_properties["OPT_CHARSET_NAME"] = "utf8";
connection_properties["OPT_SET_CHARSET_NAME"] = "utf8";
I hope you can build your library with this information, and hopefully in the future it will become more easier and clear.
Good Luck.

Related

Trying to build mysql-connector-cpp on Windows

I want to be able to build mysql-connector/c++ applications in debug mode (VS2k17), and understand the only way I can do that is to first build mysql-connector-cpp from source on my computer (Windows 10/64bit). I tried the following:
cmake . -DWITH_SSL=C:\Users\Rawb\source\libraries\OpenSSL-Win64
and it looks to complete successfully ...
Install location: C:/Users/Rawb/MySQL/MySQL Connector C++ 8.0
Connector libraries will be installed at: lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Rawb/source/repos/mcc2/mysql-connector-cpp
but when I run the following cmake build ...
cmake --build . --config
it fails with this output ...
LINK : fatal error LNK1104: cannot open file 'ssleay32.lib' [C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj]
Done Building Project "C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj" (default targets) -- FAILED.
Done Building Project "C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\ALL_BUILD.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj" (default target) (10) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ssleay32.lib' [C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:14.57
What might I be doing wrong? Do I just need to place the ssleay32.lib file somewhere? I do have a copy of it but not sure how it should be included. Or is it more complex? I.e. Do I need to build Open SSL first on my machine as well? This is a deep rabbit hole for me, I may be in over my head haha!
NOTE: I also asked this question on reddit with no luck, so hoping someone here might know.
If you're using MSVS (any version, including MSVS 2017), then I'd suggest using "NMake" (instead of cmake). Or just create a new C/C++ library project in the MSVS IDE.
The flag you're looking for is /LIBPATH. I don't think you need "-D", but you certainly need "/LIBPATH".
Here are the MSVS linker options:
https://learn.microsoft.com/en-us/cpp/build/reference/linker-options?view=vs-2017
Finally, you might be able to do all the troubleshooting/tracing you want without actually debugging (and rebuilding) the connector code.
Here's how to enable tracing in the MySQL Connector:
https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-debug-tracing.html
Please let me know if this helps.

Unable to build GDAL Visual Studio project with "generate_vcxproj.bat"

I need to link GDAL library to a c++ project.
I use the instruction from here:
http://trac.osgeo.org/gdal/wiki/GeneratingVisualStudioProject
Download gdal231.zip from official web site. Unpack.
(this step may be omitted — result will be the same) Edit nmake.opt by adding this in the very top of the file:
MSVC_VER=1910
WIN64=1
(don't know if it's right; there is no thorough guide)
Run win cmd, type "generate_vcxproj.bat 15.0 64 gdal_vs2017", wait for finish.
Open gdal_vs2017.vcxproj with MSVS Community 15.8.4. Build solution.
Build failed with "fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory".
Project settings look strange:
1
"VC++ Directories" seem normal, except $(VC_SourcePath) in "Library Directories":
2
What's wrong with it?
In order to build GDAL one doesn't need a Visual Studio project. Don't know what's wrong with "generate_vcxproj" script — it just does'nt work. But there is another way.
Unpack gdal231.zip.
Launch "x64 Native Tools Command Prompt for VS 2017" (or whatever version of VS command prompt that suits your needs). cd to "gdal-2.3.1\" dir.
Open nmake.opt file. In it's beginning there are some hints for usage of makefile.vc. Pick some arguments from there. I opt for x64 release build, so my call to nmake was like that: "nmake -f makefile.vc MSVC_VER=1910 WIN64=1". (1910 is a version of Visual Studio 2017).
Switch to "Native tools command prompt" and type "nmake -f makefile.vc MSVC_VER=1910 WIN64=1" there. Enter.
When it's finished, type "nmake -f makefile.vc MSVC_VER=1910 WIN64=1 install" and press Enter.
When that's finished too, type "nmake -f makefile.vc MSVC_VER=1910 WIN64=1 devinstall" and press Enter.
Done. The library is in C:\warmerda\bld\ folder.
I got the same problem when building with VS2017 Community Edition. I was able to build fine using VS2015 Community Edition.
Bottom line: when running the .bat, use the 2015 option.
Modify the generate_vcxproj.bat file using the information from here:
https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
I modified mine to work with Visual Studio Community 2019 by modifying lines 55-70 to be this:
if "%_vcver_%"=="16.2" (
set _clver_=1922
set _vstoolset_=v1422
) else if "%_vcver_%"=="15.0" (
set _clver_=1910
set _vstoolset_=v141
) else if "%_vcver_%"=="14.0" (
set _clver_=1900
set _vstoolset_=v140
) else ( if "%_vcver_%"=="12.0" (
set _clver_=1800
set _vstoolset_=v120
) else (
echo Wrong value for parameter 1. See usage:
goto :usage
))

LNK1181 error when compiling V8 engine on Win10

I'm following this guide on building V8 but I am hitting some issues on the compilation step. I am running Windows 10 x64. I am trying to compile with options to embed the engine also.
Running the following command:
ninja -C out.gn/x64.release
Gives me this error:
ninja: Entering directory `out.gn/x64.release'
[1/471] LINK mksnapshot.exe mksnapshot.exe.pdb
FAILED: mksnapshot.exe mksnapshot.exe.pdb
C:/Workspace/depot_tools/win_tools-2_7_6_bin/python/bin/python.exe ../../build/toolchain/win/tool_wrapper.py link-wrapper environment.x64 False link.exe /nologo /OUT:./mksnapshot.exe /PDB:./mksnapshot.exe.pdb #./mksnapshot.exe.rsp
LINK : fatal error LNK1181: cannot open input file 'comdlg32.lib'
ninja: build stopped: subcommand failed.
Now I believe I have narrowed down the error to looking for the .lib files in the wrong directory. I have (had) multiple versions installed, so there were multiple folders in my Windows Kit install.
Windows Kits/10/Lib/10.0.16299.0
Windows Kits/10/Lib/10.0.15xxx.0
If I dragged and dropped the comdlg32.lib file from 10.0.16299.0 into the 10.0.15xxx.0 directory then the error changed to a LNK1181 error with a different input file. I did this a few times but I was unsure if this was going to cause issues with different versions and there was probably going to be a lot.
I uninstalled the 10.0.15xxx.0 version which left behind the folder I mentioned, so I removed that and after doing so I have started getting the LNK1181 error with a different input file (advapi32.lib I assume the very first file it can't find). This is how I came to the conclusion about the path being incorrect.
So I have tried a few things to change the path (I hoped just uninstalling the old version would fix it) such as:
Uninstalling the old version.
Going through registry entries to see if I can find an install path or something using that path, which I didn't. I did notice that there was still installation and data in the registry for the 10.0.15xxx.0 install, I might try deleting that from the registry directly as a last resort?
I have tried to explicitly set the path by setting <TargetUniversalCRTVersion>10.0.16299.0</TargetUniversalCRTVersion> in this file: C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\uCRT.props
I have never used Ninja before so I tried looking for a way to set some kind of lib-path in the command but couldn't really find anything.
I looked through the python scripts being executed to try and locate something to do with the libs path but couldn't see anything.
I would be grateful for any help and suggestions. Thanks.
You can try to compile v8 using Visual Studio as explained here: https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md#using-the-visual-studio-ide
By running the following commands:
$ gn gen --ide=vs out.gn/x64.release
$ cd out.gn/x64.release
$ msbuild all.sln
You can see a full example here: https://github.com/phpv8/v8js/issues/272#issuecomment-262848754
Apparently this method is not officially supported anymore, but I had the same problem as you have and this solved the issue for me.
Note that after this I had another issue, the unit tests failed to be compiled due to a linking error, but I had the necessary libraries to use v8. So there may be deeper problem that is causing all of this that I'm missing.
Edit:
Also, you could try to set the following parameters with gn args:
visual_studio_path = "..."
visual_studio_version = "2017"
wdk_path = "..."
windows_sdk_path = "C:\Program Files (x86)\Windows Kits\10"
To set those parameters, do:
gn args out.gn/x64.release
This will open a text editor where you can write the extra parameters you are interested in.
To see the full list of parameters you can specify:
gn args --list out.gn/x64.release
I was following this guide https://medium.com/dailyjs/how-to-build-v8-on-windows-and-not-go-mad-6347c69aacd4 and also ran into the error
LINK1181: cannot open input file 'advapi32.lib'
I'm pretty sure it was because I had the wrong versions of the Windows 10 SDK. Similar to you I had versions:
Windows Kits/10/Lib/10.0.10240.0
Windows Kits/10/Lib/10.0.16299.0
But according to https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md#Setting-up-Windows (Which I think is relevant) you need version 10.0.15063.0
After installing version 10.0.15063.0 (with the visual studio installer) to
Windows Kits/10/Lib/10.0.15063.0
I was able to continue with the build.

Stroustrup: For C++, how do I install FLTK library?

Question: Can someone give me instructions on how to install FLTK for Microsoft Visual Studio 2015, so that I can use FLTK for C++?
Extra Information:
the Chapter 12 drill, in Bjarne Stroustrup's Programming: Principle and Pracice using C++ wants me to install FLTK.
I have Microsoft Visual Studio 2015.
I downloaded the files at www.stroustrup.com/Programming/FLTK.
Then I opened the fltk.dsw in C://Program Files (x86)/Microsoft Visual Studio 14.0/VC.
But the build failed.
I searched this website for any similar problems; but the last similar question is a person asking for help with VS2010, 4 years ago.
I'm sorry again, guys. but this issue seems beyond my grasp because this is my first time installing a library on C++
Since the above answer was given, changes have occurred that have made it easier to install the FLTK library on a Microsoft Windows system. I have outlined below how I went about installing the FLTK library and getting a simple FLTK program to run.
For those of you working your way through Bjarne Stroustrup's Programming, Principles, and Practices Using C++, here is how I got the FLTK library installed and operational on a Windows 10.0.18363 Build 18363 a.k.a. Windows 10 1809 Pro using the VCPKG and MSYS2 versions of the FLTK library 1.3.5.
INSTALLATION
Using Microsoft VCPKG
The steps below assume that Visual Studio is already installed.
1. Clone the VCPKG
1.1 Open PowerShell as an Administrator.
1.2 Enter a directory to clone the VCPKG--e.g. C:\ProgramFiles.
1.3 Copy and paste the following into PowerShell and press enter to start downloading VCPKG or go to https://github.com/Microsoft/vcpkg: git clone https://github.com/microsoft/vcpkg.git
1.3.1 After VCPKG finishes downloading, there should be a vcpkg-master directory. Enter the following at the command line:
1.3.1.1 cd vcpkg-master
1.3.1.2 .\bootstrap-vcpkg.bat
1.3.1.3 .\vcpkg integrate install
1.3.2 The command in step 1.3.1.2 will compile the VCPKG library using the most recent Visual Studio it can find on your system.
1.3.3 The command in step 1.3.1.3 will configure Visual Studio to locate all vcpkg header files and binaries on a per-user basis. There's no need for manual editing of VC++ Directories paths. SEE https://learn.microsoft.com/en-us/cpp/build/vcpkg?view=vs-2019#installation for more info.
1.4 This concludes the installation of VCPKG. For more information, see the following:
1.4.1 https://learn.microsoft.com/en-us/cpp/build/vcpkg?view=vs-2019#installation
1.4.2 https://devblogs.microsoft.com/cppblog/vcpkg-a-tool-to-acquire-and-build-c-open-source-libraries-on-windows/
2. Install FLTK Using VCPKG
2.1 In PowerShell, execute the following commands:
2.1.1 .\vcpkg install fltk:x86-windows
2.1.2 .\vcpkg install fltk:x64-windows
2.2 The above two commands will install FLTK into vcpkg-master\packages.
3. Modify the x.H file
3.1 When trying to run the FLTK test program under Visual Studio 2019, I was getting the error message: "… cannot open include file ‘x11/xlib.h’ no such file or directory …" that is documented in Resource #3 below. So, I ended up modifying the x.H file as instructed in this resource. Here's what to do. . .
3.2 If you get this error, double-click on the error message to open up the file within Visual Studio. If it does not open, I found my file in: ..\vcpkg-master\installed\x64-windows\include\FL\x.H
3.3 Go to line 28, "...between # include “Enumerations.H” on line 27 and # ifdef WIN32..." add include "# define WIN32" as shown by the red arrow in the screen shot below:
Using MSYS2
The steps below assume that MSYS2 is already installed.
1. Install FLTK
1.1 Open the MSYS2 MSYS terminal.
1.2 For 64-bit systems, enter: pacman -S mingw-w64-x86_64-fltk
For 32-bit systems, enter: pacman -S mingw-w64-i686-fltk
1.3 In the ../msys64/mingw64/bin directory, there should be a fltk-config file. If the installation was successful, you should see the fltk version number after executing the following command: fltk-config --version.
FLTK TEST PROGRAM
Using Microsoft Visual Studio Community 2019 Version 16.4.5
1. Create a new project
1.1 Select File --> New --> Project or press CTRL+SHIFT+N
1.2 Click on Windows Desktop Application
1.3 Enter a project name and create your project
2. Create a header file
2.1 Right-click on the Header Files folder and select Add --> New Item
2.2 Name the header file
2.3 In the new header file, under #include "resource.h" enter the following:
#include <Fl/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
2.4 Save the file.
3. Open the source file
3.1 Under #include "framework.h", enter a #include statement for the header file created in step 2 above.
3.2 Locate the comment: // TODO: Place code here.
3.3 Copy and paste the following code below the comment in Step 3.2:
Fl_Window window(200, 200, "Window Title");
Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
window.show();
return Fl::run();
3.4 Press CTRL+F5 to run the program. A window should display with the words: "Hey, I mean, Hello, World!".
Using MSYS2
1. Using a text editor or IDE of your choice, create a header file and copy and paste the following:
#include <Fl/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
2. Create a source file--e.g. fltk_test.cpp. Copy and paste the following code into the source file:
#include "name of your header file in Step 1"
using namespace std;
int main (int argc, char *argv[])
{
Fl_Window *window = new Fl_Window(340, 180);
Fl_Box *box = new Fl_Box(20, 40, 300, 100, "Hello World");
box->box(FL_UP_BOX);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
3. Compile and build the source
3.1 Open a MSYS MinGW 64 terminal
3.2 Enter the following at the command line: g++ -v -g <your source file name> -lfltk -o <your exe file name>. For example, g++ -v -g fltk_test.cpp -lfltk -o fltk_test.exe
3.4 The linker flag -lfltk MUST come after the source file [THIS IS VERY IMPORTANT!]. If it does not, undefined reference errors will be generated.
4. Run the program: .\fltk_test.exe. A window should display with the words: "Hello, World!".
EXTRA - Makefile
Below is a sample Makefile using the file name: fltk_mingw_test
#
# DATE: 2020 FEB 27
# FILENAME: Makefile
# DESCRIPTION: This is a Makefile for the MSYS2 version of FLTK
# 1.3.5. It will compile and build the Hello World program
# found at https://www.fltk.org/doc-1.3/basics.html#basics_standard_compiler
#
CXX = $(shell fltk-config --cxx)
DEBUG = -g
CXXFLAGS = $(shell fltk-config --use-gl --use-images --cxxflags ) -I.
LDFLAGS = $(shell fltk-config --use-gl --use-images --ldflags )
LDSTATIC = $(shell fltk-config --use-gl --use-images --ldstaticflags )
LINK = $(CXX)
TARGET = C:\<your path>\fltk_mingw_test.exe #File extension must be exe
OBJS = fltk_mingw_test.o
SRCS = fltk_mingw_test.cpp
.SUFFIXES: .o .cpp
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(DEBUG) -c $<
all: $(TARGET)
$(LINK) -o $(TARGET) $(OBJS) $(LDSTATIC)
$(TARGET): $(OBJS)
fltk_mingw_test.o: fltk_mingw_test.cpp fltk_mingw_test.h
clean: $(TARGET) $(OBJS)
rm -f *.o 2> /dev/null
rm -f $(TARGET) 2> /dev/null
Please note: you need to put a tab character at the beginning of every recipe line! This is an obscurity that catches the unwary. If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character (see Special Variables).
FOR MORE INFORMATION SEE: GNU Make Manual
RESOURCES
vcpkg: a C++ package manager for Windows, Linux, and MacOS
Vcpkg: a tool to acquire and build C++ open source libraries on Windows
How to install and use fltk-1.3.4 in Visual Studio 2017 2.0 [complete guide] – preventing cross-contamination
GNU make Manual
To install the FLTK to work with the VS 2015, you can follow this article: http://www.c-jump.com/bcc/common/Talk2/Cxx/FltkInstallVC/FltkInstallVC.html
Now the latest version of FLTK is 1.3.3 and you can find it from here http://www.fltk.org/software.php and select the ‘fltk-1.3.3-source.tar.gz’ to download. I already downloaded this one and followed the steps in the above guide document, finally it is successful and the test result is matched the expected one as below:

How to fix unresolved external symbol due to MySql Connector C++?

I followed this tutorial http://blog.ulf-wendel.de/?p=215#hello. I tried both on Visual C++ 2008 and Visual C++ 2010. Either static or dynamic, the compiler gave me the same exact error messages:
error LNK2001: unresolved external symbol _get_driver_instance
Has anyone experience this issue before?
Update:
+ Additional Dependencies: mysqlcppconn.lib
+ Additional Include Directories: C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include
+ Additional Libraries Directories: C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt
Another Update:
Click F12 on get_driver_instance() linked to:
class CPPCONN_PUBLIC_FUNC Driver
{
protected:
virtual ~Driver() {}
public:
// Attempts to make a database connection to the given URL.
virtual Connection * connect(const std::string& hostName, const std::string& userName, const std::string& password) = 0;
virtual Connection * connect(std::map< std::string, ConnectPropertyVal > & options) = 0;
virtual int getMajorVersion() = 0;
virtual int getMinorVersion() = 0;
virtual int getPatchVersion() = 0;
virtual const std::string & getName() = 0;
};
} /* namespace sql */
extern "C"
{
CPPCONN_PUBLIC_FUNC sql::Driver *get_driver_instance();
}
Apparently, the function existed, but the linker could not find it.
Code snippet:
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
using namespace std;
#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 *conn;
sql::Statement *stmt;
sql::ResultSet *res;
driver = get_driver_instance();
conn = driver->connect( "http://localhost/chandb", "root", "chan" );
stmt = conn->createStatement();
res = stmt->executeQuery( "select * from another" );
while( res->next() ) {
cout << "id = " << res->getInt( "Id" );
cout << "id = " << res->getInt( "GoldValue" );
cout << "id = " << res->getString( "Model" );
}
delete conn;
delete stmt;
delete res;
std::cout << "This is it";
}
catch( sql::SQLException e ) {
cout << e.what();
}
}
Thanks,
Chan
According to MySQL 5.1 Reference Manual if you are using the Version 1.1 of the MySQL Connector C++:
"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."
If I understand the previous note correctly, you have to use the dynamic build and define mysqlcppconn_EXPORTS.
If you use static linking, you need to set CPPCONN_PUBLIC_FUNC= in Project / Properties / C++ / Preprocessor / Preprocessor Definitions
I faced Same Error while using c++/Sql Connector.
and after spending entire day I solved this problem by using 32 bit libmysql.dll , 32 bit libmysqlcppcon.lib and 32 bit libmysqlcppcon.dll ( Dynamic binding is used because driver instance creation is only available in dynamic library of libmysqlcppcon.lib)
I found very good link explaining everything along with the working code. I think it would help others if they stuck at the same issue.
http://r3dux.org/2010/11/how-to-use-mysql-connectorc-to-connect-to-a-mysql-database-in-windows/
error LNK2001: unresolved external
symbol _get_driver_instance
That error message basically means that the linker cannot locate the function get_driver_instance anywhere, eg. it's not in any of the object files from your compilation units, not in a static .lib library or import library. This can also happen if the mangled names in the library doesn't match exactly with what the linker expects to find. eg. Library was built with different calling convention etc.
I would suggest that you take a look at the final command line being used from your project and update your post here for both compiling and linking. Second, make sure the mysql library you're linking against has that function. I believe there's a commandline tool in vs for dumping and viewing the contents of a static lib.
If you're linking against a dynamic dll version of mysql, make sure the import library contains the missing referenced symbol. Additionally, you can crack the dll open with a PE viewer and look under it's export tables to verify that that function actually exist and is visible.
Edit: According to this post, the function get_driver_instance should be in 'mysqlcppconn.lib' somewhere. Are you sure that file is being properly linked?
I read the article you mentioned.
It has this line for static compilation : As said, you need to link both "mysqlcppconn-static.lib" and "libmysql.lib".
Since you don't mention this is you question ,have you tried this ?
Also , on a forum I read this (for eclips) "You must have this in source":
#include "mysql_driver.h"
#include "mysql_connection.h"
using namespace sql::mysql;
Anyway ,good luck !
I don't know if you have your heart set on using this MySQL Connector/Driver package but there are many robust database wrappers available for free or nearly free out there if this is causing seemingly unspoken headaches for you.
I actually was thoroughly impressed by QT database objects when I used them previously for a data model project. The QT framework is licensed under LGPL and also has a commercial version available and is a very versatile set of cross platform libraries. The QtSql objects provide a consistent interface to many databases including MySql, SQLServer, Postgres, ODBC, etc with the ability to substitute your own drivers and still use the same interface for everything at a high level in C++
Some other notable options:
SQLApi++
MySQL++
Not trying to come on like a salesman or anything and I have no affiliation with any of these but sometimes it never hurts to shop around and find something that works better for your needs.
I solved using the 32bit version both for mysql server and connector/c++ on 64bit OS.
I think the problem are the boost libraries but im not sure.
I spent several hours trying to solve the problem exactly the same as you. I finally found out the problem myself. I downloaded the 64-bit version of MySQL/SQL Connector and followed a tutorial in MySQL.com in setting up win32 console project its properties and got the error message as mentioned. It was because the tutorial is teaching to build a 32-bit program. After I change to build a release version of X64 code, problem was solved.
Make sure your library is 32bit or 64bit and then configure your Visual Studio accordingly (in configuration manager).
Hello same problem for me, i have search and found my solution, i give you my paths on my local computer, but you can put all where you want, it's just my personnal notes:
The goal is to compile mysql cpp connector on your computer, to have lib which work on your computer when you compile somewhat with.
DEPENDENCIES:
clone (recursively with submodules, to have the folder jdbc) the repo on master branch (same than 8.0.27 for me when i write this post) of mysql cpp connector source code for windows on github:
https://github.com/mysql/mysql-connector-cpp/tree/master
Or if you haven't git, you can do it manualy by download zip: mysql-connector-c++-8.0.27-src.zip: https://dev.mysql.com/downloads/connector/cpp/
and download manualy jdbc by clicking on jdbc folder on this page: https://github.com/mysql/mysql-connector-cpp/tree/master
and the jdbc download must to be unzip and rename by "jdbc", and put in the mysql cpp connector folder
download mysql server for windows:
choice: Windows (x86, 64-bit), ZIP Archive
version: 8.0.27
size: 209.4M
url: https://dev.mysql.com/downloads/mysql/
filename: mysql-8.0.27-winx64
and put mysql-8.0.27-winx64 in C:\Users\< USER >\Downloads\mysql-8.0.27-winx64
download openssl (Win64 OpenSSL v1.1.1m):
binary installer msi: https://slproweb.com/products/Win32OpenSSL.html
it's not official :/ but that work (and it linked by this site too: https://wiki.openssl.org/index.php/Binaries), and i have failed and give up to build from source code)
Install openssl here: E:\OpenSSL-Win64
unfortunaly the version 3.0.1 doesn't work for build cpp connector (or my bad ?)
download boost: https://www.boost.org/users/download/
untarGz and put it here: E:\boost_1_78_0
CONFIGURATION:
for the configuration you must have this folder architecture:
. Parent Folder (for me it's E:\MySql)
|
|\
| \
| . _SOURCE (renamed mysql cpp connector repo)
| |
| .
| .
| .
| |
| |\
| | \
| | . jdbc (jdbc submodule)
| .
| .
| .
|
|\
| \
| . _BUILD
\
\
. _INSTALL
with this folder architecture if you have errors in next commands, your sources will not to be modify, you will have just to remove the containt of _BUILD and _INSTALL folders to relaunch
open powershell in E:\MySql and launch cmd:
cmake .\_SOURCE\ -B .\_BUILD\ -D CMAKE_INSTALL_PREFIX=.\_INSTALL -D CMAKE_BUILD_TYPE=Debug -D WITH_SSL="E:\OpenSSL-Win64" -D BUILD_STATIC=OFF -D WITH_JDBC=ON -D WITH_MYSQL="C:\Users\< USER >\Downloads\mysql-8.0.27-winx64" -D WITH_BOOST="E:\boost_1_78_0" -D MYSQLCLIENT_STATIC_BINDING=OFF -D MYSQLCLIENT_STATIC_LINKING=OFF -G "Visual Studio 16" -A "x64"
the last lines of output must to be like:
-- Configuring done
-- Generating done
-- Build files have been written to: Your-Build-Path/_BUILD
BUILDING:
launch cmd: cmake --build .\_BUILD\
There are a lot of fatal errors possible:
mysql not found
boost not found
openssl not found
openssl bad version (need 1.1.1)
no compatible options values between options
forgoten options, if this is the case, try to add the option with his default value
so check yours paths dependecies if you have errors
There somes not fatal warning:
the "is_same" test doesn't work
file sys/endiand.h not found
file sys/byteorder.h not found
when the output say "look log files output.log and errors.log" you have fatal error some where, but may be (MAY BE) don't loss time on the warnings and on the logs files... and look all the lines of the ouput, because for me the fatals errors was not listed in the logs files but in the output (may be not for you, i don't know)
INSTALLATION:
cmake --install .\_BUILD\ --config Debug
END:
in folder: E:\MYSQL\_INSTALL\lib64
there are dynamic lib
in folder: E:\MYSQL\_INSTALL\lib64\vs14
there are static lib
and E:\MYSQL\_INSTALL\lib64\vs14\mysqlcppconn.lib
will containt "get_driver_instance" functions to use mysql cpp connector etc...
if you want open mysqlcppconn.lib with 7zip, right click, open archive, open 1.txt and 2.txt, and CTRL+F your functions
NOTES:
you can't configurate in Debug (-D CMAKE_BUILD_TYPE=Release), else the first cmake cmd will create a visual studio project (E:\MYSQL\_BUILD\jdbc\connector-jdbc-deps.vcxproj) with inside a unknow linked library (MYSQLLIB-NOTFOUND-DEBUG), and the cmake build cmd will fail
in my visual studio project, i have link the two static lib, and i have copy past the two dynamic lib next to my exe, that work for me
VERSION-ARCH:
software
version
arch
windows pro
10
x64
cmake
3.22.1
x64
Microsoft Visual Studio Community 2019
16.11.8
x64
Microsoft .NET Framework
4.8.04084
x64
openssl
v1.1.1m
x64
boost
1.78.0
cross-arch ?
mysql server
8.0.27
x64
mysql cpp connector
8.0.27
x64