wlav / cppyy

Other
391 stars 40 forks source link

Generate automatic python binding for a c++20 library #137

Open axmat opened 1 year ago

axmat commented 1 year ago

Hello,

cppyy works fine with C++17. However, when I try to generate the bindings for a C++20 library I get the following error:

error: invalid value 'c++20' in '-std=c++20'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard
error: invalid value 'c++20' in '-std=c++20'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard
Error: Parsing Linkdef file /home/ahmat/git/Tenseur/build-python/bindings/python/linkdef.h
make[2]: *** [bindings/python/CMakeFiles/TenseurCppyy.dir/build.make:74: bindings/python/Tenseur.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:142: bindings/python/CMakeFiles/TenseurCppyy.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

It might be because clang expect the flag "-std=c++2a" instead of "-std=c++20".

Here's my CMake file:

execute_process(COMMAND cling-config --cmake OUTPUT_VARIABLE CPPYY_MODULE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
message("CPYY_MODULE_PATH: " ${CPPYY_MODULE_PATH})
list(INSERT CMAKE_MODULE_PATH 0 ${CPPYY_MODULE_PATH})
find_package(Cppyy)

cppyy_add_bindings(
   "Tenseur" "0.0.0" "..." "..."
   LANGUAGE_STANDARD "20"
   GENERATE_OPTIONS "-D__PIC__;-Wno-macro-redefined"
   INCLUDE_DIRS ${PROJECT_SOURCE_DIR}
   H_DIRS ${PROJECT_SOURCE_DIR}/Ten
   H_FILES "Test.hxx")

Thanks

wlav commented 1 year ago

It might be because clang expect the flag "-std=c++2a" instead of "-std=c++20".

Yes, as the latest release is still Clang9.

Repo is at Clang13, which will be released as cppyy 3.0.0. Then C++20 support will be much better.

wlav commented 1 year ago

cppyy 3.0.0 has been released. To test C++20, set the envar EXTRA_CLING_ARGS to something like -std=c++2a -O2 -march=native.

axmat commented 1 year ago

cppyy 3.0.0 has been released. To test C++20, set the envar EXTRA_CLING_ARGS to something like -std=c++2a -O2 -march=native.

Thank you for the update. I've tested it and it works fine with those flags.

The library requires a more recent version of Clang (It compiles with Clang-16).

wlav commented 1 year ago

This is Clang13. I'm dependent on upstream (Cling) to update first; they claim that going forward, updates can come faster as a lot of changes in Clang needed for Cling have found their way into Clang proper.

16.0.0, however, has only been out for 3 days ...

axmat commented 1 year ago

This is Clang13. I'm dependent on upstream (Cling) to update first; they claim that going forward, updates can come faster as a lot of changes in Clang needed for Cling have found their way into Clang proper.

16.0.0, however, has only been out for 3 days ...

I've been installing clang from the git repository so I don't keep track of the releases. It seems that the only option I have is to try to downgrade to Clang-13.

Thanks for cppyy, it's an incredibly useful library.