Solution to the error of cscope – Q option in Windows

In the past, some netizens left a message. When using cscope under windows, the following prompt appeared when using the – Q option:

D:\Temp> cscope -Rbkq
Input file specified two times.

cscope: cannot create inverted index; ignoring -q option
cscope: removed files ncscope.in.out and ncscope.po.out

At that time, easby thought that cscope of Windows version did not support – Q option

However, netizen Liang Feng left a message yesterday

Windows版本的cscope是支持-q选项的,出现以上错误是因为没找到合适的sort命令。所以只要cscope进程的工作目录下有GNU版本的sort就可以了。注意是进程的工作目录,不是可执行程序的目录。具体原因看一下cscope的代码片段。

build.c

#ifdef WIN32
snprintf(sortcommand, sizeof(sortcommand), “set LC_ALL=C && sort -T %s %s”, tmpdir, temp1);
#else
snprintf(sortcommand, sizeof(sortcommand), “env LC_ALL=C sort -T %s %s”, tmpdir, temp1);
#endif

So we did the experiment again. After cygwin is installed, cscope is used in the shell interface of cygwin, and the above error prompt does not appear. However, if you open the command line window of windows, cmd.exe, and execute cscope in it, the above error will appear

After carefully comparing the environment of cygwin with that of cmd.exe, it turns out that sort.exe, which comes with windows, is the ghost

In the shell window of cygwin, the setting of path environment variable will make it find the GNU version of sort.exe first, so the above cscope command can be executed successfully. But in the cmd.exe window, the path environment variable will make it find the sort.exe that comes with windows first instead of GNU sort.exe, so the above error prompt will appear

Knowing the cause of the problem, the solution is very simple. We can write a batch program, reset the path environment variable in this program, and make cscope use GNU version of sort.exe. The sample procedure is as follows:

D:\Temp> type cs.bat
@echo off
set path=c:\cygwin\bin;
cscope -Rbkq

In this batch process, first point the path environment variable to C:// cygwin/bin;, My cscope.exe and GNU version of sort.exe are in this directory. Next, execute the cscope command. Now it uses the GNU version of sort. Exe

Similar Posts: