CMake how to remove the path from compile errors - path

When using cmake if there is a compile error the error is output with the entire path to the file containing the error. This path can be very long (see example below) so often it word wraps and makes it difficult to read.
Example Output:
/home/nick/projects/projectA/src/environment/base/terrain/base/TestFile.h:21:37: error: ‘TestFile’ does not name a type
/home/nick/projects/projectA/src/environment/base/terrain/base/TestFile.h:21:54: error: expected unqualified-id before ‘test’
/home/nick/projects/projectA/src/environment/base/terrain/base/TestFile.h:21:54: error: expected ‘)’ before ‘test’
Is there a way to remove the path from the error?
Something like this:
TestFile.h:21:37: error: ‘TestFile’ does not name a type
TestFile.h:21:54: error: expected unqualified-id before ‘test’
TestFile.h:21:54: error: expected ‘)’ before ‘test’
Thanks

I don't know if it is possible within cmake, but you can always redirect stderr to stdout and filter the output with a short sed script. At least the common project path can be filtered
make 2>&1 | sed 's/\/home\/nick\/projects\/projectA\/src\///g'

Related

Xcode Import Localizations failed

We use the 'Export Localizations...' and 'Import Localizations...' tool of Xcode for localization in our project and it works well on Xcode 12.4. But after we upgrade Xcode to 12.5.0, errors raised with the same 'xliff' file, with message:Localizable.strings: Missing ';' on line 1028, Check the strings file with plutil or/and check_strings and fix the syntax error.
We do something below:
check all string files find ./ -name '*.strings' -exec plutil -lint {} \; but no errors found
run command line tool xcodebuild -importLocalizations -localizationPath xxx.xliff -project Project.xcodeproj, and we find some error like this genstrings: error: bad entry in file .../xxx.m (line = 603): Argument is not a literal string., so we fix all the error raised by NSLocalizedString and NSLocalizedStringFromTableInBundle.
but the import is still not working with error 2021-08-05 09:36:17.801 xcodebuild[29848:4770072] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 1028. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. xcodebuild: error: Localizable.strings: Missing ';' on line 1028
If anyone can shed a light it would be wonderful.

Cannot compile Open CV on Ubuntu 18.04 because of jasper.h not found

I am trying to compile Opencv on Ubuntu 18.04. I installed many dependencies packages but when I run make I get the error:
grfmt_jpeg2000.cpp:59:10: fatal error: jasper/jasper.h: No such file or directory
#include <jasper/jasper.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
I had already jasper installed and installed libjasperreports-java. However the file jasper.h cannot still be found in my system. Is there any library I can install with apt install to get that file? Or am I missing any other library?
EDIT 1
I tried also downloading the opencv_contrib to install extra moduels of openCV but first of all jaspar is not present and secondly setting the build with
cmake -D CMAKE_INSTALL_PREFIX=./ -D CMAKE_BUILD_TYPE=Debug -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ../openCV
returns the error:
Make Error at cmake/OpenCVModule.cmake:352 (message):
Duplicated modules NAMES has been found
while CMakeError.log contains many errors of the type:
Build output check failed:
Regex: 'command line option .* is valid for .* but not for C\+\+'
Output line: 'cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++'

Why can't ld called from MSYS find (existing static) library when arguments are read from a response #file containing backslashes?

