qt中未定义的引用

undefined reference in qt

本文关键字:引用 未定义 qt      更新时间:2023-10-16

In qt MainWindow::on_pushButton_clicked();

如果我想从另一个。c文件中调用函数,我已经添加了。c和。h文件,并#include它。

但是编译仍然显示失败,它显示:

 undefined reference to `Load_bmp(char const*, int*, int*, int*)

我该如何解决这个问题,谢谢。这是我的代码:https://drive.google.com/file/d/0B6RzrpHF18PGd3UtWmEzdTQyLUk/view?usp=sharing

qt是c++,所以使用cpp扩展文件。

对于您的情况,最快的方法是将您的bmp.c文件重命名为bmp.cpp,它将神奇地构建。

必须使用的另一种方法是更改接口以指定c项目文件的c链接,因此:
#ifndef _BMP_H_
#define _BMP_H_
#ifdef __cplusplus
    extern "C" {
    #endif
        unsigned char* Load_bmp(const char *fname_s, int *Height, int *Width, int *Depth);
        int Save_bmp_8bit(const char *fname_t, unsigned char *image_s, int height, int width);
        int Save_bmp_24bit(const char *fname_t, unsigned char *image_s, int height, int width);
        unsigned char * T8bitTo24bit(unsigned char *ima, size_t Height, size_t Width);
        unsigned char * T24bitTo8bit(unsigned char *ima, size_t Height, size_t Width);
    #ifdef __cplusplus
    }
    #endif
#endif