How to add MySQL connector/C++ 1.1 to Visual Studio 2010 project? - c++

I'm trying to add MySQL Connector/C++ to my visual Studio 2010 project.
I followed the steps (here, mysql docs) to add it to Visual Studio (I also added Boost in the "Additional include Directories").
It asked for a "sqlstring.h" file ( How a release can miss a file ?! ), so I had it from the source files (mysql source archives).
Then, It asked for libmyql.lib, I had the lib directory of MySQL Server 5.5\lib.
And now, I'm on this error:
Error 127 error LNK1120: 31 unresolved externals C:\Users\Haks\Documents\Visual Studio 2010\Projects\ProductManager\Debug\ProductManager.exe ProductManager
Error 60 error LNK2001: unresolved external symbol "__declspec(dllimport) bool __cdecl std::operator<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??$?MDU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#0#Z) C:\Users\Haks\Documents\Visual Studio 2010\Projects\ProductManager\ProductManager\mysqlcppconn-static.lib(mysql_ps_resultset.obj) ProductManager
So, maybe it's because I got the binary release of MySQL Connector/C++ 1.1 and maybe it's not compatible with VS 2010...
But I don't find the good way to compile the source files, and I never use Boost or CMake and it's seem to be needed.
I found no reference to my problem, so if someone got a response or a good way, it will be very useful for me and a lot of people I think.
Thank you

First of all, thanx to the dar7yl for pointing in the right direction.
After spending much time debugging mysql connection (VS 2010, C++), which proves to be a much hair raising experience, I am compelled to say something about it.
(assumed you setup C++ include files directory and link directory + additional dependence file correctly, else refer to the website on point 2 for reference)
0.) Yes, we need boost library. Download boost library (search google) and unpack it into your development folder and have your c++ additional include directories point to it(boost main directory, not the boost child directory).
1.) Need to be clear on the difference in VS solution configuration mode "debug" and "release". The .lib files provided provided after full installation of MYSQL under directory ...\mysql\Connector C++ ____\lib\ has two directories of debug and opt for use with solution mode "debug" and "release" accordingly. The main difference being "debug" mode uses the extra .pdb files.
2.) http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html gives a very detail outline for VS2008 mysql connection setup. Particularly the need to include under [Project, Properties tree view, under C++, Preprocessor] two statement of CPPCONN_PUBLIC_FUNC= and HAVE_INT8_T=1
3.) be clear which mode of connection you would like with the library, mysqlcppconn.lib is dll based while mysqlcppconn-static.lib is static based. For dll based lib, related dll mysqlcppconn.dll needs to be deposited into \windows\system32\ or other system path for access.
For static connection remember its using extern C connection so you will need libmysql.lib + libmysql.dll (libmysql.pdb if under "debug") from ...\mysql\connectorc c ___\, if not you will get the unresolved external symbol error LNK 2019. So promptly update your c++ include files directory, link include file directory, additional dependency accordingly and deposite the .dll file into system path or ....\windows\system32\
4.) At this point, things should work for some of us. And no, it didn't work for me. Reason? Library comparability issue as outlined by dar7yl. So if this is the case, download source code for the connector under http://dev.mysql.com/downloads/connector/cpp/ by select platform to source code. Unpack and it get a bit complicated from here.
No VS solution or project files? No worries, see the cmake__.txt file? that's our solution.
Download cmake and have the source directory and destination directory point to your unpacked source code directory. Then open cmake__.txt in the directory and search for keyword "boost" and update the boost directory to point to your boost directory. Run configure and set to VS 2010, check the outlined configuration and change whatever is necessary Name/Value table then press generate.
By now your project + solution files should have been generated, open it and you will see many projects. We are only concerned with mysqlcppconn and mysqlcppconn-static. check and update the include files, link files + dependency in the two project's property and compile. Drop the generated .lib + .dll (and .pdb if using "debug" mode) into the corresponding directories and your project should work now.
By this point mysql connection now works for me, hope it works for you too. Some details might be missing from the above and I do apologies.

Just a small addition to dddddd great post. If you are compiling on Windows7 then you will probably get some 'unresolved externals' from the libmysql.lib library. I found this was due to the fact that the libmysql.lib came from a 64bit installation of the server. You will need to find the 32 bit version and link with that, or just install the 32 bit server instead.

I finally got MySQL Connector/C++ working with visual Studio 2010 by downloading the source and compiling it with the same settings as my project. It still warns about SqlString library:
j:\mysql-connector-c++-1.1.0\cppconn\sqlstring.h(36): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
but, it seems to be ok with that.

Related

Problems linking Nlopt-2.4.2 in visual studio 2017

