【问题标题】:How to reference 3rd party dlls/libraries in Qt projects如何在 Qt 项目中引用 3rd 方 dll/库
【发布时间】:2011-11-26 20:58:07
【问题描述】:

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

在 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

【问题讨论】:

    标签: c++ qt mingw sdl qt-creator


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      尝试类似:

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

      【讨论】:

      • @Kobojunkie:试试LIBS += "C:/Users/vata/Desktop/DskProj/Dsk-build-desktop/debug/SDL.dll"
      • @Kobojunkie:对不起,我一开始没有认真阅读你的问题。你还在收到“SDL.h:没有这样的文件或目录”吗?如果是这样,您应该将 ICLUDEPATH 添加到 .pro 文件中的 SDL 包含
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多