error: previous declaration of '****' was here

在使用C语言编写代码时,遇到与系统中已有的函数重名的情况导致编译错误。通过修改自定义函数的名称,成功解决了此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在写c代码后遇到这个错误,发现是我定义的getline()函数跟系统中已有的重名了,改名后,解决。



你的代码发生报错huaxi@ubuntu:~/c_projects/httpd/11_httpd_process/src$ make gcc -std=c99 -Wall -c main.c -o main.o gcc -std=c99 -Wall -c server.c -o server.o server.c:30:6: error: conflicting types for ‘recv_http_request’ void recv_http_request(int client_fd) ^ In file included from server.c:16:0: server.h:68:7: note: previous declaration of ‘recv_http_request’ was here void* recv_http_request(void* arg); ^ server.c: In function ‘recv_http_request’: server.c:43:24: warning: passing argument 2 of ‘parse_request’ makes pointer from integer without a cast [-Wint-conversion] parse_request(buf, client_fd); ^ In file included from server.c:16:0: server.h:71:5: note: expected ‘int *’ but argument is of type ‘int’ int parse_request(const char *message, int *conn_fd); ^ server.c: At top level: server.c:53:5: error: conflicting types for ‘parse_request’ int parse_request(const char *message, int conn_fd) ^ In file included from server.c:16:0: server.h:71:5: note: previous declaration of ‘parse_request’ was here int parse_request(const char *message, int *conn_fd); ^ server.c: In function ‘parse_request’: server.c:61:35: warning: passing argument 1 of ‘handle_get_request’ makes pointer from integer without a cast [-Wint-conversion] return handle_get_request(conn_fd, path); ^ In file included from server.c:16:0: server.h:74:5: note: expected ‘int *’ but argument is of type ‘int’ int handle_get_request(int *conn_fd, const char *path); ^ server.c:65:36: warning: passing argument 1 of ‘handle_post_request’ makes pointer from integer without a cast [-Wint-conversion] return handle_post_request(conn_fd, path, message); ^ In file included from server.c:16:0: server.h:77:5: note: expected ‘int *’ but argument is of type ‘int’ int handle_post_request(int *conn_fd, const char *path, const char *message); ^ server.c: At top level: server.c:77:5: error: conflicting types for ‘handle_get_request’ int handle_get_request(int conn_fd, const char *path) ^ In file included from server.c:16:0: server.h:74:5: note: previous declaration of ‘handle_get_request’ was here int handle_get_request(int *conn_fd, const char *path); ^ server.c:105:5: error: conflicting types for ‘handle_post_request’ int handle_post_request(int conn_fd, const char *path, const char *message) ^ In file included from server.c:16:0: server.h:77:5: note: previous declaration of ‘handle_post_request’ was here int handle_post_request(int *conn_fd, const char *path, const char *message); ^ makefile:16: recipe for target 'server.o' failed make: *** [server.o] Error 1
最新发布
08-12
根据你提供的错误信息,函数 `MainWindow::selectFile()` 的定义与其声明的返回类型不一致。 在你的 `mainwindow.h` 文件中,`MainWindow::selectFile()` 函数的声明的返回类型是 `int`,但是在 `mainwindow.cpp` 文件中的函数定义中,返回类型被修改为了 `bool`。 要修正这个问题,你需要确保函数的声明和定义的返回类型是一致的。根据你在 `selectFile()` 函数中的实现,返回类型应该是 `bool`。 将 `mainwindow.h` 文件中的函数声明修改为: ```cpp bool selectFile(); ``` 修正后的代码如下所示: **mainwindow.h** ```cpp #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: bool selectFile(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H ``` **mainwindow.cpp** ```cpp #include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { QPushButton *selectButton = new QPushButton("选择文件", this); connect(selectButton, &QPushButton::clicked, this, &MainWindow::selectFile); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(selectButton); QWidget *centralWidget = new QWidget(this); centralWidget->setLayout(layout); setCentralWidget(centralWidget); ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } bool MainWindow::selectFile() { QString dir = QFileDialog::getOpenFileName(this, "选择文件", "", "DWG Files (*.dwg)"); if (dir.isEmpty()) { qDebug() << "error: File import failure!"; return false; } else { // 进行导入操作 // ... return true; } } ``` 请确保在 `mainwindow.cpp` 文件中包含了 `#include "mainwindow.h"` 的代码行。这样可以确保函数的定义与声明是一致的。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值