Some back story: I am trying to get the bolt-lmm software to compile on a Windows machine, because it would be a nice addition to the research group I am in. The developers of the software have only made a linux static executeable, but made the source code available. I am used to programming in R or python, and this is my first ever encounter with C++.
I have solved a fair bit of problems, but for some reason I have not been able to get visual studio to link properly with Nlopt-2.4.2.
I downloaded it
and followed the steps given there on how to install it.
I can tell I have done the same to link the Nlopt library to the project as is described in How to add additional libraries to Visual Studio project?
I still get errors like:
Error LNK2019 unresolved external symbol __imp__nlopt_create referenced in function "public: __thiscall nlopt::opt::opt(enum nlopt::algorithm,unsigned int)" (??0opt#nlopt##QAE#W4algorithm#1#I#Z) boltCompiler C:\Users\au483192\source\repos\boltCompiled\boltCompiler\NonlinearOptMulti.obj 1
(there are a total of 12 of this type of error, and an error link 1120, which just tells me there are 12 unresolved eternals.)
I hope this is enough information to provide a hint of what is going wrong.
I did some more digging, and it seems the linker needed more than just the folder for the .lib file.
This post sums it up:
Linking a static library to my project on Visual Studio 2010
Essentially you just need to tell the linker the placement of the lib and the actual name of the .lib file.
Hopefully this will help others who forgot/did not know that added library names manually could be needed for some libraries.
TL;DR:
open configuration properties for the project > linker > general
Then add the path to the .lib file in the "addition library directories" line
Then (still in configuration properties) go to linker > input
add the .lib file name to the "addition dependencies" line, e.g. libnlopt-0.lib (don't forget to separate with ";")

Unresolved external symbol in library in C++

I am trying to compile un software which is written in C++ at visual studio 2017,but I face un problem in the library. The description is like this.
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual void __thiscall CEZOptionsDlg::AddButton(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >,unsigned int)" (?AddButton#CEZOptionsDlg##UAEXV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##I#Z)
I have already included the path of library in the "VC++ directories" and added the *.lib in "Additional library directories".
The setting is in the mode "Debug" , "x86".
I have tried to change the setting in "Runtime library" but it doesn't work.
I have tried to change the "calling convention", but it doesn't work ,too.
Because it is a software who is written a bit long ago, I doubt that is it possible that the problem is on the x86 and x32. But in the "configuration manager", it runs at platform win32. It shouldn't be wrong.
I also doubt it might be the problem in the .dll, but I just compile the software. It should only be related to .lib
I don't know if the *.lib is complete because I don't have source code of this library.
I have been trapped in the problem for 2 days. Can anyone come and help me.
Your checklist
1) Confirm toolkit V110, v120,v14,v141
2) Confirm x86 or x64
3) Confirm MT ( static -> need only lib) or ML ( dynamic -> need a dll & lib)
4) DLL may be release or debug version
5) VS SDK version ( SDK 7.xx , SDK 8.1, SDK 10.xxx etc)
Use dumpbin.exe from your VS 2017 to find details for the exported methods and other signatures from the lib file. Use dependency-walker ( free download on net) to analyze the DLL file.
I finally found out it is caused by a very old version of de Visuel C++(VS 98), who is probably the same age as I am. After I used the VS98 in Visuel Stdio 2017( which sound ridiculous ), the code can build correctly.
I think this problem may only be occured to me. But, anyway, I hope this solution will help others.

Linking libpqxx from Visual Studio 2015 on Windows 10

I've recently decided to try out PostgreSQL as the database platform for some C++ development I'm working on. I decided to use libpqxx as the connection library for my project, and quickly found out this would be an uphill battle to do from VS 2015 on a Windows 10 machine.
After much teeth-gnashing and nail-biting, I have gotten libpqxx to compile on Windows 10.
This leaves me with the following directory structure
Per libpqxx's documentation, I also placed a copy of libpq.dll in my project's executable directory. Please note: I have done this for both debug and release builds, tried to build both, and ended up with the same result.
All the tutorials I've seen seem to indicate that the library can be used after linking it and simply #including pqxx/pqxx, so I set up a small project to do just that. I receive the error:
fatal error C1083: Cannot open include file: 'pqxx/pqxx': No such file or directory
When attempting to build the project. I have also tried this will both debug and release builds, to no avail.
Here is a screenshot of my linker settings.
Does anyone have any suggestions for how I might be able to link and use this library from Visual Studio 2015?
As Sami Kuhmonen pointed out, this was not actually a linker error, but a compiler error. I needed to include an actual header, which Visual Studio needed to be able to find. After adding the correct folder (C:\libpqxx\include in my case) to Visual Studio's "additional include directories" setting under C\C++ -> General per drescherjm's suggestion, the program compiles just fine.
For future reference:
I did also run into unresolved external linker errors after solving the initial issue. This is because you need to make sure to also link to ws2_32.lib and libpq.lib. You also need to copy some other DLL files that libpq also relies on into your libpqxx lib folder. On my system, I believe these were ssleay32.dll, libeay32.dll, and libintl-8.dll. These files reside under the root of the PostgreSQL install. The DLL step is mentioned under libpqxx's INSTALL.txt file, however I believe it stated that the DLLs resided one folder under where I actually found them.
I have also faced same issue. Then I realized that I was building ,my application as a 32bit. I changed the target to x64 and it compiled successfully

