Opened 3 years ago

Closed 2 years ago

#5756 closed defect (fixed)

undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >

Reported by: elexis Owned by: wraitii
Priority: Release Blocker Milestone: Alpha 24
Component: Core engine Keywords:
Cc: Patch: Phab:D2745

Description

Can't compile the game on gcc 10 and clang 10:

Perhaps from r22207 which introduced the test.

Can't compile on gcc 10.1.0:

/usr/bin/ld: obj/test_Release/test_HierPathfinder.o: in function `TestHierarchicalPathfinder::assert_blank(HierarchicalPathfinder&)':
/home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:97: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: /home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:100: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: obj/test_Release/test_HierPathfinder.o: in function `TestHierarchicalPathfinder::test_reachability_and_update()':
/home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:164: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: /home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:167: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: /home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:189: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: obj/test_Release/test_HierPathfinder.o:/home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:202: more undefined references to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const' follow
collect2: error: ld returned 1 exit status
make[1]: *** [test.make:326: ../../../binaries/system/test] Error 1
make: *** [Makefile:187: test] Error 2

clang 10.0.0

/usr/bin/ld: obj/test_Release/test_HierPathfinder.o: in function `TestHierarchicalPathfinder::assert_blank(HierarchicalPathfinder&)':
/home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:97: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: /home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:100: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: obj/test_Release/test_HierPathfinder.o: in function `TestHierarchicalPathfinder::test_reachability_and_update()':
/home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:164: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: /home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:167: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: /home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:189: undefined reference to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const'
/usr/bin/ld: obj/test_Release/test_HierPathfinder.o:/home/elexis/code/0ad-svn5/trunk/source/simulation2/components/tests/test_HierPathfinder.h:202: more undefined references to `void HierarchicalPathfinder::FindReachableRegions<std::less<HierarchicalPathfinder::RegionID> >(HierarchicalPathfinder::RegionID, std::set<HierarchicalPathfinder::RegionID, std::less<HierarchicalPathfinder::RegionID>, std::allocator<HierarchicalPathfinder::RegionID> >&, unsigned short) const' follow
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [test.make:326: ../../../binaries/system/test] Error 1
make: *** [Makefile:187: test] Error 2

Change History (5)

comment:1 by wraitii, 3 years ago

Owner: set to wraitii

comment:2 by wraitii, 3 years ago

This appears to be the same issue as #5709

Based on the comments there and on https://stackoverflow.com/questions/8130602/using-extern-template-c11#comment26605821_8131212, I think we relied on the fact that an implicit instantiation in another TU was used, which seems to never have been guaranteed, and now it breaks.

Given that simply moving the definition to the header works and requires no additional headers, it seems, like on #5709, the best fix.

comment:3 by wraitii, 3 years ago

Patch: Phab:D2749

comment:4 by wraitii, 3 years ago

Patch: Phab:D2749Phab:D2745

comment:5 by Itms, 2 years ago

Resolution: fixed
Status: newclosed

In 23794:

Fix building on GCC 10, fixes #5709, #5756.

Patch By: pcpa and wraitii
Tested By: Nescio, andy5995 and others
Differential Revision: https://code.wildfiregames.com/D2745

Note: See TracTickets for help on using tickets.