#### Archived

This topic is now archived and is closed to further replies.

# mysql++ for msVC++: Problems

This topic is 5191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I first attempted to direct this question to the developer of the api, but my mail returned an "undeliverable" message. The api in question is the mysql++ api for MS VC++6.0 from www.mysql.com I followed every instruction in the readme and went over it again and again, but no luck so far. My only hope is that someone in here have used the api successfully and can point me in the right direction. This is the errors I get:
--------------------Configuration: scms - Win32 Debug--------------------
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_string@ DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in scms.obj msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(class s td::basic_string,class std::allocator > const &,unsigned int,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z) already defined in libcpd.lib(ios.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string,class std::allocator >::_Tidy(bool)" (?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEX_N@Z) alread y defined in scms.obj msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string,class std::allocator >::_Copy(unsigned int)" (?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXI@Z)
already defined in libcpd.lib(iostream.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "void __cdecl std::_Xlen(void)" (?_Xlen@std@@YAXXZ) already defined in libcpd.lib(string.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ) already defined in libcpd.lib(iostream.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ) already defined in libcpd.lib(iostream.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::_Winit::_Winit(void)" (??0_Winit@std@@QAE@XZ) already defined in libcpd.lib(wiostrea.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::_Winit::~_Winit(void)" (??1_Winit@std@@QAE@XZ) already defined in libcpd.lib(wiostrea.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string,class std::allocator >::_Eos(unsigned int)" (?_Eos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXI@Z) a lready defined in libcpd.lib(iostream.obj) msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: bool __thiscall std::basic_string,class std::allocator >::_Grow(unsigned int,bool)" (?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAE
_NI_N@Z) already defined in libcpd.lib(iostream.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string,class std::allocator >::_Split(void)" (?_Split@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXXZ) alread y defined in libcpd.lib(iostream.obj) msvcprt.lib(MSVCP60.dll) : error LNK2005: "void __cdecl std::_Xran(void)" (?_Xran@std@@YAXXZ) already defined in libcpd.lib(string.obj) msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(class basic_string,class std::allocator >::basic_string,class std::allocator > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in libcpd.
lib(ios.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(char co
nst *,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z) already defined in libcpd.lib(iostream.obj) msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::erase(unsigned int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in libcpd.lib(iostream.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: char const * __thiscall std::basic_string,class std::allocator >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE PBDXZ) already defined in libcpd.lib(ios.obj) msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string,class std::allocator >::_Freeze(void)" (?_Freeze@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXXZ) alre
ady defined in libcpd.lib(iostream.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in scms.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(void)" (??0_Lockit@std@@QAE@XZ) already defined in scms.obj
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _memmove already defined in LIBCD.lib(memmove.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: "public: int __thiscall type_info::operator==(class type_info const &)const " (??8type_info@@QBEHABV0@@Z) already defined in LIBCD.lib(typinfo.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: "public: int __thiscall type_info::before(class type_info const &)const " (?before@type_info@@QBEHABV1@@Z) already defined in LIBCD.lib(typinfo.obj)
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/scms.exe : fatal error LNK1169: one or more multiply defined symbols found

scms.exe - 24 error(s), 1 warning(s)

------------- E-)mil "I feel like... I feel like... Like taking over the world!" - Day of the Tentacle

##### Share on other sites
Did you link with the multithreaded dll runtime?

C runtime I mean

##### Share on other sites
From working a bit with mysql++, I suggest you use the /NODEFAULTLIB:library switch on the libs it complains about. It doesn''t play well with STLPort either, so use MSVC++''s STL implementation.

##### Share on other sites
>>Maega
Whats the name of that dll?
>>CWizard
Where do I set that option?

##### Share on other sites
quote:
Original post by emileej
>>Maega
Whats the name of that dll?

Project->Settings->C/C++ (Category: Code Generation)->Use run-time library:

Set the "Multi-threaded DLL" for your release version, and "Debug Multi-threaded DLL" for your debug version.
quote:
>>CWizard
Where do I set that option?
Project->Settings->Link (Category: General)->Project Options:

Add to the end of the list "/NODEFAULTLIB:msvcprt.lib /NODEFAULTLIB:MSVCRT.lib"

##### Share on other sites
Now I get the following errors in stead:

--------------------Configuration: scms - Win32 Debug--------------------
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_s tring@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ)" imported LINK : warning LNK4049: locally defined symbol ""public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(c lass std::basic_string,class std::allocator > const &,unsigned int,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z)" imported
LINK : warning LNK4049: locally defined symbol ""public: static unsigned int const std::basic_string,class std::allocator >::npos" (?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB)" im ported LINK : warning LNK4049: locally defined symbol ""private: void __thiscall std::basic_string,class std::allocator >::_Tidy(bool)" (?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEX_N@Z)"
imported
LINK : warning LNK4049: locally defined symbol ""private: void __thiscall std::basic_string,class std::allocator >::_Copy(unsigned int)" (?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AA EXI@Z)" imported LINK : warning LNK4049: locally defined symbol ""void __cdecl std::_Xlen(void)" (?_Xlen@std@@YAXXZ)" imported LINK : warning LNK4049: locally defined symbol ""char const private: static char const * __cdecl std::basic_string,class std::allocator >::_Nullstr(void)''::2''::_C" (?_C@?1??_Nullstr@?$basic_string@DU?$char _traits@D@std@@V?$allocator@D@2@@std@@CAPBDXZ@4DB)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Winit::_Winit(void)" (??0_Winit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Winit::~_Winit(void)" (??1_Winit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""private: void __thiscall std::basic_string,class std::allocator >::_Eos(unsigned int)" (?_Eos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEX I@Z)" imported LINK : warning LNK4049: locally defined symbol ""private: bool __thiscall std::basic_string,class std::allocator >::_Grow(unsigned int,bool)" (?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@st
d@@AAE_NI_N@Z)" imported
LINK : warning LNK4049: locally defined symbol "_memmove" imported
LINK : warning LNK4049: locally defined symbol ""private: void __thiscall std::basic_string,class std::allocator >::_Split(void)" (?_Split@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXXZ)" imported LINK : warning LNK4049: locally defined symbol ""void __cdecl std::_Xran(void)" (?_Xran@std@@YAXXZ)" imported LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(class basic_stringar,struct std::char_traits,class std::allocator >::basic_string,class std::allocator > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)" imported
LINK : warning LNK4049: locally defined symbol ""public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(c
har const *,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z)" imported LINK : warning LNK4049: locally defined symbol ""public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::erase(un signed int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z)" imported
LINK : warning LNK4049: locally defined symbol ""public: char const * __thiscall std::basic_string,class std::allocator >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@st d@@QBEPBDXZ)" imported LINK : warning LNK4049: locally defined symbol ""private: void __thiscall std::basic_string,class std::allocator >::_Freeze(void)" (?_Freeze@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXXZ
)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Lockit::_Lockit(void)" (??0_Lockit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: int __thiscall type_info::operator==(class type_info const &)const " (??8type_info@@QBEHABV0@@Z)" imported
LINK : warning LNK4049: locally defined symbol ""public: int __thiscall type_info::before(class type_info const &)const " (?before@type_info@@QBEHABV1@@Z)" imported
mysql++.lib(connection.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string,class std::allocator >::basic_string,clas
s std::allocator >(class basic_string,class std::allocator >::allocator const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV?$allocator@D@1@@Z)
mysql++.lib(field_names.obj) : error LNK2001: unresolved external symbol __imp__tolower
mysql++.lib(field_names.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: char & __thiscall std::basic_string,class std::allocator >::operator[](unsigned int)" (__imp_??A?$basic_ string@DU?$char_traits@D@std@@V?\$allocator@D@2@@std@@QAEAADI@Z)
Debug/scms.exe : fatal error LNK1120: 3 unresolved externals

scms.exe - 4 error(s), 25 warning(s)

##### Share on other sites
Yeah, I know the hell...

A couple of suggestions/questions:
- Make sure you are using MSVC++'s STL, not eg. STLPort
- Have you updated MSVC++'s headers? Do you have the latest SDK and MSVC Service Pack (5 is the latest I think)?
- You will have to live with the warnings.
- If you just want simple MySQL access, consider using the plain C API or using another language than C/C++.

[edited by - CWizard on October 25, 2003 4:34:47 PM]

##### Share on other sites
There is a non-customised version of the api? Arrrrgggghhh! Ill get on it first thing in the mornin.

##### Share on other sites
quote:
Original post by emileej
There is a non-customised version of the api? Arrrrgggghhh! Ill get on it first thing in the mornin.
Yes, Mysql++ is just an wrapper over the libmysql library. The only nice thing about it under normal circumstances is the automatic type conversions.

##### Share on other sites
I downloaded the source distribution, added the path to the "sqlplusint" to my list of additional include directories and as the online example does I included .
When I try to compile I get this:

--------------------Configuration: scms - Win32 Debug--------------------
Compiling...
scms.cpp
c:\programmering\cpp\mysql\sqlplusint\defs(5) : fatal error C1083: Cannot open include file: ''mysql.h'': No such file or directory
Error executing cl.exe.

scms.exe - 1 error(s), 0 warning(s)

I have searched all the directories of the download and I cannot find mysql.h anywhere. Did I get the wrong download or am I perhaps doing something else wrong?

-------------
E-)mil
"I feel like... I feel like...
Like taking over the world!"
- Day of the Tentacle

##### Share on other sites
quote:
Original post by emileej
I downloaded the source distribution, added the path to the "sqlplusint" to my list of additional include directories and as the online example does I included .
??? Not a clue what you are doing now. Are you trying the plain C API? If so, there is no such thing as "sqlplus*" in it.
quote:
I have searched all the directories of the download and I cannot find mysql.h anywhere.
Just what have you downloaded? Go here: http://www.mysql.com/downloads/mysql-4.1.html, and download the Windows source package. I am *very* sure mysql.h is in there.

##### Share on other sites
That link you just posted talks of the server - this is where I have downloaded from:

##### Share on other sites
Ok, please state if you want to work with Mysql++ or the C API, because you indicated that you wanted to try the latter.

There sure is a mysql.h in the Mysql++ distribution (mysql++/mysql/include).

The C API is bundled with the server distribution available from the link I posted.

This is getting really messy. If you want more help, you need to recap what you are trying to do, what you have done and with what; I''m currently very confused about these things.

##### Share on other sites
Look - I just want to make my program connect to my database - period. I was told to use mysql connect aka mysql++, but that is not the case?

##### Share on other sites
quote:
Original post by emileej
Look - I just want to make my program connect to my database - period.
Then use either the standard C API, or use the Mysql++ API. Choose one
quote:
I was told to use mysql connect aka mysql++, but that is not the case?
"mysql connect aka mysql++"?

I don''t know what your problem is, but I assure you that it is quite possible to get Mysql++ working, although it is cranky on Windows. It will take some effort to make it work.

You''re not very easy to help. It is not possible for me to say "do that", and everything is solved. I''ve asked you several questions in order to understand your situiation, and suggested things to do, and you have not replied. Are you still working with Mysql++? Have you updated MSVC''s headers?

##### Share on other sites
Ok... STOP! REVERSE!

Well believe it or not, but I am actualy trying to explain to you that I have thrown everything on the floor and wanna know what you would reccomend. So far mysql++ has not worked and then you mention the other api so I just want to know which one you think would be best for me to use. Is the one faster than the other? Is it easier to implement? Which download should I get? Which of the apis will probably be most/earliest updated in the future?

I think I now have listed as many questions I can think of to give you a hint of where I am and what I want.

##### Share on other sites
I suggested that you might want to try the plain C API, and you said you would try it "the first thing in the morning", but then proceded showing errors that related to Mysql++.

I don''t know which API you should use. Mysql++ is simpler because it utilize C++ to ease type conversions etc. It is, however, significantly more complex and error prone, and is not perfectly ported to Windows yet. The standard C API requires more code, but yet rather easy.

The C API is more supported, as that is actively developed by MySQL AB parallell to the server software. Mysql++ is an abstraction layer above the C API, maintained by someone else.

I suggest you read the respective docs, and then decide which one fits your needs:
MySQL C API: http://www.mysql.com/doc/en/C.html
MySQL C++ API: http://www.mysql.com/documentation/mysql++/index.html

If you choose the C API, you shall download the server source distribution (for Windows, in your case) here: http://www.mysql.com/get/Downloads/MySQL-4.1/mysql-4.1.0-alpha-src.zip/from/pick.
Exactly how to set it up, I cannot remember, but it should be in the C API docs linked above or in the archive.

Either path, restart from scratch, and come back with any problems. Be sure to mention the exacts steps you have taken (tip: take notes), and I''m happy to help in any way I can.

##### Share on other sites
The C API does not look hard to inplement to me - very similar to filepointers and the way it is done in php (in my opinion). I''ll download it, give it a try and post my progress here.

##### Share on other sites
quote:
Original post by emileej
The C API does not look hard to inplement to me - very similar to filepointers and the way it is done in php (in my opinion).
Yes, the MySQL functions in PHP is a straight mapping to MySQL C API functions (except mysql_fetch_assoc() etc, of course).

##### Share on other sites
I have now implemented the api and it compiles and run without any problems. However: when I call mysql_real_connect the program stalls on me - no matter if the server is not started or if it is started, but I am attempting to connect to a non-existing database using a non-existing login (dont know how to create the login and if I try to create the database from a std mysql prompt I get an access denied msg). Is this normal or should mysql_real_connect just return an error (as I would expect it to do) if it cant connect to the server - this caused by the server not being online an/or the login being invalid?

##### Share on other sites
Hmm, it sounds odd. I''m not to sure though, as it has been a long time since I worked directly with the C API. Is it not possible to set some sort of timeout? It may some other problem as well.

I don''t have time to investigate now or teach about MySQL server administration, but will try to address both later. Do *bump* the thread if I forget.

##### Share on other sites
I''d worked with c API for mysql, you may try to link with "Ignore all default libraries" option, and my project having the following arguments within the "object/libraries module", you may take referenced with it :

"libmysql.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib winmm.lib libcmtd.lib libcpmtd.lib"

Hope it may useful with your case.

##### Share on other sites
I cant see why changing linker options will help a program that already compiles and does not crash.
As requested: *bump*

##### Share on other sites
Um, yeah...

Do you have a MySQL server running that you can access with a MySQL client? Make sure the server is alright before attempting to troubleshoot your program.

If you can connect with:

But not with the same info from your program, I''m stumped. I will need to test myself, but will only do that when you''ve verified the above.

##### Share on other sites
I am not exactly the master of mysql servers - Ill have a look around mysql.com tryin to find somekind of walkthru on setting up the mysql server...

"I feel like I could...like I could.... TAKE ON THE
WORLD!" - Day of the Tentacle