CMake And Visual Studio build errors

I've been trying to compile tulip using cmake to generate visual studio 2012 project files. It's giving me lots of trouble. I don't know how to get this to build. I've been trying to get visual studio to build this for 4 days now, and I'm extremely frustrated. Essentially, I follow the steps here, and then set the variables CMAKE_LIBRARY_PATH AND CMAKE_INCLUDE_PATH according to these instructions.
To get to where I'm at, all you have to do is download tulip, and:
Unzip it, create a separate build directory outside of this source directory
Open CMake-gui to the source and build directories
Hit configure. Check use qt5, tell it where qmake is (make sure it's qt5)
You need some dependencies as described in The Independent CMake tutorial. Grab all those dependencies
As you continue to hit configure, specify each of the directories that it asks for as it errors out. It should ask for freetype, glew, zlib and sphinx. It shouldn't ask for where libxml or libpng, or libjpeg are. I don't know why it doesn't ask for those.
Generate, and then browse to the ALL_BUILD that you've generated. Open it with visual studio
try to build it with visual studio.
In those instructions and in the process of getting CMake to generate the visual studio build files, it specifically asks for freetype's location. But in my build, it doesn't have a clue how to link the freetype library.
Here are the errors that I get
Here is my CMakeCached.txt
I know that many people aren't going to want to exactly try and go about replicating the build environment, so I've uploaded my build directory to dropbox. You can pull the entire thing down, and then open it in cmake gui and open the visual studio files in there too.
https://www.dropbox.com/sh/qsvukh9t5gb6bvt/tOfOBxWgd0
The linker errors you point to (mostly "unresolved external" errors) indicate that there are missing libraries on the link command line.
That is most likely happening because target_link_libraries calls in the tulip project are either being skipped or being called with library names that do not match the library names on disk.
Open up the solution in Visual Studio and right click the project and choose "Properties" -- look at the "Linker > Input" panel at the "Additional Dependencies" field. That should list all the libraries it wants to link to. Is there a freetype library listed there? Does that library exist in the referenced location on your disk?
There could be a mistake in the tulip project, or there could just be something wrong with your build/install of freetype...
UPDATE AFTER SOME CHAT:
Or it may be that you have some libraries built for x86 and some for x64... or maybe some for Debug and some for Release... or maybe even some with the MinGW compiler and some with the Visual Studio compiler. If that's the case, start over, from a clean slate, and build everything with a consistent compiler, configuration type and architecture. Then report back again with an update and see if the problems still remain.
I do with Dave,
You should try to fix your error 1 by 1.
The first error seems to be a link error:
Error 1 error LNK2019: unresolved external symbol gzread referenced in function "public: virtual int __cdecl gzstreambuf::underflow(void)" (?underflow#gzstreambuf##UEAAHXZ) C:\Users\kenne_000\tulip-build\tulip-build-debug\thirdparty\gzstream\gzstream.obj gzstream
gzstream is a third party lib included with tulip source in:
thirdparty\gzstream
from
thirdparty\gzstream\CMakeLists.txt
you can see that the missing symbols should be coming from ZLIB.
However your CMakeCache.txt indicate that
ZLIB_LIBRARY:FILEPATH=C:/Users/kenne_000/dependencies/zlib128-dll/lib/zdll.lib
is found.
So the question may be, was this dependency compiled with the same compiler?
Don't you have compiler-specific name mangling issue ?

Linking DLL error visual studio

I walked through this tutorial and tried to recreate the example I get this error:
Error 1 error LNK2019: unresolved external symbol __imp__GetXyz#0 referenced in function _main app.obj app
If I download the source from the website and run the project in visual studio it works, but If I even copy the code from the original project in my own visual studio solution it still doesn't work. I guess it must be some project settings, I don't know. What do do?
You need to add the XyzLibrary.lib to your Linker settings within project settings.
You can also do it directly in code by using #pragma comment(lib,"xyzlibrary.lib") if you are using VisualStudio.
The reason why it works in the given sample without these 2 approaches is that in the solution file, the dependencies are set from XyzExe to XyzLib, and XyzProject has 'Link Library Dependencies' in Linker settings set to true. However, I am not too keen on this approach, as I don't like to store data important for building inside solution files (for larger projects, developer's solution files can differ from build system solution files)
Seems like you are missing some external library that needs to be linked in. Whatever provides the GetXyz function is missing.
Open the Solution that works, right click the project, Properties, Linker, Input, and check what their Additional Dependencies list up. You need to add the same to your own project.