使用现有 C 程序编写 Qt 程序时找不到符号

Symbol(s) not found while writing a Qt program using existing C program

我用 C 写了一个 ftp 客户端(使用 GNU make),现在想用 Qt 为它写一个 GUI。

构建时出现错误:

error: symbol(s) not found for architecture x86_64
linker command failed with exit code 1 (use -v to see invocation)
Undefined symbols for architecture x86_64:
  "showHelpMsg()", referenced from:
  _main in main.o

我的 main.cpp 看起来像这样:

include "client.h" 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ftpClient w;
    w.show();
    showHelpMsg();
    return a.exec();
}

client.h:

#include"common.h"
#include"handler.h"
#include"util.h"    //These headers works fine while using gnu make    
void showHelpMsg();

client.c:

include "client.h" 
void showHelpMsg()
{
    //....
}

还有我的project.pro:(由Qt自动生成)

SOURCES += main.cpp\
    ftpclient.cpp \
client.c \
common.c \
handler.c \
util.c

HEADERS  += ftpclient.h \
client.h \
common.h \
handler.h \
util.h

作为参考,这是我以前的 makefile:

objects = client.o handler.o util.o common.o

server : $(objects)
cc -Wall -o client $(objects)

.PHONY : clean
clean :
    rm client $(objects)

尝试将 client.h 更改为:

#ifdef __cplusplus
extern "C" {
#endif
#include"common.h"
#include"handler.h"
#include"util.h"
void showHelpMsg();
#ifdef __cplusplus
}
#endif

问题可能是 C++ 编译器 showHelpMsg 是一个名称错乱的 C++ 函数,而 C 编译器只生成一个名称正常的普通 C 函数。