SSoelvsten / adiar

An I/O-efficient implementation of (Binary) Decision Diagrams
https://ssoelvsten.github.io/adiar/
MIT License
24 stars 13 forks source link

Adiar fails to compile #403

Closed lassemoldrup closed 1 year ago

lassemoldrup commented 1 year ago

Describe the bug Simply running make on my Mac (macOS version 12.4) fails to compile giving the following error:

[ 51%] Linking CXX static library libtpie.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libtpie.a(portability.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libtpie.a(portability.cpp.o) has no symbols
[ 51%] Built target tpie
[ 53%] Building CXX object src/adiar/CMakeFiles/adiar.dir/adiar.cpp.o
In file included from /Users/lasse/Code/adiar/src/adiar/adiar.cpp:1:
In file included from /Users/lasse/Code/adiar/src/adiar/adiar.h:24:
In file included from /Users/lasse/Code/adiar/src/adiar/../adiar/zdd.h:476:
/Users/lasse/Code/adiar/src/adiar/../adiar/zdd/build.h:113:22: error: no matching function for call to 'min'
      id_t curr_id = std::min(remaining_levels, max_id);
                     ^~~~~~~~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2532:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp'
      ('unsigned long' vs. 'unsigned long long')
min(const _Tp& __a, const _Tp& __b)
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2543:1: note: candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against
      'unsigned long'
min(initializer_list<_Tp> __t, _Compare __comp)
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2523:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2552:1: note: candidate function template not viable: requires single argument '__t', but 2 arguments
      were provided
min(initializer_list<_Tp> __t)
^
1 error generated.
make[5]: *** [src/adiar/CMakeFiles/adiar.dir/adiar.cpp.o] Error 1
make[4]: *** [src/adiar/CMakeFiles/adiar.dir/all] Error 2
make[3]: *** [src/adiar/CMakeFiles/adiar.dir/rule] Error 2
make[2]: *** [adiar] Error 2
make[1]: *** [build/static] Error 2
make: *** [build] Error 2

cmake --version: cmake version 3.24.1 clang --version: Apple clang version 11.0.3 (clang-1103.0.32.59)

To Reproduce N/A

Additional context The project has previously compiled, and I don't think I have done anything except update the library.

SSoelvsten commented 1 year ago

Duplicate of #317 .

SSoelvsten commented 1 year ago

@lassemoldrup , can you check whether branch bug/317 (#404) addresses this issue?

lassemoldrup commented 1 year ago

@SSoelvsten That seems to have fixed the error, but there is now a new one:

[ 56%] Building CXX object src/adiar/CMakeFiles/adiar.dir/bdd/apply.cpp.o
In file included from /Users/lasse/Code/adiar/src/adiar/bdd/apply.cpp:9:
/Users/lasse/Code/adiar/src/adiar/../adiar/internal/levelized_priority_queue.h:43:20: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  constexpr size_t no_lookahead_bound(const size_t degree = 1)
                   ^
/Users/lasse/Code/adiar/src/adiar/../adiar/internal/levelized_priority_queue.h:45:16: note: non-constexpr function 'pow<int, unsigned long>' cannot be used in a constant
      expression
    return 8 * std::pow(2, degree);
               ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/math.h:995:1: note: declared here
pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
^
SSoelvsten commented 1 year ago

Luckily a power of two is just the same as a left-shift, so std::pow can be replaced with (1 << degree). I assume there is another error that pops up now, @lassemoldrup ?

lassemoldrup commented 1 year ago

It compiles now 🎉

However, running make examples/queens gives a lot of linker warnings (only warnings) of the form

ld: warning: direct access in function 'tpie::priority_queue<adiar::prod_tuple_1, adiar::tuple_fst_lt, tpie::pq_overflow_heap<adiar::prod_tuple_1, adiar::tuple_fst_lt> >::init(unsigned long, unsigned long long)' from file '../src/adiar/libadiar.a(apply.cpp.o)' to global weak symbol 'typeinfo for tpie::exception' from file 'CMakeFiles/queens.dir/queens.cpp.o' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

Might also be related to clang?

SSoelvsten commented 1 year ago

That looks quite odd. Googling around says one should make sure the visibility is the same between the project, its subprojects and all their dependencies. Both TPIE and Adiar has in their respective CMakeLists.txt set the CXX_VISIBILITY_PRESET to hidden. My best guess would be, that this has something to do with a difference in Boost and how it was compiled?

lassemoldrup commented 1 year ago

I am using the Homebrew version of boost (v. 1.79), if that helps: https://formulae.brew.sh/formula/boost#default

SSoelvsten commented 1 year ago

Ubuntu ships with 1.71 but I cannot remember what version is on my Fedora machine. Can you try to manually change both the settings for Adiar and TPIE by setting their CXX_VISIBILITY_PRESET to default instead?

lassemoldrup commented 1 year ago

Changing the CXX_VISIBILITY_PRESET of just Adiar fixes the warning. I also noticed that one of the warnings generated by CMake is possibly related:

CMake Warning (dev) at external/tpie/tpie/CMakeLists.txt:224 (add_library):
  Policy CMP0063 is not set: Honor visibility properties for all target
  types.  Run "cmake --help-policy CMP0063" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "tpie" of type "STATIC_LIBRARY" has the following visibility
  properties set for CXX:

    CXX_VISIBILITY_PRESET

  For compatibility CMake is not honoring them for this target.
This warning is for project developers.  Use -Wno-dev to suppress it.
SSoelvsten commented 1 year ago

That seems odd - I need to read up on what is going on here. But, thanks for debugging with me. I might ask a few more questions another day.

lassemoldrup commented 1 year ago

No problem, feel free.

SSoelvsten commented 1 year ago

I created a pull request for TPIE which fixes that very CMake warning (see the pull request above that mentions this issue). Whether that truly fixes this problem I cannot say. What happens if you do the following?

cd external/tpie
git remote set-url origin https://github.com/SSoelvsten/tpie.git
git fetch
git checkout cmake/cleanup
cd ../../
make clean
make examples/queens

If not, then I guess I have to set CXX_VISIBILITY_PRESET for Adiar to default.

lassemoldrup commented 1 year ago

@SSoelvsten Using your TPIE branch sadly doesn't fix the CMake warning or the linker errors.

SSoelvsten commented 1 year ago

So #408 is a fix, @lassemoldrup ?

lassemoldrup commented 1 year ago

Yes, that fixes the linker warnings (but not the CMake warning).

SSoelvsten commented 1 year ago

What version of CMake are you using? The change for TPIE fixed the CMake warning on my version 3.22.2, as far as I could tell.

lassemoldrup commented 1 year ago

I am using version 3.24.1.