fix(i2p): Windows link order — i2pd archives + Boost/zlib sandwich

The linker needs to see i2pd archives, then Boost/zlib to resolve
their symbols, then i2pd archives AGAIN to resolve any remaining
references. Added raw -l fallbacks for MinGW where Boost:: CMake
imported targets may not exist even though libs are installed.
This commit is contained in:
Krystie
2026-06-28 16:47:21 -07:00
parent 045bc36716
commit 8e6c6b36bf
+30 -11
View File
@@ -234,31 +234,50 @@ if(USE_I2P_EMBEDDED)
) )
# i2pd builds as two static libraries: libi2pd.a (core router) and # i2pd builds as two static libraries: libi2pd.a (core router) and
# libi2pd_client.a (SAM, SOCKS, tunnels, client context). Both are needed. # libi2pd_client.a (SAM, SOCKS, tunnels, client context). Both are needed.
# The static libs have circular inter-dependencies. Rather than using # The static libs have circular inter-dependencies and also reference
# --start-group/--end-group (which CMake mis-orders with Ninja), we # Boost (filesystem, program_options) and zlib symbols. On MinGW the
# list each archive twice so the linker resolves all symbols in two # Boost:: targets may not exist as CMake imported targets even though
# left-to-right passes. # the libraries are installed, so we use raw -l flags as a fallback.
target_link_libraries(triangles_common PUBLIC target_link_libraries(triangles_common PUBLIC
"${I2P_SOURCE_ROOT}/libi2pdclient.a" "${I2P_SOURCE_ROOT}/libi2pdclient.a"
"${I2P_SOURCE_ROOT}/libi2pd.a" "${I2P_SOURCE_ROOT}/libi2pd.a"
"${I2P_SOURCE_ROOT}/libi2pdlang.a" "${I2P_SOURCE_ROOT}/libi2pdlang.a"
"${I2P_SOURCE_ROOT}/libi2pdclient.a" "${I2P_SOURCE_ROOT}/libi2pdclient.a"
"${I2P_SOURCE_ROOT}/libi2pd.a" "${I2P_SOURCE_ROOT}/libi2pd.a"
Boost::program_options Boost::thread Boost::chrono )
# Boost and zlib dependencies of i2pd — these MUST come after the
# archives in link order so unresolved symbols get satisfied.
if(TARGET Boost::filesystem)
target_link_libraries(triangles_common PUBLIC Boost::filesystem)
elseif(WIN32)
target_link_libraries(triangles_common PUBLIC boost_filesystem-mt)
endif()
if(TARGET Boost::system)
target_link_libraries(triangles_common PUBLIC Boost::system)
elseif(WIN32)
target_link_libraries(triangles_common PUBLIC boost_system-mt)
endif()
if(TARGET Boost::program_options)
target_link_libraries(triangles_common PUBLIC Boost::program_options)
elseif(WIN32)
target_link_libraries(triangles_common PUBLIC boost_program_options-mt)
endif()
target_link_libraries(triangles_common PUBLIC
Boost::thread Boost::chrono
OpenSSL::SSL OpenSSL::Crypto OpenSSL::SSL OpenSSL::Crypto
ZLIB::ZLIB ZLIB::ZLIB
) )
# List the archives again after Boost/zlib so the linker can resolve
# any remaining i2pd→Boost references in a second pass.
target_link_libraries(triangles_common PUBLIC
"${I2P_SOURCE_ROOT}/libi2pd.a"
"${I2P_SOURCE_ROOT}/libi2pdclient.a"
)
if(WIN32) if(WIN32)
target_link_libraries(triangles_common PUBLIC target_link_libraries(triangles_common PUBLIC
-Wl,--allow-multiple-definition -Wl,--allow-multiple-definition
) )
endif() endif()
if(TARGET Boost::filesystem)
target_link_libraries(triangles_common PUBLIC Boost::filesystem)
endif()
if(TARGET Boost::system)
target_link_libraries(triangles_common PUBLIC Boost::system)
endif()
endif() endif()
# Platform-specific libraries # Platform-specific libraries