Cytnx icon indicating copy to clipboard operation
Cytnx copied to clipboard

Problem with installing on Mac

Open josephinius opened this issue 1 year ago • 14 comments

First, I had to add add_compile_options(-Wno-c++11-narrowing) into CMakeLists.txt to get rid of this error:

error: non-constant-expression cannot be narrowed from type 'value_type' (aka 'int') to 'unsigned long long' in initializer list [-Wc++11-narrowing]
        auto eigTens = P_inv.at({0, maxIdx}) * qs[0];

But I still have the following error while installing:

error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];

I use clang as a compiler.

josephinius avatar Aug 27 '24 13:08 josephinius

The first one can be resolved by explicit casting.

error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];

Can you tell me where it occurs?

Here is a related fix https://github.com/tfhe/tfhe/issues/213

yingjerkao avatar Aug 28 '24 06:08 yingjerkao

Here are the whole error messages:

/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:31:36: error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];
                 ~                 ^~~~~~~~~~~~~~~
/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:55:35: error: implicit conversion from '_Complex float' to 'float' is not permitted in C++
        od[0] *= (cytnx_complex64)_Rin[i * N + i];

josephinius avatar Aug 28 '24 12:08 josephinius

#455 fixed the no-c++11-narrowing problem. For the implicit conversion, I can't reproduce the error while using clang++. @josephinius, does the error still happen?

IvanaGyro avatar Sep 01 '24 03:09 IvanaGyro

with commit 0be640dcb08dcfd4de8ed9a2f7da73dec7ddfaf2 and clang version: -- The CXX compiler identification is AppleClang 15.0.0.15000309 -- The C compiler identification is AppleClang 15.0.0.15000309

I still encounter this

[ 83%] Building CXX object CMakeFiles/cytnx.dir/src/backend/linalg_internal_cpu/Ger_internal.cpp.o
/Users/pcchen/github/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:31:36: error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];
                 ~                 ^~~~~~~~~~~~~~~
/Users/pcchen/github/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:55:35: error: implicit conversion from '_Complex float' to 'float' is not permitted in C++
        od[0] *= (cytnx_complex64)_Rin[i * N + i];
                 ~                ^~~~~~~~~~~~~~~
2 errors generated.

pcchen avatar Sep 01 '24 05:09 pcchen

A solution was given in #461. I am not sure if the change really suppress the error of invalid conversion because I cannot reproduce on CentOS with clang and the online clang compiler either.

圖片

Someone who has Mac can try to build the code below with clang++ and see if it can be successfully compiled. If it is not passed, there may be a bug in Mac's clang.

#include <complex.h>
#include <iostream>
#include <complex>


int main() {
    double _Complex c_type_right = 123.4 + 45435.1I;
    std::complex<double> cpp_type_right{23, 23};
    std::complex<double> left{43.4, 2532.1};
    left *= (std::complex<double>)c_type_right;
    left *= (std::complex<double>)cpp_type_right;

    std::cout << std::complex<float>{c_type_right} << std::endl;
}

IvanaGyro avatar Sep 01 '24 09:09 IvanaGyro

@IvanaGyro I tried to compile the code

#include <complex.h>
#include <iostream>
#include <complex>

int main() {
    double _Complex c_type_right = 123.4 + 45435.1I;
    std::complex<double> cpp_type_right{23, 23};
    std::complex<double> left{43.4, 2532.1};
    left *= (std::complex<double>)c_type_right;
    left *= (std::complex<double>)cpp_type_right;

    std::cout << std::complex<float>{c_type_right} << std::endl;
}

using Apple clang version 15.0.0 (clang-1500.3.9.4); I got the error:

complex_example.cpp:10:35: error: implicit conversion from '_Complex double' to 'double' is not permitted in C++ left *= (std::complex)c_type_right; ~ ^~~~~~~~~~~~ complex_example.cpp:13:38: error: implicit conversion from '_Complex double' to 'float' is not permitted in C++ std::cout << std::complex{c_type_right} << std::endl; ~~~ ^~~~~~~~~~~~ 2 errors generated.

josephinius avatar Sep 02 '24 13:09 josephinius

It seems that #461 has resolve this issue. Apple Clang missed some features. We may consider not to support Apple Clang.

IvanaGyro avatar Sep 14 '24 18:09 IvanaGyro

Which c++ version are we targeting? I would suggest target C++24 (don't use anything that is too new)

And If to possible please write the code that could cover most of the compilers ( specifically clang has more restrictions compared to g++, so I suggest to target clang when developing).

kaihsin avatar Sep 14 '24 20:09 kaihsin

Also. Apple's clang (Apple clang) is different from the typical clang. The behavior is different from the clang one installs on Mac via homebrew.......

pcchen avatar Sep 15 '24 03:09 pcchen

I wanted to bring this up since it seems there is a workaround: Installing a different version of clang that follows the standards. Could someone comment on this or give a brief howto? This could also be added as a comment in the user guide for Mac users.

manuschneider avatar May 05 '25 08:05 manuschneider

Maybe refer to this post: https://apple.stackexchange.com/questions/245891/installed-gcc-with-homebrew-now-how-to-use-that-gcc-instead-of-clang It seems using homebrew is a simple way to install the compiler like GCC or Clang.

IvanaGyro avatar May 05 '25 08:05 IvanaGyro

#616 is one of PR of the milestone to release and build Cytnx for Mac.

IvanaGyro avatar Jun 24 '25 09:06 IvanaGyro

Can also do conan2.

On Tue, Jun 24, 2025, 05:46 Ivana @.***> wrote:

IvanaGyro left a comment (Cytnx-dev/Cytnx#449) https://github.com/Cytnx-dev/Cytnx/issues/449#issuecomment-2999594067

#616 https://github.com/Cytnx-dev/Cytnx/pull/616 is one of PR of the milestone to release and build Cytnx for Mac.

— Reply to this email directly, view it on GitHub https://github.com/Cytnx-dev/Cytnx/issues/449#issuecomment-2999594067, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFCX3SL5QD3AYQH66OEPOJD3FENBHAVCNFSM6AAAAAB4OBHUZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOJZGU4TIMBWG4 . You are receiving this because you commented.Message ID: @.***>

kaihsin avatar Jun 24 '25 10:06 kaihsin

This should be fixed by PR #639 @josephinius could you check it is working?

yingjerkao avatar Aug 19 '25 02:08 yingjerkao