0

I have been trying to compile a repository in OSX unsuccessfully.

The repository is in C++. When I use cmake and then make in Ubuntu, all is good. Even on Windows with MinGW, I am able to build the code.

However, in OSX 11.0.1 Big Sur, I get no errors with cmake, but make fails. I have installed the latest version of Xcode, including for the command line.

Here is the error I receive:

error: 
      non-constant-expression cannot be narrowed from type 'long' to
      '__darwin_suseconds_t' (aka 'int') in initializer list [-Wc++11-narrowing]

I have seen similar posts, but haven't been able to solve my problem yet.

Enrico Anderlini
  • 447
  • 6
  • 21

1 Answers1

1

You could try to force CMake to use gcc by setting the flags:

cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ ...

or maybe provide -Wno-c++11-narrowing flag to cmake.

This post is a good resource for adding compilerflags via the command line. But if you own the project you're trying to compile you should just edit the CMakeLists.txt file itself.

EDIT: I misspelled the disabling of the warning flag

EA: I updated the path to the directory where my GNU files are stored as compared with clang.

Enrico Anderlini
  • 447
  • 6
  • 21
Sillydan
  • 104
  • 13
  • Still no luck after trying both solutions. I'm now having a look at the linked post. – Enrico Anderlini Nov 17 '20 at 08:23
  • Unfortunately, I do not own the repository. – Enrico Anderlini Nov 17 '20 at 08:23
  • Do you still get the same error when changing the compiler to gcc? It's been a while since I played with clang, but it looks like it is a clang warning to me. If the repo is FOSS, could you link it? – Sillydan Nov 18 '20 at 07:07
  • Also, are you sure that you have gcc installed on your mac-device? – Sillydan Nov 18 '20 at 07:07
  • gcc is installed (version 10.2.0). However, I can see that when I run gcc --version, I end up with clang, so I will try to relink it. Thanks! – Enrico Anderlini Nov 18 '20 at 08:13
  • 1
    You were right: the computer was still using clang. This is because my GNU gcc & g++ are in /usr/local/bin. I also had to specify the version number, so this worked for me: `cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc-10 -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-10 ...` – Enrico Anderlini Nov 18 '20 at 08:51