我目前在SQL Library for C和链接过程中遇到问题。
我没有#include
处理任何.c文件,并且对于引发错误的函数名,我没有多个函数定义。我只包括:
#include <stdio.h>
#include <stdlib.h>
#include <gps.h>
#include <mysql/mysql.h>
根据互联网,我需要添加这一行来将SQL库编译到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'
所以我想说我需要那里的编译行,这只是弄清楚为什么它会给我多定义错误
这是我的一个错误。
在编译行中,开关-o
将打开文件,我指定该文件为main.c
,它已经被打开,因此调用每个函数两次。
如果其他人按照其他地方的建议使用完整命令,删除此行并将其单独更改为-lmysqlclient
可以解决此问题。