QMake:使用相对路径引用库 [英] QMake: Referencing a library using relative paths

查看:48
本文介绍了QMake:使用相对路径引用库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 SQLite 的 Qt 项目,所以我有以下目录结构:

I have a Qt project using SQLite, so I have the following directory structure:

C:\Workspace\MyProject\MyProject.pro
C:\Workspace\MyProject\sqlite3\sqlite3.lib

使用绝对路径添加 sqlite3.lib 工作正常:

Adding sqlite3.lib with absolute paths works fine:

LIBS += -L"c:/Workspace/MyProject/sqlite3" -lsqlite3

但我不能让它与相对路径一起工作.我尝试:

But I can't make it work with relative paths. I try with:

LIBS += -L"sqlite3" -lsqlite3

但是失败了:

:-1: error: LNK1104: cannot open file 'sqlite3\sqlite3.lib'

我尝试过 LIBS += -L"../sqlite3" 甚至 LIBS += -L"../../sqlite3",但是也没有用.

I tried but LIBS += -L"../sqlite3" or even LIBS += -L"../../sqlite3", but that didn't work either.

我使用 MSVC 2008 作为编译器工具链.

I'm using MSVC 2008 for the compiler toolchain.

推荐答案

由于可以从与项目目录不同的目录构建,因此指向项目目录的相对路径应以 $$PWD/ 为前缀(PWD qmake 变量包含当前处理的 *.pro 文件所在目录的绝对路径).

Since it's possible to build from different directory than project directory, relative path pointing to project directory should be prefixed with $$PWD/ (PWD qmake variable contains absolute path to directory with currently processed *.pro file).

你的行看起来像:

LIBS += -L"$$PWD/sqlite3" -lsqlite3

这篇关于QMake:使用相对路径引用库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