qmake .pro文件未正确解析以生成LD_LIBRARY_PATH [英] qmake .pro file not parsed correctly to generate LD_LIBRARY_PATH

查看:511
本文介绍了qmake .pro文件未正确解析以生成LD_LIBRARY_PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的几天里,我一直在尝试了解qmake的工作原理. 我想要一个具有以下结构的项目:

I have been trying in the last days to understand how qmake works buy I'm stuck. I want a project with the following structure:

  • bin
    • testjson
    • bin
      • testjson
      • libjson.so
      • testjson.cpp

      我只想测试json库.我在Qt Creator 2.3.0中创建了一个新的空项目,并设置了所有设置,以便可执行文件可以运行.测试了我想要的内容并关闭了应用程序.

      All i wanted was to test the json library. I have created a new empty project in Qt Creator 2.3.0, and set up all the settings so the executable will run. Tested what I wanted and closed the application.

      后来,当我再次打开Qt Creator时,我加载了.pro文件并感到惊讶,当我尝试运行该项目时,我收到以下消息:未指定可执行文件." :|在这种情况下,我转到项目选项卡,并手动选择了可执行文件,但是正如预期的那样,当我尝试运行该可执行文件时,出现以下消息:加载共享库时出错:libjson.so:无法打开共享库文件:没有这样的文件文件或目录".由于未设置LD_LIBRARY_PATH,这是预期的(就像我从cli运行它一样.)

      Later, when I opened Qt Creator again, I loaded the .pro file and surprise, when I try to run the project I get this message: "No executable specified." :| In this case I went to the project tab, and selected the executable manually but, as expected, when I tried to run it, I got this message "error while loading shared libraries: libjson.so: cannot open shared object file: No such file or directory". It was expected since the LD_LIBRARY_PATH is not set(it's like i'd run it from cli).

      .pro文件似乎没有正确解析,因为第一次选择运行"选项卡时,在项目选项卡上,我会看到一条消息:正在解析.pro文件",然后是正在运行的配置将被填充并显示为灰色,因此这意味着LD_LIBRARY_PATH是Qt Creator在解析.pro文件后添加的.

      It looks like the .pro file isn't parsed properly because the 1st time, on the project tab when I was selectig Run tab, I'd see a message : "Parsing .pro file", and then the running config would get filled, and greyed out, so it means that the LD_LIBRARY_PATH was added by Qt Creator after parsing the .pro file.

      现在我的问题是:为什么第一次正确解析.pro文件?

      Now my questing is: why was the .pro file parsed correctly 1st time?

      这是.pro文件:

      !include(../../common.pri){
          error(Couldn't find the common.pri file!)
      }
      
      TEMPLATE = app
      
      SOURCES += testjson.cpp
      CONFIG += console
      TARGET = testjson
      
      CONFIG(release, debug|release) {
          DESTDIR = $$BinaryDir/Release
      } else {
          DESTDIR = $$BinaryDir/Debug
      }
      
      LIBS += -L$$LibraryDir -ljson
      
      INCLUDEPATH += $$DefaultInclude
      DEPENDPATH += $$LibraryDir
      

      PS:解决方案是将LD_LIBRARY_PATH手动添加到建筑环境中,但是我发现这不是正确的方法.

      PS: The solution is to manually add the LD_LIBRARY_PATH to the building environment, but I find this not the right way to do it.

      推荐答案

      我认为您对qmake(.pro)文件控制的内容和运行时环境控制的内容之间感到困惑. .pro文件仅指定BUILD环境,而不指定运行时环境. .pro文件仅在构建过程中使用.

      I think you have confusion between what is controlled by the qmake (.pro) file and what is controlled by your runtime environment. The .pro file is only specifies the BUILD environment, not the runtime environment. The .pro file is only used during the build process.

      无论是从命令行还是从Qt Creator中运行构建的代码,您都在处理RUNTIME环境.如果尝试从外壳运行程序,则必须专门指定LD_LIBRARY_PATH.在Qt Creator中,您将必须执行相同的操作.

      When you go to run the built code, whether from a command line or from within Qt Creator, you are dealing with the RUNTIME environment. If you tried running the program from the shell, you would have to specifically specify the LD_LIBRARY_PATH. From within Qt Creator, you will have to do the same thing.

      [我仅在此处安装了Qt Creator 2.2,但在2.3中应该非常相似]

      [I only have Qt Creator 2.2 installed here, but it should be very similar in 2.3]

      要设置运行时环境,

      1. 在左侧工具栏中选择项目"图标.
      2. 在顶部,选择运行设置"
      3. 在运行设置"页面上,转到运行环境"设置,然后单击详细信息"以显示环境的详细信息.
      4. 单击添加...",然后使用适当的设置添加"LD_LIBRARY_PATH".

      完成后,设置将与您的项目一起存储. [设置实际上存储在以".user"结尾的文件中,而不是".pro"文件.]

      When you are done, the setting will be stored with your project. [The settings are actually stored in a file with a ".user" ending, not the ".pro" file.]

      当您运行项目时,将使用在运行设置"下设置的环境,并且您的应用程序应以正确的LD_LIBRARY_PATH开始.

      When you go to run your project, the environment you setup under "Run Settings" will be used, and you application should start with the correct LD_LIBRARY_PATH.

      这篇关于qmake .pro文件未正确解析以生成LD_LIBRARY_PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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