奇怪的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,希望用到此版本的人注意哟!

Categories

| | 评论(0)

发表评论

May 2010

            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

关于此日记

此日记由 Cnangel 发表于 November 24, 2008 4:53 PM

此Blog上的上一篇日记关于经济危机

此Blog上的下一篇日记怎么安装Fedora10源

首页归档页可以看到最新的日记和所有日记。

归档

Powered by Movable Type 5.02