CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Join Date
    Feb 2009
    Posts
    201

    MySQL Connector C++ "linker" error.

    Hello guys. Been working this for some time now, but I'm getting more and more confused.

    When I use the MingW compiler on Windows, to compile my program:
    Code:
    #include <iostream>
    
    #include <mysql_connection.h>
    #include <mysql_driver.h>
    
    using namespace std;
    
    int main(){
    sql::mysql::MySQL_Driver *driver;
    sql::Connection	*con;
    
    driver = sql::mysql::get_mysql_driver_instance();
    
    con = driver->connect("tcp://127.0.0.1:3306", "root", " ");
    cout << "connection OK";
    cin.get();
    
    delete con;
    
    }
    Using the following command:
    Code:
    g++ hw.cpp -o hw.exe
    I get the following error:
    Code:
    C:\Users\kk\AppData\Local\Temp\ccRrhIs3.o:hw.cpp:(.text+0x7): undefined referen
    ce to `_imp___ZN3sql5mysql19get_driver_instanceEv'
    collect2: ld returned 1 exit status
    I did a few attempts on how to link a libary, but it didn't work.

    - realchamp.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: MySQL Connector C++ "linker" error.

    If I remember correctly you use -l to link additional libraries (the letter l as in link that is, not I)
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Feb 2009
    Posts
    201

    Re: MySQL Connector C++ "linker" error.

    Quote Originally Posted by S_M_A View Post
    If I remember correctly you use -l to link additional libraries (the letter l as in link that is, not I)
    I did a link to mysqlcppconn.lib which were located insite the Connector C++ package, but nothing really happened.

    -l mysqlcppconn.lib

  4. #4
    Join Date
    May 2008
    Posts
    38

    Re: MySQL Connector C++ "linker" error.

    it should be -lmysqlcppconn without the space. It might not be able to find the lib to link, you could try specifying the libs location by adding -L/c/path/to/lib.

  5. #5
    Join Date
    Feb 2009
    Posts
    201

    Re: MySQL Connector C++ "linker" error.

    Quote Originally Posted by Cheezewizz View Post
    it should be -lmysqlcppconn without the space. It might not be able to find the lib to link, you could try specifying the libs location by adding -L/c/path/to/lib.
    Thanks for your reply.

    Unfortunately it still dont work.

    This is were it wants the mysqlcppconn.lib in:
    Code:
    c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/
    If I open my explorer and enter that path, it gives me
    Code:
    C:\MinGW\mingw32\bin
    So I dropped the mysqlcppconn.lib in there and then compiled once agian and..
    Code:
    C:\MinGW\bin>g++ hw.cpp -lmysqlcppconn -o hw.exe
    Info: l&#248;ser std::cout  ved at l&#230;nke til __imp___ZSt4cout (automatisk import)
    Info: l&#248;ser std::cin  ved at l&#230;nke til __imp___ZSt3cin (automatisk import)
    c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
    uto-importing has been activated without --enable-auto-import specified on the c
    ommand line.
    This should work unless it involves constant data structures referencing symbols
     from auto-imported DLLs.
    C:\Users\kk\AppData\Local\Temp\ccldRR4I.o:hw.cpp:(.text+0x7): undefined referen
    ce to `_imp___ZN3sql5mysql19get_driver_instanceEv'
    collect2: ld returned 1 exit status
    And I've even put the mysqlcppconn.lib into multiple folders, to insure that it's in place!
    Last edited by realchamp; October 18th, 2010 at 08:19 AM.

  6. #6
    Join Date
    May 2008
    Posts
    38

    Re: MySQL Connector C++ "linker" error.

    where was the lib for mysqlconnector initially installed to? you don't have to move it you can just specify it's location on the command line. -l is for the addtional library names and then -L is for additional library locations...

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: MySQL Connector C++ "linker" error.

    The -l flag is a bit strange. If you say "-lmylibrary", then you need to have libmylibrary.lib available. Note, not only is the extension ".lib" not included in the -l statement, but also the prefix "lib". At least, that's how gcc works in Linux (with .a or .so rather than .lib, though); I'm assuming it's the same for MinGW.

    If the name of the library you are trying to link does not start with "lib", then you cannot use the -l flag. Instead, simply put the library name on the command line after the names of your source files.

  8. #8
    Join Date
    May 2008
    Posts
    38

    Re: MySQL Connector C++ "linker" error.

    that makes sense but then does it not normally complain about not being able to find a library named blah if you're trying to link it against the wrong name? Not only that but i've been using Mingw gcc port for a while and have used it like -ldxd9 -lwininet etc. and they've always been OK. if you google get_driver_instance, the first result points to another forum with others having similar problems and the solution, i think, was the location of the lib file...
    Last edited by Cheezewizz; October 18th, 2010 at 09:48 AM.

  9. #9
    Join Date
    Feb 2009
    Posts
    201

    Re: MySQL Connector C++ "linker" error.

    Quote Originally Posted by Cheezewizz View Post
    where was the lib for mysqlconnector initially installed to? you don't have to move it you can just specify it's location on the command line. -l is for the addtional library names and then -L is for additional library locations...
    I think it's installed here: C:\Program Files (x86)\MySQL\Connector ODBC 5.1
    Or here: C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt

    The opt folder contains the mysqlcppconn.lib

    Quote Originally Posted by Lindley View Post
    The -l flag is a bit strange. If you say "-lmylibrary", then you need to have libmylibrary.lib available. Note, not only is the extension ".lib" not included in the -l statement, but also the prefix "lib". At least, that's how gcc works in Linux (with .a or .so rather than .lib, though); I'm assuming it's the same for MinGW.

    If the name of the library you are trying to link does not start with "lib", then you cannot use the -l flag. Instead, simply put the library name on the command line after the names of your source files.
    Can I just put that prefix on the file name? Also what do you mean with put the library on the command line?

    Like:
    Code:
    g++ hw.cpp -o hw.exe mysqlcppconn.lib
    Quote Originally Posted by Cheezewizz View Post
    that makes sense but then does it not normally conplain about not being able to find a library named blah if you're trying to link it against the wrong name? Not only that but i've been using Mingw gcc port for a while and have used it like -ldxd9 -lwininet etc. and they've always been OK. if you google get_driver_instance, the first result points to another forum with others having similar problems and the solution, i think, was the location of the lib file...
    I will try to google that, thanks! Was it this that you refered to?:: http://forums.mysql.com/read.php?167...601#msg-299601
    Last edited by realchamp; October 18th, 2010 at 09:50 AM.

  10. #10
    Join Date
    May 2008
    Posts
    38

    Re: MySQL Connector C++ "linker" error.

    that's the one yep. I've just downloaded the lib and tried your code and end up with exactly the same issue. So I was wrong and it's obviously not a problem with not being able to locate the lib. It does however say somewhere on their site that "Binary incompatibilities can also occur if you are using a different C Run-Time Libraries (CRT) than we used for building" and i believe the prebuilt binaries were done with visual studio so maybe that's messing it up? could try grabbing the source and building your own binaries with mingw...

    edit: er yeah i just tried one of the older binaries that they compiled with VS2005, and using VS2005 your test code compiles and links fine with it, so unfortunately it must be an issue with Mingw...
    Last edited by Cheezewizz; October 18th, 2010 at 01:33 PM.

  11. #11
    Join Date
    Feb 2009
    Posts
    201

    Re: MySQL Connector C++ "linker" error.

    Quote Originally Posted by Cheezewizz View Post
    that's the one yep. I've just downloaded the lib and tried your code and end up with exactly the same issue. So I was wrong and it's obviously not a problem with not being able to locate the lib. It does however say somewhere on their site that "Binary incompatibilities can also occur if you are using a different C Run-Time Libraries (CRT) than we used for building" and i believe the prebuilt binaries were done with visual studio so maybe that's messing it up? could try grabbing the source and building your own binaries with mingw...

    edit: er yeah i just tried one of the older binaries that they compiled with VS2005, and using VS2005 your test code compiles and links fine with it, so unfortunately it must be an issue with Mingw...
    Thanks for your reply. That just cleared up alot for me.

    Should it work if I compiled it on Linux?

  12. #12
    Join Date
    May 2008
    Posts
    38

    Re: MySQL Connector C++ "linker" error.

    i don't see why not as long as you grab the right source for whatever distro you're using

  13. #13
    Join Date
    Feb 2009
    Posts
    201

    Re: MySQL Connector C++ "linker" error.

    Quote Originally Posted by Cheezewizz View Post
    i don't see why not as long as you grab the right source for whatever distro you're using
    I will go try compiling it on Linux. Thanks

  14. #14
    Join Date
    Feb 2009
    Posts
    201

    Re: MySQL Connector C++ "linker" error.

    Linux attempt on Debian 5.0.

    Code:
    g++ hw.cpp -Llibmysqlcppconn.so.1.0.5 -o hw
    /tmp/ccOXABZ5.o: In function `main':
    hw.cpp:(.text+0x5e): undefined reference to `sql::mysql::get_mysql_driver_instance()'
    collect2: ld returned 1 exit status
    root@vs170144:~#
    I'm seriously on the egde to give up.

  15. #15
    Join Date
    May 2008
    Posts
    38

    Re: MySQL Connector C++ "linker" error.

    Not having much luck with this are ya? thought about just using the C API directly instead? :P well the first thing to try (again) would be to make sure that it's definitely checking the right path for the shared library. check out this guy's post in another forum http://forums.mysql.com/read.php?167...772#msg-282772 and see if that works out...

    Also will it make any difference that Debian isn't on this list? I used to occasionally struggle with getting stuff to work on there til I gave up and moved to Ubuntu...

    Code:
    Supported Platforms 
        Linux
    
        * FC4 (x86)
        * RHEL 3 (ia64, x86, x86_64)!
        * RHEL 4 (ia64, x86, x86_64)o
        * RHEL 5 (ia64*, x86, x86_64)o
        * SLES 9 (ia64, x86, x86_64)o
        * SLES 10 (ia64, x86_64)o
        * SuSE 11.0, (x86_64)
        * Ubuntu 8.04 (x86)
        * Ubuntu 8.10 (x86_64)
    Last edited by Cheezewizz; October 19th, 2010 at 02:44 AM.

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
  •  





Click Here to Expand Forum to Full Width

Featured