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

问题描述 投票:0回答:1

我在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)
c++ c qt gnu-make qmake
1个回答
0
投票

尝试将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函数。

© www.soinside.com 2019 - 2024. All rights reserved.