savoirfairelinux / opendht

OpenDHT: a C++17 Distributed Hash Table implementation
GNU General Public License v3.0
1.03k stars 172 forks source link

can't compile correctly on the window platform #727

Open ac169 opened 2 weeks ago

ac169 commented 2 weeks ago

environment: win 10 + clion + vcpkg + VS 2022 toolchain opendht version: v3.2.0

Cmakelists.txt files in the source code are almost unavailable. Combining the current compilation environment rewriting CMAKELISTS.txt file,

...
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)

set(OPENDHT_HTTP ON)
set(OPENDHT_TOOLS OFF)
set(OPENDHT_PROXY_CLIENT ON)

list(APPEND opendht_SOURCES src/base64.h src/base64.cpp)

find_package(PkgConfig REQUIRED)

pkg_search_module(GnuTLS REQUIRED IMPORTED_TARGET gnutls)
pkg_search_module(Nettle REQUIRED IMPORTED_TARGET nettle)
pkg_search_module(OPENSSL REQUIRED IMPORTED_TARGET openssl)
pkg_search_module(argon2 REQUIRED IMPORTED_TARGET libargon2)

find_package(fmt CONFIG REQUIRED)
find_package(msgpack-cxx CONFIG REQUIRED)
find_package(Restinio CONFIG REQUIRED)
find_package(jsoncpp CONFIG REQUIRED)
find_package(unofficial-readline-win32 CONFIG REQUIRED)

add_definitions(-DOPENDHT_JSONCPP)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN -DSTATIC_GETOPT -DGNUTLS_INTERNAL_BUILD)

set(DISABLE_MSC_WARNINGS "/wd4101 /wd4244 /wd4267 /wd4273 /wd4804 /wd4834 /wd4996")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DISABLE_MSC_WARNINGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT")
...
  1. Configure the above option, compile error:
    include\opendht\infohash.h(254): error C2375: “dht::operator <<”: redefinition; different linkage

    Modify include\opendht\infohash.h the following modifications of the following, You can compile and generate the OpenDHT library file.

...
// template <size_t M>
// OPENDHT_PUBLIC friend std::ostream& operator<< (std::ostream& s, const Hash<M>& h);
template <size_t M> friend std::ostream& operator<< (std::ostream& s, const Hash<M>& h);
...
// template <size_t N> std::ostream& operator<< (std::ostream& s, const Hash<N>& h)
template <size_t N>
OPENDHT_PUBLIC std::ostream& operator<< (std::ostream& s, const Hash<N>& h)
...
  1. After turning on OpenDHT_C option, compile the error:
    opendht.cpp.obj : error LNK2001: unresolved external symbol "struct dht::HexMap const dht::hex_map" (?hex_map@dht@@3UHexMap@1@B)
    opendht.cpp.obj : error LNK2001: unresolved external symbol "public: static struct dht::ValueType const dht::ValueType::USER_DATA" (?USER_DATA@ValueType@dht@@2U12@B)
ac169 commented 1 week ago

https://github.com/savoirfairelinux/opendht/issues/722#issuecomment-2401481124

According to the version provided by the author, it has been successfully compiled after adapting to the CLion + VCPKG environment, but the problem encountered by dhtchat is also the same!

I hope the official can optimize the package management method of VCPKG.