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

Thread: MySQL and C++ lib error

Hybrid View

  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,418

    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 offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,018

    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 offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,018

    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
    Apr 1999
    Posts
    27,418

    Re: MySQL and C++ lib error

    Here is the lib file that was installed on my machine.

    libsql.zip

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by Paul McKenzie View Post
    Here is the lib file that was installed on my machine.

    libsql.zip

    Regards,

    Paul McKenzie
    works, why?

  9. #9
    Join Date
    Apr 1999
    Posts
    27,418

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    works, why?
    It works because it does. This is what is installed by the MySql installer -- it has to work, else the people at MySql needs to go back and provide a workable lib file.

    Regards,

    Paul McKenzie

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,018

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    works, why?
    It is wrong question! It "works" just because this lib file was created to "work"!
    The question you have to ask is: why does your lib file not work? I guess it is because "your" lib is NOT for 32-bit debug version or the file was corrupted.
    Victor Nijegorodov

  11. #11
    Join Date
    Oct 2013
    Posts
    39

    Re: MySQL and C++ lib error

    Quote Originally Posted by VictorN View Post
    It is wrong question! It "works" just because this lib file was created to "work"!
    The question you have to ask is: why does your lib file not work? I guess it is because "your" lib is NOT for 32-bit debug version or the file was corrupted.
    32bit release version*

    yeah, I said that it is probvably for a 64 bit, but I have no idea why, I downloaded installer for 32 bit

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

    Re: MySQL and C++ lib error

    Quote Originally Posted by DaigonoYouso View Post
    32bit release version*

    yeah, I said that it is probvably for a 64 bit, but I have no idea why, I downloaded installer for 32 bit
    Well, I downloaded the installer last night, and didn't do anything beyond that except make the installer run.

    Make sure that you are pointing to the proper directory. Maybe the installer can detect what system you're running, and install both 32 and 64 bit versions. If that is the case, then usually 32-bit versions are installed in "Program Files (x86)" and not "Program Files". I am running a 32-bit only system, and installing caused no issues.

    Regards,

    Paul McKenzie

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