MySQL and C++ lib error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: MySQL and C++ lib error

  1. #1
    Join Date
    Oct 2013
    Posts
    39

    MySQL and C++ lib error

    1. I downloaded win installer
    2. installed "FULL" version
    3. added programfiles/mysql/include dir
    4. added programfiles/mysql/lib dir
    5. linked "libmysql.lib"

    still getting

    Code:
    1>Source.obj : error LNK2001: unresolved external symbol _mysql_real_connect@32
    1>Source.obj : error LNK2001: unresolved external symbol _mysql_init@4
    looks like the lib is for 64 bit (I guess), but I downloaded 32 bit installer and im compiling it for 32 bit, any suggestions? im using vs2012

    code:

    Code:
    #include <my_global.h>
    #include <mysql.h>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    #define DB_HOST	"localhost"
    #define DB_USER	"root"
    #define DB_PASS	"root"
    #define DB_DB	"test"
    #define DB_PORT	3306
    
    int main()
    {
    	MYSQL *conn;
    	conn = mysql_init(NULL);
    	if(conn = mysql_real_connect(conn, DB_HOST, DB_USER, DB_PASS, DB_DB, DB_PORT, NULL, 0))
    	{
    	}
    	else
    		cout << "Cant connect to the DB" << endl;
    
    	system("pause");
    	return 0;
    }
    I have 64 bit OS, vs2012 express, compiling for 32 bit, I downloaded 32 bit mysql installer

  2. #2
    Join Date
    Apr 1999
    Posts
    27,424

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    1. I downloaded win installer
    2. installed "FULL" version
    3. added programfiles/mysql/include dir
    4. added programfiles/mysql/lib dir
    5. linked "libmysql.lib"
    You list all of these things you did, but no one knows if you did any of these correctly.
    looks like the lib is for 64 bit
    Nothing in that error message suggests that the library is 64-bit.
    5. linked "libmysql.lib"
    Tell us what you mean by "linked". There are multiple ways to specify a library to link to in Visual Studio.

    Also, showing us C++ source code isn't going to give information on what caused a linker error.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by Paul McKenzie View Post
    You list all of these things you did, but no one knows if you did any of these correctly.
    Nothing in that error message suggests that the library is 64-bit.
    Tell us what you mean by "linked". There are multiple ways to specify a library to link to in Visual Studio.

    Regards,

    Paul McKenzie
    1. well, I downloaded win installer from mysql website, and I dont really think this can be done wrong
    2. I installed full version by selecting "full" on the start of installation, it did install connectors and everything it could
    3. and 4. im not using external libs for the first time, I also did this correctly
    5. i linked it under input

    I had same error with lua lib that I accidentaly built for 64 bit, everything was linked but I still got the error telling me that I dont have lib included in my project

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    ...
    5. i linked it under input
    What could it mean?
    Victor Nijegorodov

  5. #5
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by VictorN View Post
    What could it mean?
    uhm, that it is linked under input section of linker in properties?

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    uhm, that it is linked under input section of linker in properties?
    Do you mean you added the lib pathname in the Additional Dependencies list?

    And BTW, are there different .lib versions for debug/release builds?
    Victor Nijegorodov

  7. #7
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by VictorN View Post
    Do you mean you added the lib pathname in the Additional Dependencies list?

    And BTW, are there different .lib versions for debug/release builds?
    yes, the debug version is in debug folder within lib folder

    edit: just to make this clear, in lib folder are 2 libs, libmysql and mysqlclient, both of them are linked to my project, there's debug folder with ONLY mysqlclient, which im not using at all (only the first 2 in lib folder), also there's libmysql but DLL, not a lib, maybe I need to include all libs AND dll? if so, how do I include dll? i never worked with those
    Last edited by DaigonoYouso; October 29th, 2013 at 02:22 PM.

  8. #8
    Join Date
    Apr 1999
    Posts
    27,424

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    yes, the debug version is in debug folder within lib folder

    edit: just to make this clear, in lib folder are 2 libs, libmysql and mysqlclient, both of them are linked to my project,
    That doesn't make it clear in terms of what your exact steps are in Visual Studio as to how you're doing this "linking".

    In the Properties for the project:

    1) Linker -> General -> Additional Library Directories... Did you specify the directory where the .lib file(s) are found?

    2) Linker -> Input -> Additional Dependencies... If you did step 1), in this step, did you specify the name of the library, including the .lib extension (i.e. mylib.lib)?
    there's debug folder with ONLY mysqlclient, which im not using at all (only the first 2 in lib folder), also there's libmysql but DLL, not a lib, maybe I need to include all libs AND dll? if so, how do I include dll? i never worked with those
    Just because you have folders on your machine means nothing if you don't follow the steps required for the Visual Studio IDE and the linker to find these library files.

    As to the DLL, the DLL is not used in the build process. The DLL is relevant only when you run your program.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 29th, 2013 at 03:51 PM.

  9. #9
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by Paul McKenzie View Post
    That doesn't make it clear in terms of what your exact steps are in Visual Studio as to how you're doing this "linking".

    In the Properties for the project:

    1) Linker -> General -> Additional Library Directories... Did you specify the directory where the .lib file(s) are found?

    2) Linker -> Input -> Additional Dependencies... If you did step 1), in this step, did you specify the name of the library, including the .lib extension (i.e. mylib.lib)?
    Just because you have folders on your machine means nothing if you don't follow the steps required for the Visual Studio IDE and the linker to find these library files.

    As to the DLL, the DLL is not used in the build process. The DLL is relevant only when you run your program.

    Regards,

    Paul McKenzie
    how I said, this is not first time I'm using libraries, so yes

    3. added programfiles/mysql/include dir
    4. added programfiles/mysql/lib dir
    5. linked "libmysql.lib"

  10. #10
    Join Date
    Apr 1999
    Posts
    27,424

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    how I said, this is not first time I'm using libraries, so yes
    You're doing something wrong, since MySQL is used by thousands of C++ coders without issue.

    Unless we see for ourselves that

    1) those are the correct directories (this should be a full path name), and
    2) you are following the steps that I outlined in detail (the actual items in the Properties),

    then there is nothing else we can tell you. Adding libraries to be linked is very simple and should be no issue if the directories specified are correct, the name of the libraries are correct, and you're specifying these in the Visual Studio IDE correctly.

    Regards,

    Paul McKenzie

  11. #11
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by Paul McKenzie View Post
    You're doing something wrong, since MySQL is used by thousands of C++ coders without issue.

    Unless we see for ourselves that

    1) those are the correct directories (this should be a full path name), and
    2) you are following the steps that I outlined in detail (the actual items in the Properties),

    then there is nothing else we can tell you. Adding libraries to be linked is very simple and should be no issue if the directories specified are correct, the name of the libraries are correct, and you're specifying these in the Visual Studio IDE correctly.

    Regards,

    Paul McKenzie
    additional something directories in linker > general = C:\Program Files\MySQL\MySQL Server 5.6\lib;%(AdditionalLibraryDirectories)
    additional dependencies in linker > input = mysqlclient.lib;libmysql.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

    the folder path is 100% correct since I selected it within the interface (when u're adding it to that line and selecting a folder)

  12. #12
    Join Date
    Apr 1999
    Posts
    27,424

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    additional something directories in linker > general = C:\Program Files\MySQL\MySQL Server 5.6\lib;%(AdditionalLibraryDirectories)
    additional dependencies in linker > input = mysqlclient.lib;libmysql.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

    the folder path is 100% correct since I selected it within the interface (when u're adding it to that line and selecting a folder)
    Do not add mysqlclient.lib.

    The functions you're calling are within the libmysql.dll module, therefore the library that you should be linking to is libmysql.lib. Don't add libraries that you have no idea what they are for or what functions they provide. In all likelihood, specifying that mysqlclient.lib library (which looks like a static library to me) messes up the linker in finding the subsequent functions in libmysql.lib.

    I took this simple program, and was able to build it with no issues with Visual Studio 2008:
    Code:
    #include <my_global.h>
    #include <mysql.h>
    
    int main()
    {
        mysql_init(NULL);
    }
    I specified the lib directory in the Additional Directories, and specified libmysql.lib in the Linker -> Input section. I did nothing else except start the build, and it built successfully the first time I tried it.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 29th, 2013 at 10:36 PM.

  13. #13
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by Paul McKenzie View Post
    Do not add mysqlclient.lib.

    The functions you're calling are within the libmysql.dll module, therefore the library that you should be linking to is libmysql.lib. Don't add libraries that you have no idea what they are for or what functions they provide. In all likelihood, specifying that mysqlclient.lib library (which looks like a static library to me) messes up the linker in finding the subsequent functions in libmysql.lib.

    I took this simple program, and was able to build it with no issues with Visual Studio 2008:
    Code:
    #include <my_global.h>
    #include <mysql.h>
    
    int main()
    {
        mysql_init(NULL);
    }
    I specified the lib directory in the Additional Directories, and specified libmysql.lib in the Linker -> Input section. I did nothing else except start the build, and it built successfully the first time I tried it.

    Regards,

    Paul McKenzie
    I actually had ONLY libmysql.lib there - if you look at original post, I never mentioned mysqlclient - I just added it after I was looking for debug folder and noticed there's mysqlclient in there, so no, it's not working without mysqlclient and libmysql only neither

    edit: I ALSO tried to make NEW project, empty project, added cpp file, copypasted my code, pointed to include dir, pointed to lib dir, added libmysql.lib, same error again, release build
    Last edited by DaigonoYouso; October 30th, 2013 at 09:21 AM.

  14. #14
    Join Date
    Apr 1999
    Posts
    27,424

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    I actually had ONLY libmysql.lib there - if you look at original post, I never mentioned mysqlclient - I just added it after I was looking for debug folder and noticed there's mysqlclient in there, so no, it's not working without mysqlclient and libmysql only neither

    edit: I ALSO tried to make NEW project, empty project, added cpp file, copypasted my code, pointed to include dir, pointed to lib dir, added libmysql.lib, same error again, release build
    I tried the same thing, but this time with VS 2012. Again, no problems -- worked the first time I tried it for Debug and Release build. This time, I took your code, and had no problems building.

    The libmysql.lib file is dated Sept 10, 2013. The file size is 27,538 bytes. Is this the file you're linking with?

    Regards,

    Paul McKenzie

  15. #15
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by Paul McKenzie View Post
    I tried the same thing, but this time with VS 2012. Again, no problems -- worked the first time I tried it for Debug and Release build. This time, I took your code, and had no problems building.

    The libmysql.lib file is dated Sept 10, 2013. The file size is 27,538 bytes. Is this the file you're linking with?

    Regards,

    Paul McKenzie
    ‎10. ‎september ‎2013, ‏‎9:59:58
    25 852 bytes
    28 672 bytes on disk

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center