nmslib icon indicating copy to clipboard operation
nmslib copied to clipboard

Build error Clang: pragma message requires parenthesized string

Open veneres opened this issue 2 years ago • 4 comments

Hi all! First of all, a big thank you to the maintainers of this awesome library. I am opening an issue because I found a problem installing the pyserini Python library.

Following the stack trace I found that the problem was with the installation of nmslib, thus I tried to build it with Clang and I found out that the compiling error was the following:

./similarity_search/src/distcomp_scalar.cc:85:9: error: pragma message requires parenthesized string
#pragma message WARN("ScalarProductSIMD<float>: SSE2 is not available, defaulting to pure C++ implementation!")

I am using Clang 14.03:

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

On a MacBook Pro with Apple M1 Pro.

Trying to solve the problem, I found that the definition of the WARN macro is in python_bindings/similarity_search/include/utils.h but it seems that during the compilation distcomp_scalar.cc does not include utils.h. A simple workaround has been the inclusion of #define WARN(exp) ("WARNING: " exp) in distcomp_scalar.cc as in the patch below.

diff --git a/similarity_search/src/distcomp_scalar.cc b/similarity_search/src/distcomp_scalar.cc
index 0aed6eb..c1402f8 100644
--- a/similarity_search/src/distcomp_scalar.cc
+++ b/similarity_search/src/distcomp_scalar.cc
@@ -21,6 +21,8 @@
 #include <algorithm>


+#define WARN(exp) ("WARNING: " exp)
+
 namespace similarity {

 using namespace std;

With this patch, I was able to install the Python binding for nmslib and the pyserini without any problem.

Since I do not have a clear picture of the dependency of each file, I am not able to provide a better solution and a pull request. I do not know if this can be fixed, but at least I will leave this issue with this workaround if somebody else is going to have the same problem.

veneres avatar Jul 13 '23 09:07 veneres

Same problem here.

damian0815 avatar Aug 26 '23 15:08 damian0815

From this issue: https://github.com/allenai/scispacy/issues/497

I was able to get it to build (no patch) with

CFLAGS="-mavx -DWARN(a)=(a)" pip install nmslib

It looks like #539 fixes this but there isn't a plan to merge it.

ajb5d avatar Dec 28 '23 15:12 ajb5d

Same problem when building with LLVM Clang:

/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_math_nmslib/nmslib/work/nmslib-2.1.1/similarity_search/src/distcomp_scalar.cc:85:9: error: pragma message requires parenthesized string
#pragma message WARN("ScalarProductSIMD<float>: SSE2 is not available, defaulting to pure C++ implementation!")
        ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_math_nmslib/nmslib/work/nmslib-2.1.1/similarity_search/src/distcomp_scalar.cc:169:18: warning: explicit instantiation of 'NormScalarProductSIMD<float>' that occurs after an explicit specialization has no effect [-Winstantiation-after-specialization]
template float   NormScalarProductSIMD<float>(const float* pVect1, const float* pVect2, size_t qty);
                 ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_math_nmslib/nmslib/work/nmslib-2.1.1/similarity_search/src/distcomp_scalar.cc:83:7: note: previous template specialization is here
float NormScalarProductSIMD(const float* pVect1, const float* pVect2, size_t qty) {
      ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_math_nmslib/nmslib/work/nmslib-2.1.1/similarity_search/src/distcomp_scalar.cc:195:9: error: pragma message requires parenthesized string
#pragma message WARN("ScalarProductSIMD<float>: SSE2 is not available, defaulting to pure C++ implementation!")
        ^

barracuda156 avatar Mar 19 '24 05:03 barracuda156