如何在 Qt 项目中引用第 3 方 dll/库

发布于 2024-12-18 07:41:54 字数 2075 浏览 2 评论 0原文

我已经尝试解决这个问题一个小时了。我拥有的是一个在 Qt Creator 中打开的简单 Qt 项目。我想做的是将 SDL 库 (dll) 与我的 Qt 项目一起使用。

在 Visual Studio 中,我通常会使用提供此功能的 VS 工具添加对此 dll 的引用。在 Qt Creator 中,我打开了项目的 .pro 文件,并为 STD dll 添加了一个 LIB 条目

# Add more folders to ship with the application, here
folder_01.source = qml/BoxGame
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01

# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =

symbian:TARGET.UID3 = 0xEED812B5

# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
# fail to install if self-signed. By default qmake uses the unprotected
# range value if unprotected UID is defined for the application and
# 0x2002CCCF value if protected UID is given to the application
#symbian:DEPLOYMENT.installer_header = 0x2002CCCF

# Allow network access on Symbian
symbian:TARGET.CAPABILITY += NetworkServices

# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
LIBS  +=  C:\Users\vata\Desktop\DskProj\Dsk-build-desktop\debug\SDL.dll


# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
    blockboxes.cpp \
    block.cpp \
    boxengine.cpp \
    boxgame.cpp \
    point.cpp \
    gamecontroller.cpp \
    gamecontrollermod.cpp

# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()

HEADERS += \
    blockboxes.h \
    block.h \
    boxengine.h \
    boxgame.h \
    Globals.h \
    point.h \
    gamecontroller.h \
    gamecontrollermod.h \
    controller.h

,但是,这似乎不包括 Qt 中供我使用的库。编译时,我仍然收到 SDL.h: No such file or directory 错误消息。我将不胜感激任何帮助解决这个问题并可能为未来学习的帮助,因为我打算在我的开发工作中更频繁地使用 Qt。

Running build steps for project Tetris...
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe" clean
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug clean

Been trying to figure this out for an hour now. What I have is a simple Qt Project open in Qt Creator. What I would like to do is use the SDL library (dll) with my Qt project.

In visual Studio, what I would normall do is add a reference to this dll using VS tool that provides for that. In Qt creator, I opened the .pro file for my project, and added a LIB entry for the STD dll

# Add more folders to ship with the application, here
folder_01.source = qml/BoxGame
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01

# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =

symbian:TARGET.UID3 = 0xEED812B5

# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
# fail to install if self-signed. By default qmake uses the unprotected
# range value if unprotected UID is defined for the application and
# 0x2002CCCF value if protected UID is given to the application
#symbian:DEPLOYMENT.installer_header = 0x2002CCCF

# Allow network access on Symbian
symbian:TARGET.CAPABILITY += NetworkServices

# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
LIBS  +=  C:\Users\vata\Desktop\DskProj\Dsk-build-desktop\debug\SDL.dll


# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
    blockboxes.cpp \
    block.cpp \
    boxengine.cpp \
    boxgame.cpp \
    point.cpp \
    gamecontroller.cpp \
    gamecontrollermod.cpp

# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()

HEADERS += \
    blockboxes.h \
    block.h \
    boxengine.h \
    boxgame.h \
    Globals.h \
    point.h \
    gamecontroller.h \
    gamecontrollermod.h \
    controller.h

However, that does not seem to include the Library in Qt for my use. When I compile, I still get an SDL.h: No such file or directory error message. Would appreciate any help in figuring this out and probably learning for the future as I intend to use Qt more often than not for my development work.

Running build steps for project Tetris...
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe" clean
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug clean

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屌丝范 2024-12-25 07:41:54

SDL.h 是 C 头文件,而不是库。为了让编译器找到它,您需要将其目录添加到 qmake 的 INCLUDEPATH 中。例如:(

INCLUDEPATH += C:/Dir/Where/SDL/Headers/Are/Found

提示:您可以使用 / 而不是 \,以避免将 \ 解释为转义字符。)

SDL.h is a C header file, not a library. For the compiler to find it, you need to add its directory to qmake's INCLUDEPATH. For example:

INCLUDEPATH += C:/Dir/Where/SDL/Headers/Are/Found

(Tip: you can use / instead of \ to stay clear of possible interpretations of \ as an escape character.)

醉生梦死 2024-12-25 07:41:54

尝试类似:

LIBS += -LC:\\Users\\vata\\Desktop\\DskProj\\Dsk-build-desktop\\debug -lsdl

Try something like:

LIBS += -LC:\\Users\\vata\\Desktop\\DskProj\\Dsk-build-desktop\\debug -lsdl

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文