奇怪的GCC

今天被一个mysql的问题弄了很奇怪,很明显,我的代码和Makefile没有任何问题,但是就是出现undefined reference to `mysql_init'的编译错误。
[lijunlia@cadev08 Extractors]$gcc `mysql_config --libs` t.c -o t
/tmp/ccMQ3Odc.o(.text+0x22): In function `main':
: undefined reference to `mysql_init'
/tmp/ccMQ3Odc.o(.text+0x4d): In function `main':
: undefined reference to `mysql_real_connect'
/tmp/ccMQ3Odc.o(.text+0x62): In function `main':
: undefined reference to `mysql_error'
collect2: ld returned 1 exit status
测试代码如下:
[lijunlia@cadev08 Extractors]$more t.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>

int main(int argc, char *argv[])
{
    MYSQL *conn;
    conn = mysql_init(NULL);
    if (!mysql_real_connect(conn, "localhost", "root", "", "bcm", 3306, NULL, 0))
    {
        printf("%s\n", mysql_error(conn));
        return -1;
    } else {
        printf("Connect Successfull!!\n");
    }
    mysql_close(conn);
    return 0;
}
换了一种方式:
[lijunlia@cadev08 Extractors]$gcc t.c `mysql_config --libs` -o t
[lijunlia@cadev08 Extractors]$gcc --version
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-9)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
运行测试文件:
[lijunlia@cadev08 Extractors]$./t
Connect Successfull!!
开始还一直以为是mysql库安装问题或者lib等问题,后来才意识的这个gcc问题。
另外,gcc3.2.3版本还有两个Bug,不支持base_string的一些属性以及c_str()函数的Bug,希望用到此版本的人注意哟!

Monthly Archives

Pages

Powered by Movable Type 7.7.2

About this Entry

This page contains a single entry by Cnangel published on November 24, 2008 4:53 PM.

关于经济危机 was the previous entry in this blog.

怎么安装Fedora10源 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.