Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling problem when using API with newer g++ version #29

Open
p4p4 opened this issue Oct 23, 2016 · 1 comment
Open

Compiling problem when using API with newer g++ version #29

p4p4 opened this issue Oct 23, 2016 · 1 comment

Comments

@p4p4
Copy link

p4p4 commented Oct 23, 2016

My project that uses MiniSat did not compile anymore after
updating from Ubuntu 15.10 to 16.10
The following error message was shown:

/home/patrick/uni/SEA/libs/minisat/mtl/Map.h:32:99: error: missing template arguments before ‘(’ token
 late<class K> struct Hash  { uint32_t operator()(const K& k)               const { return hash(k);  } };
                                                                                               ^

and

/home/patrick/uni/SEA/libs/minisat/mtl/Map.h: In member function ‘uint32_t Minisat::DeepHash<K>::operator()(const K*) const’:
/home/patrick/uni/SEA/libs/minisat/mtl/Map.h:35:103: error: missing template arguments before ‘(’ token
 class K> struct DeepHash  { uint32_t operator()(const K* k)               const { return hash(*k);  } };

I could only fix it by replacing those lines as described in the following commit:
see changes
I applied the changes after i compiled MiniSAT, but before I compiled my own tool that includes "minisat/core/Solver.h". That way everything works again, but I'm not sure if that's really the way to resolve the problem..

I am using CMake to link everything together

SET_SOURCE_FILES_PROPERTIES(MiniSatApi.cpp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-parentheses -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS")

Before upgrading Ubuntu everything worked just fine.

g++ version:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.2.0-5ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12) 

The same in Debian:
gcc version 6.1.1 20160802 (Debian 6.1.1-11)

However, if I switch to clang, everything works as usual.

Any ideas? Thank you in advance for your help!

@ShaswataJash
Copy link

If you analyze "mtl/Map.h" file in minisat, you can observe following lines at the very beginning of the header file -

template struct Hash { uint32_t operator()(const K& k) const { return hash(k); } };
template struct Equal { bool operator()(const K& k1, const K& k2) const { return k1 == k2; } };

template struct DeepHash { uint32_t operator()(const K* k) const { return hash(k); } };
template struct DeepEqual { bool operator()(const K
k1, const K* k2) const { return *k1 == *k2; } };

static inline uint32_t hash(uint32_t x){ return x; }
static inline uint32_t hash(uint64_t x){ return (uint32_t)x; }
static inline uint32_t hash(int32_t x) { return (uint32_t)x; }
static inline uint32_t hash(int64_t x) { return (uint32_t)x; }

The root-cause is g++ is not able to see declaration of hash() functions used within a templatized struct Hash, Equal, DeepHash and DeepEqual. In the included header also, there is no declaration of hash() function - actually, the functions are defined/declared just after their usage location :) Needless to say, the solution is as simple as ensuring static inline definition of overloaded hash() functions are brought up before their usage so that -std=c++11 compilation is able to find the declaration of hash() function. Thus the solution would be to rearrange the above lines as follows -

static inline uint32_t hash(uint32_t x){ return x; }
static inline uint32_t hash(uint64_t x){ return (uint32_t)x; }
static inline uint32_t hash(int32_t x) { return (uint32_t)x; }
static inline uint32_t hash(int64_t x) { return (uint32_t)x; }

template struct Hash { uint32_t operator()(const K& k) const { return hash(k); } };
template struct Equal { bool operator()(const K& k1, const K& k2) const { return k1 == k2; } };

template struct DeepHash { uint32_t operator()(const K* k) const { return hash(k); } };
template struct DeepEqual { bool operator()(const K
k1, const K* k2) const { return *k1 == *k2; } };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants