compiling problems with flat_hash_map

868 views
Skip to first unread message

LinuxFre eBird

unread,
Jul 4, 2020, 8:07:03 PM7/4/20
to abse...@googlegroups.com
Hello Abseil Representatives

Using either cmake or g++ I am able to compile my code with absl::btree_map with no issues, but including absl::flat_hash_map does not compile for me. The compiling error I get is shown below.

`absl::container_internal::HashtablezInfoHandle::~HashtablezInfoHandle()':
benchmark_containers.cpp:(.text._ZN4absl18container_internal20HashtablezInfoHandleD2Ev[_ZN4absl18container_internal20HashtablezInfoHandleD5Ev]+0x33): undefined reference to `absl::container_internal::UnsampleSlow(absl::container_internal::HashtablezInfo*)'
collect2: error: ld returned 1 exit status

My build command is shown below

g++ -I "~/Source/CMakeProject/install/include" -std=c++17 benchmark_containers.cpp -o benchmark_containers.out -ltcmalloc 2>&1 | tee out.txt

My cpp script is shown below

#include "~/Source/CMakeProject/install/include/absl/container/btree_map.h"
#include "~/Source/CMakeProject/install/include/absl/container/flat_hash_map.h"

int main()
{
  absl::btree_map<int,int> _btm;
  absl::flat_hash_map<int,int> _fhm;
  ... 
  return 0;
}

What should I do?

Sincerely,

Benjamin Commeau

Andy Getzendanner

unread,
Jul 6, 2020, 4:18:16 PM7/6/20
to LinuxFre eBird, abse...@googlegroups.com
Your compile command does not link in any Abseil libraries, so the linker is unable to find definitions for things declared in Abseil's headers but defined in its .cc files.  You should use either CMake or Bazel to specify your binary's dependence on Abseil's flat_hash_map library (the build system will take care of any transitive dependencies).  The portions of btree_map you used must be header-only (not uncommon for templated types).

--
You received this message because you are subscribed to the Google Groups "Abseil.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to abseil-io+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/abseil-io/CA%2Bf1ixFCFhhjw5x4o3DD9Ftxhf5yR8AiCoAyL3_04arFgUGjfg%40mail.gmail.com.

LinuxFre eBird

unread,
Jul 6, 2020, 10:59:36 PM7/6/20
to Andy Getzendanner, abse...@googlegroups.com
Thank you! I was able to compile flat_hash_map. May I ask, how do I generate a hash from a pair of ints?

Andy Getzendanner

unread,
Jul 7, 2020, 12:36:57 AM7/7/20
to LinuxFre eBird, abse...@googlegroups.com
Like this, I think:
absl::Hash<std::pair<int, int>>()({5, 7})

You should be able to use e.g. an absl::flat_hash_set<std::pair<int, int>> without passing a custom hasher.
Message has been deleted

aditya sharma

unread,
Oct 7, 2024, 7:20:08 AM10/7/24
to Abseil.io
hi LinuxFre eBird,

what libraries you used to link , for successfull compilation of abs::flat_hash_map
I too am facing similar issue explained below.
aditya sharma
3:43 PM (1 hour ago) 
to Abseil.io
I am getting below error while compiling the absl::flat_hash_map sample program
hash.cc:(.text+0x60): undefined reference to `absl::lts_20230802::hash_internal::CityHash32(char const*, unsigned long)'

helloworld.cpp
#include <iostream>
#include "absl/container/flat_hash_map.h"
int main() {
absl::flat_hash_map<int, std::string> map = {{1, "huey"}, {2, "dewey"}, {3, "louie"}};
for (auto it = map.begin(); it != map.end();) {
std::cout<<"it->second[0]"<<it->second[0];it++;
}
return 0;
}
the compile command is as below:
g++ -std=c++17 hello_world.cpp -o newout -L{installDir}/lib64 -labsl_hash -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_synchronization -labsl_raw_logging_internal -labsl_base -I {installDir}/include



Rana Usman

unread,
Oct 11, 2024, 4:08:25 PM10/11/24
to aditya sharma, Abseil.io

Lan put lao pyooo pyoo hi hunda😅


Sourabh Goel

unread,
Feb 18, 2025, 9:01:34 AMFeb 18
to Abseil.io
I am facing the same problem. Could you please share your command on how to compile the sample program? Earlier you were using " g++ -I "~/Source/CMakeProject/install/include" -std=c++17 benchmark_containers.cpp -o benchmark_containers.out -ltcmalloc 2>&1 | tee out.txt "
What changes did you make in this command to make your compilation successful?
On Tuesday, July 7, 2020 at 8:29:36 AM UTC+5:30 LinuxFre eBird wrote:
Reply all
Reply to author
Forward
0 new messages