gcc wont compile and run MySQL C libraries

后端 未结 7 581
不知归路
不知归路 2021-02-03 14:20
#include 
#include 

int main(int argc, char **argv)
{
  printf(\"MySQL client version: %s\\n\", mysql_get_client_info());
}

相关标签:
7条回答
  • 2021-02-03 14:37

    You are not linking to the libraries. Use: gcc -llibrarygoeshere -o mysql-test MySQL-Test.c See here for more information about linking with gcc.

    0 讨论(0)
  • 2021-02-03 14:42

    Maybe late but worked for me
    If you are using an IDE you should link the library to your project.
    I am using CodeBlocks on ubuntu 12.4 64x. For linking the library, you should go to Project -> Build options -> linker settings and add the library. this is my lib path : /usr/lib/x86_64-linux-gnu/libmysqlclient.so

    Hope be useful...

    0 讨论(0)
  • 2021-02-03 14:43

    For uses of Netbeans on Linux

    Open you make file (MakeFile) and add the following lines

    # These are the flags that gcc requires in order to link correctly against our installed 
    # client packages
    MYSQL_LIBS := $(shell mysql_config --libs)
    

    right below the Environment block.

    Then right click on your project node , select Properties, Build and add $(MYSQL_LIBS) to the Additional options parameter.

    0 讨论(0)
  • 2021-02-03 14:46

    You forgot to link against the MySQL library. Try adding -lmysql to your compilation line.

    See http://www.adp-gmbh.ch/cpp/gcc/create_lib.html for more information.

    0 讨论(0)
  • 2021-02-03 14:47

    You need gcc -o mysql-test MySQL-Test.c -L/usr/local/mysql/lib -lmysqlclient -lz

    Replace -L/usr/local/mysql/lib with wherever you client library is (if it isn't already in your libpath)

    See the MySql instructions for building clients.

    0 讨论(0)
  • 2021-02-03 14:50

    MySQL comes with a special script called mysql_config. It provides you with useful information for compiling your MySQL client and connecting it to MySQL database server.

    Pass --libs option - Libraries and options required to link with the MySQL client library.

    $ mysql_config --libs
    

    Typical Output:

    -L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto
    

    Now you can add this to your compile/link line:

    gcc -o mysql-test MySQL-Test.c $(mysql_config --libs)
    
    0 讨论(0)
提交回复
热议问题