简体   繁体   English

cmake如何避免系统库

[英]cmake How to avoid system libraries

I want to use a certain version of Qt4 in my project. 我想在项目中使用特定版本的Qt4。 I'm using debian and there is already an older version of Qt4 installed. 我正在使用debian,并且已经安装了旧版本的Qt4。 When I'm using the find_package command in my CMakeLists file, of course, the system library is found, because the file /usr/share/cmake-2.8/Modules/FindQt4.cmake is used by cmake. 当我在CMakeLists文件中使用find_package命令时,当然会找到系统库,因为cmake使用了/usr/share/cmake-2.8/Modules/FindQt4.cmake文件。

What I've done so far to link the newer Qt4, is to edit the paths with ccmake manually. 到目前为止,我链接新的Qt4的方法是使用ccmake手动编辑路径。 The problem is I'm not allowed to install the newer Qt4 version in the directories of the system. 问题是我不允许在系统目录中安装较新的Qt4版本。 Is there any easier solution to tell cmake don't use the system library just use another version. 有没有更简单的解决方案来告诉cmake不要仅使用另一个版本就使用系统库。 Of course I could create my own module and give the find_package command the path to my own module, but I think this is annoying and there have to be an more easier solution. 当然,我可以创建自己的模块,并为find_package命令提供指向自己模块的路径,但是我认为这很烦人,因此必须有一个更简单的解决方案。

What I've also looked for, are there some environment variables which are used by the FindQt4.cmake module, but there aren't. 我还寻找的是FindQt4.cmake模块使用的一些环境变量,但是没有。 - So, is there a general solution to avoid system libraries and to use libraries which installed in not system directories without doing some dirty tricks? -那么,是否有一个通用的解决方案来避免系统库并使用不安装在系统目录中的库而又不做一些恶作剧?

The only real way to use different versions of libraries on Linux is to use static linking. 在Linux上使用不同版本的库的唯一真实方法是使用静态链接。 If you require the ability to use different versions of the same library simultaneously, you'll need to use an OS that supports that paradigm. 如果您需要能够同时使用同一库的不同版本,则需要使用支持该范例的OS。 Solaris (and its derivatives) is particularly good at that (compile with -L to point to the library to compile against and -R to indicate the path to that library at runtime). Solaris(及其派生类)在这方面尤其擅长(使用-L进行编译以指向要针对其进行编译的库,使用-R进行指示以在运行时指向该库的路径)。 I believe BSD is the same. 我相信BSD是一样的。

Barring that, you'll want to create a chroot (a poor man's BSD jail) to deploy your application in. You'll install a copy of all the dependencies to the chroot, (use ldd to find them out) and the copy of Qt4 you wish to use. 除非这样做,否则您将要创建一个chroot (可怜的人的BSD监狱)来部署您的应用程序。您将所有依赖项的副本安装到chroot(使用ldd找出它们)和您想使用的Qt4。

Don't know about system libraries in general. 一般不了解系统库。 For Qt, you set the search path to qmake and qt will do the rest. 对于Qt,将搜索路径设置为qmake,其余的将由qt完成。 Qmake path is set through QT_QMAKE_EXECUTABLE, I use Qt commercial and this is how I set the path in Cmake. Qmake路径是通过QT_QMAKE_EXECUTABLE设置的,我使用Qt商业版,这就是我在Cmake中设置路径的方式。

set(QT_QMAKE_EXECUTABLE $ENV{HOME}/QtCommercialSDK/Desktop/483/gcc-64/bin/qmake) 设置(QT_QMAKE_EXECUTABLE $ ENV {HOME} / QtCommercialSDK / Desktop / 483 / gcc-64 / bin / qmake)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM