将自己的库添加到 QT creator C 项目

Adding own library to QT creator C project

如何在QT creator C 项目中使用我自己的C 库?谷歌搜索后,我遇到了两种方法:

  1. 正在创建一个全新的库和copy/paste您自己的库代码到 QT creator 中的新库中。
  2. 第二个由 "Add Existing Files" 完成,您只需调整路径和库即可。

但在我的情况下他们都给了 "undefined reference to ..."。 我认为并相信这是因为链接问题。解决方案是什么?任何建议表示赞赏。

我可以通过将 "Set Build Command" 从 "gcc -Wall -o "%e" "%f" 更改为 "gcc -Wall -o "%e" "%f" [=27= 来解决 Geany 中的相同问题].这里 myHeader.h 是我自己的图书馆。 我完全在 C 上编码。

从技术上讲,您没有库,您只有一组文件,一个简单的解决方案是创建一个 .pri,其中添加了这些文件,link .pri 到 .pro:

├── your_project.pro
├── main.c
├── ...
├── ...
└── mylibrary
    ├── file1.h
    ├── file1.c
    ├── file2.h
    ├── file2.c
    └── mylibrary.pri

mylibrary.pri

INCLUDEPATH += $$PWD

SOURCES += \
    $$PWD/file1.c \
    $$PWD/file2.c

HEADERS += \
    $$PWD/file1.h \
    $$PWD/file2.h

your_project.pro

# ...

include(mylibrary/mylibrary.pri)