【问题标题】:Symbol(s) not found while writing a Qt program using existing C program使用现有 C 程序编写 Qt 程序时找不到符号
【发布时间】:2018-04-15 17:03:56
【问题描述】:

我用 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】:

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

    【讨论】:

      猜你喜欢
      • 2014-10-23
      • 2013-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-25
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多