多重定义错误

时间:2015-08-05 17:52:53

标签: mysql sql c netbeans compiler-errors

我目前在使用SQL库C和链接过程时遇到了问题。

我不是#include任何.c文件,并且我没有多个函数名称来引发错误。我只包括:

#include <stdio.h>
#include <stdlib.h>
#include <gps.h>
#include <mysql/mysql.h>

根据互联网,我需要添加这一行来编译SQL Librarys到Compilation Line

-o gpsComplete main.c -L/usr/include/mysql/ -lmysqlclient -lz

这是我构建之后在输出中显示的内容:

/tmp/ccLqcQ6E.o: In function `main':
main.c:(.text+0x0): multiple definition of `main'
build/Debug/GNU-Linux-x86/main.o:/root/.netbeans/remote/192.168.1.132/ian-pc-Windows-x86_64/C/Users/Ian/Documents/NetBeansProjects/gpsComplete/main.c:17: first defined here
/tmp/ccLqcQ6E.o: In function `connUploadDataToServerFromMain':

main.c:(.text+0x164): multiple definition of `connUploadDataToServerFromMain'
build/Debug/GNU-Linux-x86/main.o:/root/.netbeans/remote/192.168.1.132/ian-pc-Windows-x86_64/C/Users/Ian/Documents/NetBeansProjects/gpsComplete/main.c:65: first defined here

/tmp/ccLqcQ6E.o: In function `uploadToServer':
main.c:(.text+0x194): multiple definition of `uploadToServer'
build/Debug/GNU-Linux-x86/main.o:/root/.netbeans/remote/192.168.1.132/ian-pc-Windows-x86_64/C/Users/Ian/Documents/NetBeansProjects/gpsComplete/main.c:76: first defined here
collect2: ld returned 1 exit status

但是,当我没有行-o gpsComplete main.c -L/usr/include/mysql/ -lmysqlclient -lz时,它的构建将失败,说sql命令是未定义的:

/root/.netbeans/remote/192.168.1.132/ian-pc-Windows-x86_64/C/Users/Ian/Documents/NetBeansProjects/gpsComplete/main.c:91: undefined reference to `mysql_init'
/root/.netbeans/remote/192.168.1.132/ian-pc-Windows-x86_64/C/Users/Ian/Documents/NetBeansProjects/gpsComplete/main.c:94: undefined reference to `mysql_real_connect'
/root/.netbeans/remote/192.168.1.132/ian-pc-Windows-x86_64/C/Users/Ian/Documents/NetBeansProjects/gpsComplete/main.c:96: undefined reference to `mysql_error'

所以我会说我需要那里的编译行,它只是一个弄清楚为什么它给我多重定义错误

1 个答案:

答案 0 :(得分:0)

这是我的错误。

查看编译行,交换机-o将打开我指定的文件main.c,该文件已经打开,因此调用每个函数两次。

如果其他人使用其他地方建议的完整命令,则删除此行并单独更改-lmysqlclient就可以解决此问题。