【问题标题】:Trouble on Qt Creator on macOS - ld: library not found for -lQt5Widgets_debugmacOS 上 Qt Creator 的问题 - ld:找不到 -lQt5Widgets_debug 的库
【发布时间】:2018-06-25 07:18:40
【问题描述】:

我基于Qt5.10.0安装了Qt Creator 4.5.0,做了一个简单的项目。

#include "widget.h"
#include <QApplication>
#include <QTextEdit>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextEdit textEdit;
    textEdit.show();

    return a.exec();
}

我构建了这个项目并收到了这条消息。

ld: library not found for -lQt5Widgets_debug
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我使用 macOS10.13.2、Xcode9.2。我该怎么办? 我必须为此安装一些库吗?

.pro 在下面。

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Test1
TEMPLATE = app

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
        main.cpp \
        widget.cpp

HEADERS += \
        widget.h

FORMS += \
        widget.ui

widget.h 在下面。

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private:
    Ui::Widget *ui;
};

#endif // WIDGET_H

widget.cpp 在下面。

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

感谢您观看此视频。

【问题讨论】:

  • 展示你的 .pro.
  • 感谢您观看这个问题。我在上面添加了.pro。
  • 在 main.cpp 中你包括 #include "widget.h" ... 什么是 widget.h ??
  • 我添加了 widget.h 和 widget.cpp。请观看。
  • 你是如何安装 Qt5 的?

标签: c++ xcode macos qt qt5


【解决方案1】:

您的项目中可能不存在文件widget.h 和widget.cpp,这可能会导致此问题。无论如何你的项目没有使用它们。

为了运行您在main.cpp 中编写的代码,您的项目.pro 不必多于这个:

  #-------------------------------------------------
#
# Project created by QtCreator 2018-01-15T00:00:06
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Test1
TEMPLATE = app

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
        main.cpp \


HEADERS += \


FORMS += \

并从main.cpp 中删除#include widget.h,因为您没有使用widget.cpp 和widget.h。

【讨论】:

  • 我从 .pro 中删除了 widget.cpp、widget.h 和 widget.ui。我从 main.cpp 中删除了“#include”widget.h。但是我得到了同样的错误“ld: library not found for -lQt5Widgets_debug”。你还有其他想法吗?
  • @Yoshiki.M ,你是如何安装 Qt 的?看来您缺少库,您能显示在 qt 中自动配置的工具包吗?此外,通过阅读我的帖子检查 qt 是否正确构建:stackoverflow.com/questions/48272668/…
猜你喜欢
  • 2019-01-25
  • 2017-05-26
  • 2021-08-24
  • 2016-02-11
  • 2021-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多