mysql - 多重定义错误

标签 mysql sql c netbeans compiler-errors

我目前在 C 语言 SQL 库和链接过程方面遇到问题。

我没有#include任何.c 文件,并且对于引发错误的函数名称,我没有多个函数定义。我只包括:

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

根据互联网,我需要添加这一行来编译 SQL 库到编译行:

-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'

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

最佳答案

这是我的一个错误。

查看编译行,开关-o将打开文件,我指定的是main.c,它已经被打开,从而调用每个函数两次。

删除此行并将其更改为 -lmysqlclient 可以单独解决此问题(如果其他人使用其他地方推荐的完整命令)。

关于mysql - 多重定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31839504/

相关文章:

Mysql 进程 CPU 使用率超过 3500%,Qcache_lowmem_prunes 过高

sql - LEFT JOIN 子查询表参数是否被多次评估?

php - 仅在需要时自动连接到 PDO

php - sql从表中检索数据并使它们链接

MySQL:Curdate() 与 Now()

c++ - WIN32 API 项目中的 ReadDirectoryChangesW 错误?

mysql - 如何从逗号分隔的字符串中获取find_in_set的记录。[MySql]

mysql - MySQL:无法建立表格(错误编号:150)

c++ - 从 float 到 double 和从 double 到 float 的精度损失?

c - BIO_do_connect 导致段错误