This is basically the same issue as in mingw ld cannot find some library which is exist in the search path, MinGW linker can't find MPICH2 libraries - and I'm aware that there are heaps of posts on StackOverflow regarding the issue of static and dynamic linking with MinGW - but I couldn't find anything that explains how I can troubleshoot.
I am building a project with a huge linker command like (via g++) on MinGW, in a MSYS2 shell (git-bash.exe). The process fails with, among others:
/z/path/to/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lssl
I add -Wl,--verbose to the g++ linker call (to be passed to ld), and I can see for the -L/z/path/to/libs/openssl/lib/mingw -lssl:
...
attempt to open /z/path/to/libs/openssl/lib/mingw/libssl.a failed
...
/z/path/to/libs/openssl/lib/mingw/ssl.dll failed
attempt to open /z/path/to/libs/openssl/lib/mingw\libssl.a failed
...
But this is weird, because the file exists?
$ file /z/path/to/libs/openssl/lib/mingw/libssl.a
/z/path/to/libs/openssl/lib/mingw/libssl.a: current ar archive
(... and it was built with the same compiler on the same machine)?
Weirdly, once it attempts to open with forward slash .../libssl.a, once with backslash ...\libssl.a - but at least the first path checks out in a bash shell, as shown above?
It gets even worse if I try to specify -l:libssl.a -- or if I specify -L/z/path/to/libs/openssl/lib/mingw -Wl,-Bstatic -lssl -- instead; then all attempts to open are with a backslash:
...
attempt to open /z/path/to/scripts/other/build/openssl/build/mingw/lib\libssl.a failed
attempt to open /z/path/to/libs/openssl/lib/mingw\libssl.a failed
...
To top it all off, if I look it up manually through the command line using ld, it is found ?!:
$ ld -L/z/path/to/libs/openssl/lib/mingw -lssl --verbose
attempt to open Z:/path/to/libs/openssl/lib/mingw/libssl.dll.a failed
attempt to open Z:/path/to/libs/openssl/lib/mingw/ssl.dll.a failed
attempt to open Z:/path/to/libs/openssl/lib/mingw/libssl.a succeeded
Does anyone have an idea why this happens, and how can I get ld to finally find these libraries? Or rather - how can I troubleshoot, and understand why these libraries are not found, when they exist at the paths where ld tries to open them?
OK, found something more - not sure if this is a bug; but my problem is that I'm actually reading arguments from a file (otherwise I get g++: Argument list too long). So, to simulate that:
$ echo " -Wl,--verbose -L/z/path/to/libs/openssl/lib/mingw -lssl -lcrypto " > tmcd3
$ g++ #tcmd3 2>&1 | grep succeeded | grep ssl
# nothing
$ g++ `cat tcmd3` 2>&1 | grep succeeded | grep ssl
attempt to open Z:/path/to/libs/openssl/lib/mingw/libssl.a succeeded
attempt to open Z:/path/to/libs/openssl/lib/mingw/libcrypto.a succeeded
... it turns out, if the very same arguments are fed on the command line, then static library lookup succeeds - but if the arguments are read from file through the # at-sign, then static library lookup fails?! Unfortunately, I cannot use on my actual project, since even with cat, I'd still get g++: Argument list too long ... So how can I fix this?
MSYS has special handling of directories as arguments when they are used in the shell. This translates e.g. /<drive_letter>/blabla to the proper Windows style paths. This is to accomodate Unix programs that don't handle Z: style directory root.
What you see here is that MSYS isn't performing this interpretation for string read from a file. When you think about it, it's very logical, but as you have experienced first-hand, also sometimes annoying.
Long story short: don't put Unix style paths in files with command arguments. Instead, pass them through e.g. cygpath -w, which works in MSYS2 (which should be the MSYS that Git for Windows 2+ comes with).
Ok, with some more experiments, I noticed that:
-L/z/path/to/libs/openssl/lib/mingw, the Unix path specification, tends to fail - while if we specify the same, except starting with a Windows drive letter, that is:
-LZ:/path/to/libs/openssl/lib/mingw, then things work - also from an arguments file with # at-sign:
$ echo " -Wl,--verbose -LZ:/path/to/libs/openssl/lib/mingw -lssl -lcrypto " > tmcd3
$ g++ #tcmd3 2>&1 | grep succeeded | grep ssl
attempt to open Z:/path/to/libs/openssl/lib/mingw/libssl.a succeeded
attempt to open Z:/path/to/libs/openssl/lib/mingw/libcrypto.a succeeded
I guess, since the shell is MSYS2/git-bash.exe, entering full POSIX paths on the shell with /z/... is not a problem, because the shell will convert them - but in a file, there is nothing to convert them, so we must use Windows/MingW convention to specify them...

Cmake error: Invalid escape sequence \U

While running my OpenCL code in VC++ 10 by using CMake I am getting the following error:
CMake Error at CMakeLists.txt:6 (set): Syntax error in cmake code at
C:/Users/Shreedhar/Desktop/testCL/CMakeLists.txt:6
when parsing string
C:\Users\Shreedhar\Desktop\test_CL\CMakeLists
Invalid escape sequence \U
Use forward slashes / in your paths
C:/Users/Shreedhar/Desktop/test_CL/CMakeLists
If you are reading user input like environment variables then you'll need to do this by character replacement feature of string method.
string(REPLACE "\\" "/" outputVar ${_inputVar})
For those who receive this error under Windows:
CMake Error at
C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:903 (list):
Syntax error in cmake code at
C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:903
when parsing string
C:\Dev\mongodb\src\boost/lib${_arch_suffix}-msvc-15.0
Invalid character escape '\D'. Call Stack (most recent call first):
C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:1379
(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS)
src/bsoncxx/CMakeLists.txt:100 (find_package)
Don't set the BOOST_ROOT environment variable to a backslash-ended value.

javac flag to print only the error locations

Is it possible to make javac output only the error locations and the error messages, and hide the source code dump?
Now I get:
$ javac t.java
t.java:1: <identifier> expected
class {
^
t.java:2: reached end of file while parsing
bar
^
t.java:4: reached end of file while parsing
^
3 errors
I want to get only:
$ javac ... t.java
t.java:1: <identifier> expected
t.java:2: reached end of file while parsing
t.java:4: reached end of file while parsing
I think there is no flag you could pass to javac, but you can simply filter the output through any program which removes the superfluous lines. Here an example with grep:
javac t.java 2>&1 | egrep '^[a-zA-Z0-9_/]+\.java:[0-9]+: '
You might have to change the part matching the file name if you have strange letters in your file name - this seems to work for the ASCII subset.

Resources