12

Goal: Generate/update the *.ts files of a Qt widgets app using lupdate.

Setup:

  • Windows 7 Pro 64 (tried on Windows 10 Home as well)
  • Qt 5.9.1 Prebult Components for msvc2017 64-bit,
  • Visual Studio Community 2017.

The problem: I have run lupdate from the QtCreator, as well as manually from the console, but in neither case it is working. The message is:

Starting external tool "C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin\lupdate.exe" C:/Documents/Projects/untitled1/untitled1.pro WARNING: Project ERROR: Cannot run compiler 'cl'. Maybe you forgot to setup the environment?

"C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin\lupdate.exe" finished

Otherwise the project is compiled, run and debugged without problems with the kit: Desktop Qt 5.9.1 MSVC2017 64bit (default), which is the reason I think the environment is properly set up.

I can't find any information regarding this issue. Any ideas how to make lupdate work?

EDIT: I am adding screenshots of the current setup (which is made by the Qt installer) in attempt to clarify why I believe the environment is properly set up:

kits

cmake configuration

scopchanov
  • 7,966
  • 10
  • 40
  • 68
  • @scopchanov: Do you have `cl.exe` in your machine with VS installation? Can you confirm it? See: https://stackoverflow.com/questions/7865432/command-line-compile-using-cl-exe and https://stackoverflow.com/questions/31953769/visual-studio-doesnt-have-cl-exe – Azeem Jul 05 '17 at 09:46
  • @Azeem, yes, I have cl.exe (even 4 of them for different processor architectures, e.g under C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64). As mentioned in the question: "the project is compiled, run and debugged without problems" – scopchanov Jul 05 '17 at 15:51
  • 2
    *Maybe you forgot to setup the environment* The tool is actually trying to tell you something. Maybe you forgot to setup the environment? https://learn.microsoft.com/en-us/cpp/build/setting-the-path-and-environment-variables-for-command-line-builds – n. m. could be an AI Jul 06 '17 at 04:39
  • 2
    I have no idea what the GUI tool would do, but running `lupdate` from the console most definitely requires that you run vcbars\*.bat as described in the link I gave you. That's because `lupdate` wants to run the compiler and it has no idea where to find it. `vcbars*.bat` tweaks your PATH and other environment variables. In theory the GUI should set up the environment for you, but in practice it probably doesn't. See [here](https://forum.qt.io/topic/80965/linguist-lupdate-project-error/7) but bear in mind that cl may require more environment than g++. – n. m. could be an AI Jul 06 '17 at 13:04
  • @Ruslan F. Check out the solution and see if it works for you. – scopchanov Jul 08 '17 at 20:21
  • 1
    I ran the command `lupdate "C:\some\path\project.pro"` in the Qt MinGW command prompt (the shortcut in the start menu is called "_Qt 5.9.1 for Desktop (MinGW 5.3.0 32 bit)_" and it worked just fine. Running the Qt Visual Studio command prompt didn't work strangely enough. The .ts and .qm files generated from the MinGW command prompt work even with programs compiled with Visual Studio compiler. – Donald Duck Sep 03 '17 at 16:00

4 Answers4

9

The solution

Here is the solution I've found (rather hack-ish, but not too much), based on the info and advices kindly provided by n.m. in the comments under the question:

  1. Create a translate.bat with the following single-line content:

    "%programfiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" & lupdate.exe %1

and put it under %{CurrentProject:QT_INSTALL_BINS} (in my case C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin). Make sure that the translate.bat contains the correct path to vcvars64.bat on your machine. You may as well put another version of vcvars if you need.

  1. In Qt Creator select Tools/Options/Environment/External Tools and then Add Tool under Linguist category. Name it something like Create/Update TS files. Setup the fields for this entry as follows:

    • Executable: %{CurrentProject:QT_INSTALL_BINS}\translate.bat,

    • Arguments: %{CurrentProject:FilePath},

    • Working directory: %{CurrentProject:QT_INSTALL_BINS},

as shown here: External Tools, then apply the changes and close the Options window.

  1. Go to Tools/External/Linguist, select Create/Update TS files and now it should do the job as usual.

The background

Here is once again the link, provided by n.m. in the comments, which served as a base for this solution. Here is also n.m.'s explaination:

Running lupdate from the console most definitely requires that you run vcbars*.bat as described in the link I gave you. That's because lupdate wants to run the compiler and it has no idea where to find it. vcbars*.bat tweaks your PATH and other environment variables. In theory the GUI should set up the environment for you, but in practice it probably doesn't.

scopchanov
  • 7,966
  • 10
  • 40
  • 68
  • As it is right now the translate.bat, it didn't work for me. I corrected the missing " at beginning, then it complained about not recognizing lupdate.exe command. Obviously, because it doesn't have the full path. Finally, it worked after fixing the above 2 issues. Many thanks. And here's the translate.bat I use for my msvc2015_32 configuration: "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" & c:\Qt\5.9.1\msvc2015\bin\lupdate.exe %1 – סטנלי גרונן Jul 12 '17 at 06:49
  • @groenhen thanks for making me aware of that! Indeed I've somehow missed/deleted the first quote when I edited the answer. It is corrected now. As for the path to _lupdate_, because of this setting: _Working directory: %{CurrentProject:QT_INSTALL_BINS}_, the batch file will be executed under the path specified by _CurrentProject:QT_INSTALL_BINS_ (in my case `C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin`), thus finding _lupdate.exe_ without any problems. I think it should be set up by Qt to the appropriate value for MSVC2015 as well. Anyway, I am glad that you've managed to make it work for you. – scopchanov Jul 12 '17 at 10:19
  • Maybe better set the path value of existing linguist tools? Under Tools/Options, environment, external tools, update translations (lupdate) there is Environment option with change button next to it. There you can set custom PATH value to point to the path of your current g++. Works fine for me. – elephant Mar 23 '18 at 08:34
  • @elephant, seems like a nice idea, though I wasn't able to make it work with MSVC :( – scopchanov Mar 23 '18 at 11:39
4

If you are using Qt5.9.1 of mingw version, you may need to config the system path for mingw compiling tools.

config system path for mingw for Qt's langulist lupdate

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
ndtc
  • 420
  • 5
  • 4
  • And don't forget to restart Qt Creator, as it seems to only check the `Path` at startup. – vsz May 16 '18 at 09:53
2

In my case the culprit was the fact that Qt Creator had somehow picked different target ABIs for C and C++:

C and C++ ABI mismatch

After fixing this, I managed to get lupdate running with no issues.

Alexandros
  • 3,044
  • 1
  • 23
  • 37
  • Unfortunatelly it doesn't work for MSVC2017. I've tried all possible choices from the list and the result stays the same. – scopchanov Jul 06 '17 at 22:30
  • I presume you tried setting both the C and C++ compiler ABI to amd64, is that correct (assuming, of course, that you're targeting x86_64)? – Alexandros Jul 06 '17 at 22:37
  • I've changed only the C compiler, as shown on the screenshot. – scopchanov Jul 06 '17 at 22:48
  • Do you perhaps see anything in the Issues tab when building the project? Asking because even though my project did compile successfully, I noticed a warning that eventually lead me to my answer. – Alexandros Jul 06 '17 at 23:07
  • nope. no problems (errors / warnings) are reported in the Issues nor the Compile Output tabs when building the project. – scopchanov Jul 06 '17 at 23:23
1

You have to run lupdate.exe from VS2015 x86 Native Tools Command Prompt console.

Silver Zachara
  • 2,901
  • 2
  • 16
  • 22