Skip to content

Build fails with gcc 11 / C++20 #1007

Closed

Description

@urp

Problem

Compiler error when including node.h with NAPI_VERSION=8:

napi.h:2477:60: error: expected unqualified-id before ‘)’ token
 2477 |     TypedThreadSafeFunction<ContextType, DataType, CallJs>();
      |                                                            ^
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi.h:2479:33: error: expected ‘)’ before ‘tsFunctionValue’
 2479 |         napi_threadsafe_function tsFunctionValue);
      |                                 ^~~~~~~~~~~~~~~~
      |                                 )
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi.h:2478:59: note: to match this ‘(’
 2478 |     TypedThreadSafeFunction<ContextType, DataType, CallJs>(
      |                                                           ^
In file included from /home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi.h:2725,
                 from /home/adiletkutmanov/Development/lauda_measurement_napi/src/lauda_measurement.cpp:1:
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi-inl.h:4764:8: error: no declaration matches ‘Napi::TypedThreadSafeFunction<ContextType, DataType, CallJs>::TypedThreadSafeFunction()’
 4764 | inline TypedThreadSafeFunction<ContextType, DataType, CallJs>::
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi-inl.h:4764:8: note: no functions named ‘Napi::TypedThreadSafeFunction<ContextType, DataType, CallJs>::TypedThreadSafeFunction()’
In file included from /home/adiletkutmanov/Development/lauda_measurement_napi/src/lauda_measurement.cpp:1:
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi.h:2347:9: note: ‘class Napi::TypedThreadSafeFunction<ContextType, DataType, CallJs>’ defined here
 2347 |   class TypedThreadSafeFunction {​​​​​​​
      |         ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi.h:2725,
                 from /home/adiletkutmanov/Development/lauda_measurement_napi/src/lauda_measurement.cpp:1:
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi-inl.h:4771:8: error: no declaration matches ‘Napi::TypedThreadSafeFunction<ContextType, DataType, CallJs>::TypedThreadSafeFunction(napi_threadsafe_function)’
 4771 | inline TypedThreadSafeFunction<ContextType, DataType, CallJs>::
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi-inl.h:4771:8: note: no functions named ‘Napi::TypedThreadSafeFunction<ContextType, DataType, CallJs>::TypedThreadSafeFunction(napi_threadsafe_function)’
In file included from /home/adiletkutmanov/Development/lauda_measurement_napi/src/lauda_measurement.cpp:1:
/home/adiletkutmanov/Development/lauda_measurement_napi/node_modules/node-addon-api/napi.h:2347:9: note: ‘class Napi::TypedThreadSafeFunction<ContextType, DataType, CallJs>’ defined here
 2347 |   class TypedThreadSafeFunction {​​​​​​​
      |         ^~~~~~~~~~~~~~~~~~~~~~~

Workarounds:

  • Use gcc 11 with c++17
  • Use gcc 10 with c++20

Activity

  1. KevinEady commented on Jun 3, 2021

    @KevinEady
    Contributor

    Hi @urp ,

    I am able to replicate this issue the example in the readme.

    Start container on gcc-11.1:

    docker run -it --rm -v $(pwd):/app gcc:11.1 /bin/bash
    

    And run these commands:

    apt-get update && apt-get install -y cmake
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
    
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    nvm install node
    
    cd /tmp
    git clone --branch add-typed-tsfn-example https://github.com/nodejs/node-addon-examples.git
    cd node-addon-examples/typed_threadsafe_function/node-addon-api
    npm i
    

    I have noticed that using c++20 on my Mac (Apple clang version 12.0.0 (clang-1200.0.32.29)) does work. Not sure exactly how to proceed. We can discuss in the Node-API weekly meeting

    cc: @mhdawson

  2. richardlau commented on Jun 3, 2021

    @richardlau
    Member
  3. KevinEady commented on Jun 10, 2021

    @KevinEady
    Contributor

    Thanks @richardlau for the insight! I am in the process of reporting the bug to GCC compiler team, currently waiting account creation.

    @urp, unfortunately I think we will have to go with "known incompatibility" until GCC updates their compiler; since other c++20 compilers work, it is strictly an issue with GCC.

    I will keep this issue open until I can link the GCC bug report in this ticket and our setup documentation page.

    Thanks, Kevin

  4. self-assigned this
    on Jun 10, 2021
  5. added 2 commits that reference this issue on Jun 11, 2021
    0a1b740
    dc25e0b
  6. KevinEady commented on Jun 11, 2021

    @KevinEady
    Contributor

    This issue will be fixed when the associated PR is merged.

    Thanks for reporting!

    Edit: Please see the not-a-bug bug report comment for more information.

  7. added a commit that references this issue on Sep 23, 2021
  8. added a commit that references this issue on Oct 15, 2021
  9. added a commit that references this issue on Aug 24, 2022
  10. added a commit that references this issue on Aug 26, 2022
  11. added a commit that references this issue on Sep 19, 2022
  12. added a commit that references this issue on Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions