#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    2
    Rep Power
    0

    C++->MySQL connection problem


    Hello...

    I'm trying to use borland C++ builder 6 to connect to a MySQL database. I allready downloaded the library files provided by mysql.com and I added them to my project via Project->AddToProject->libmysql.lib. I run into problems when I try to compile the following, very simple program:

    #include <windows.h>
    #include <mysql.h>

    void main() {
    MYSQL *conn;
    conn = mysql_init(NULL);
    }


    The compiler returns a linker error on "conn = mysql_init(NULL);"

    Does anyone know how to solve this?
    Last edited by kneet; September 22nd, 2003 at 03:40 AM.
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    >>Project->AddToProject->libmysql.lib

    I don't use Borland but did you link to the libraries or just add them? In MSVC you would have to add them in the linker not to the project.

    >>void main()

    If your complier does not tell you this is an error you need a new complier.

    As the app WILL return an int to the OS, better to define one.

    the standard says

    "The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

    code:int main(void) { /* ... */ }


    or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

    code:
    int main(int argc, char *argv[]) { /* ... */ }


    or equivalent; or in some other implementation-defined manner."
    Last edited by TechNoFear; September 22nd, 2003 at 04:24 AM.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    2
    Rep Power
    0
    "Have you included the libraries for the headers?"

    I dont think so, I only included libmysql.lib. Are there any other files that I should include?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    Adding the library to the project is not sufficient to cause it to link. You need to go into the project options, on the linker tab, and explicitly request that this module be linked. Any time you get an error message about an undefined reference, with any compiler, it is always a linking problem.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/

IMN logo majestic logo threadwatch logo seochat tools logo