Skip to content

Question: Build issues due to missing declaration of std::function

I have never used bazel before, therefore this might be just an user error:

  1. I am on Ubuntu 24.04 and installed bazelisk 1.25.0 via .deb package
  2. I cloned this repo and ran bazel build --config=gt_gen //Cli/... //Simulator/...
  3. For me, this results in the following build log (repeated call and thus truncated to the error)
$ bazel build --config=gt_gen //Cli/... //Simulator/...
INFO: Build options --compilation_mode, --cxxopt, --define, and 4 more have changed, discarding analysis cache.
INFO: Analyzed 65 targets (143 packages loaded, 10639 targets configured).
INFO: Found 65 targets...
ERROR: /home/timm/MiscProjects/gt-gen-simulator/Cli/BUILD.bazel:4:10: Compiling Cli/main.cpp failed: (Exit 1): gcc failed: error executing command (from target //Cli:gtgen_cli) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g '-std=c++0x' -MD -MF ... (remaining 727 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from ./Cli/cli.h:15,
                 from Cli/main.cpp:11:
./Simulator/Utils/UserData/user_data_manager.h:50:9: error: 'std::function' has not been declared
   50 |         std::function<fs::path()> get_gtgen_data_directory = DataPathHandler::GetDefaultGtGenDataDirectory,
      |         ^~~
./Simulator/Utils/UserData/user_data_manager.h:50:22: error: expected ',' or '...' before '<' token
   50 |         std::function<fs::path()> get_gtgen_data_directory = DataPathHandler::GetDefaultGtGenDataDirectory,
      |                      ^
./Simulator/Utils/UserData/user_data_manager.h:80:10: error: 'function' in namespace 'std' does not name a template type
   80 |     std::function<fs::path()> get_gtgen_data_directory_{nullptr};
      |          ^~~~~~~~
./Simulator/Utils/UserData/user_data_manager.h:18:1: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
   17 | #include "Simulator/Utils/UserData/data_path_handler.h"
  +++ |+#include <functional>
   18 | 
./Simulator/Utils/UserData/user_data_manager.h:80:65: error: extra ';' [-Werror=pedantic]
   80 |     std::function<fs::path()> get_gtgen_data_directory_{nullptr};
      |                                                                 ^
      |                                                                 -
./Simulator/Utils/UserData/user_data_manager.h:81:10: error: 'function' in namespace 'std' does not name a template type
   81 |     std::function<fs::path()> install_source_directory_{nullptr};
      |          ^~~~~~~~
./Simulator/Utils/UserData/user_data_manager.h:81:5: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
   81 |     std::function<fs::path()> install_source_directory_{nullptr};
      |     ^~~
./Simulator/Utils/UserData/user_data_manager.h:81:65: error: extra ';' [-Werror=pedantic]
   81 |     std::function<fs::path()> install_source_directory_{nullptr};
      |                                                                 ^
      |                                                                 -
cc1plus: all warnings being treated as errors
INFO: Elapsed time: 22.848s, Critical Path: 21.20s
INFO: 68 processes: 41 internal, 27 processwrapper-sandbox.
FAILED: Build did NOT complete successfully

Simply adding #include <functional> to the user_data_manager.h solves the issue. It seems like using std::function once relayed on transitive inclusions? Nonetheless, I do not understand why the projects CI is not failing on this as well.

Further information:

$ git show -s 
commit dcce8b344c4918be6c1e6d56f89d8276d4afd254 (HEAD -> main, tag: v8.0.0, origin/main, origin/HEAD)
Merge: de90291 845e348
Author: Ziqi Zhou <ziqi.zhou@ansys.com>
Date:   Thu Nov 21 12:51:24 2024 +0000

    Merge branch 'feat/integrate-simplify-positioning-for-multiple-supp-signs' into 'main'
    
    Feat: integrate simplify positioning for multiple supp signs
    
    See merge request eclipse/openpass/gt-gen-simulator!64

$ bazel --version
bazel 6.2.1

$ gcc --version
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.1 LTS
Release:	24.04
Codename:	noble
Edited by Timm Ruppert