randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.55k stars 561 forks source link

[Help wanted] Build "linking" error specific to QtCreator #2383

Closed OptoCloud closed 4 years ago

OptoCloud commented 4 years ago

Was building on windows using CMake and QtCreator (works fine with VS2019) and i got this error (which clearly isnt a linking error):

Output from QtCreator:

BUILD OUTPUT:
   INFO: F:/Source/C++/MyProject/libs/botan/configure.py invoked with options "--os=windows --cc=msvc --cpu=x86_64 --amalgamation --disable-shared --disable-modules=pkcs11 --without-documentation"
   INFO: Configuring to build Botan 2.15.0 (revision unknown)
   INFO: Running under 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]
   INFO: CXX environment variable is set which will override compiler path
   INFO: Implicit --cc-bin=C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe due to environment variable CXX
   INFO: Autodetected platform information: OS="Windows" machine="AMD64" proc="Intel64 Family 6 Model 158 Stepping 10, GenuineIntel"
   INFO: Auto-detected compiler version 19.16
   INFO: Auto-detected compiler arch x86_64
   INFO: Target is msvc:19.16-windows-x86_64
   INFO: Assuming target x86_64 is little endian
   INFO: Skipping (dependency failure): asio certstor_sqlite3 sessions_sqlite3
   INFO: Skipping (disabled by user): pkcs11
   INFO: Skipping (incompatible CPU): aes_armv8 aes_power8 sha1_armv8 sha2_32_armv8 sm4_armv8
   INFO: Skipping (incompatible OS): certstor_system_macos commoncrypto dev_random fd_unix getentropy proc_walk
   INFO: Skipping (incompatible compiler): clmul_cpu serpent_avx2 sha2_32_bmi2 sha2_64_bmi2 sha3_bmi2
   INFO: Skipping (no enabled compression schemes): compression
   INFO: Skipping (requires external dependency): boost bzip2 lzma openssl sqlite3 tpm zlib
   INFO: Loading modules: adler32 aead aes aes_ni aes_vperm aont argon2 aria asn1 auto_rng base base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 block blowfish camellia cascade cast128 cast256 cbc cbc_mac ccm cecpq1 certstor_flatfile certstor_sql certstor_system certstor_system_windows cfb chacha chacha20poly1305 chacha_avx2 chacha_rng chacha_simd32 checksum clmul_ssse3 cmac comb4p cpuid crc24 crc32 cryptobox ctr curve25519 des dh dl_algo dl_group dlies dsa dyn_load eax ec_group ecc_key ecdh ecdsa ecgdsa ecies eckcdsa ed25519 elgamal eme_oaep eme_pkcs1 eme_raw emsa1 emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy ffi filters fpe_fe1 gcm gmac gost_28147 gost_3410 gost_3411 hash hash_id hex hkdf hmac hmac_drbg hotp http_util idea idea_sse2 iso9796 kasumi kdf kdf1 kdf1_iso18033 kdf2 keccak keypair lion locking_allocator mac mce mceies md4 md5 mdx_hash mem_pool mgf1 misty1 mode_pad modes mp newhope nist_keywrap noekeon noekeon_simd numbertheory ocb ofb par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pgp_s2k pk_pad poly1305 poly_dbl prf_tls prf_x942 processor_rng psk_db pubkey rc4 rdrand_rng rdseed rfc3394 rfc6979 rmd160 rng roughtime rsa salsa20 scrypt seed serpent serpent_simd sessions_sql sha1 sha1_sse2 sha1_x86 sha2_32 sha2_32_x86 sha2_64 sha3 shacal2 shacal2_avx2 shacal2_simd shacal2_x86 shake shake_cipher simd simd_avx2 siphash siv skein sm2 sm3 sm4 socket sodium sp800_108 sp800_56a sp800_56c srp6 stateful_rng stream streebog system_rng thread_utils threefish_512 threefish_512_avx2 tiger tls tls_10 tls_cbc tss twofish utils uuid whirlpool win32_stats x509 x919_mac xmss xtea xts
   INFO: Using hardlink to link files into build dir (use --link-method to change)
  ERROR: Error linking F:/Source/C++/MyProject/libs/botan\src\lib\asn1\alg_id.h into build\include\botan: [WinError 17] The system cannot move the file to a different disk drive: 'F:/Source/C++/MyProject/libs/botan\\src\\lib\\asn1\\alg_id.h' -> 'build\\include\\botan\\alg_id.h'

CMake Error at libs/CMakeLists.txt:57 (message):
  Failed to build Botan

Output from VS2019:

1> [CMake] BUILD OUTPUT:
1> [CMake]    INFO: F:/Source/C++/MyProject/libs/botan/configure.py invoked with options "--os=windows --cc=msvc --cpu=x86_64 --amalgamation --disable-shared --disable-modules=pkcs11 --without-documentation"
1> [CMake]    INFO: Configuring to build Botan 2.15.0 (revision git:f8d4ba1455b351849fa273d50bd62461daa70954)
1> [CMake]    INFO: Running under 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]
1> [CMake]    INFO: Autodetected platform information: OS="Windows" machine="AMD64" proc="Intel64 Family 6 Model 158 Stepping 10, GenuineIntel"
1> [CMake]    INFO: Auto-detected compiler version 19.26
1> [CMake]    INFO: Auto-detected compiler arch x86_64
1> [CMake]    INFO: Target is msvc:19.26-windows-x86_64
1> [CMake]    INFO: Assuming target x86_64 is little endian
1> [CMake]    INFO: Skipping (dependency failure): asio certstor_sqlite3 sessions_sqlite3
1> [CMake]    INFO: Skipping (disabled by user): pkcs11
1> [CMake]    INFO: Skipping (incompatible CPU): aes_armv8 aes_power8 sha1_armv8 sha2_32_armv8 sm4_armv8
1> [CMake]    INFO: Skipping (incompatible OS): certstor_system_macos commoncrypto dev_random fd_unix getentropy proc_walk
1> [CMake]    INFO: Skipping (incompatible compiler): clmul_cpu serpent_avx2 sha2_32_bmi2 sha2_64_bmi2 sha3_bmi2
1> [CMake]    INFO: Skipping (no enabled compression schemes): compression
1> [CMake]    INFO: Skipping (requires external dependency): boost bzip2 lzma openssl sqlite3 tpm zlib
1> [CMake]    INFO: Loading modules: adler32 aead aes aes_ni aes_vperm aont argon2 aria asn1 auto_rng base base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 block blowfish camellia cascade cast128 cast256 cbc cbc_mac ccm cecpq1 certstor_flatfile certstor_sql certstor_system certstor_system_windows cfb chacha chacha20poly1305 chacha_avx2 chacha_rng chacha_simd32 checksum clmul_ssse3 cmac comb4p cpuid crc24 crc32 cryptobox ctr curve25519 des dh dl_algo dl_group dlies dsa dyn_load eax ec_group ecc_key ecdh ecdsa ecgdsa ecies eckcdsa ed25519 elgamal eme_oaep eme_pkcs1 eme_raw emsa1 emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy ffi filters fpe_fe1 gcm gmac gost_28147 gost_3410 gost_3411 hash hash_id hex hkdf hmac hmac_drbg hotp http_util idea idea_sse2 iso9796 kasumi kdf kdf1 kdf1_iso18033 kdf2 keccak keypair lion locking_allocator mac mce mceies md4 md5 mdx_hash mem_pool mgf1 misty1 mode_pad modes mp newhope nist_keywrap noekeon noekeon_simd numbertheory ocb ofb par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pgp_s2k pk_pad poly1305 poly_dbl prf_tls prf_x942 processor_rng psk_db pubkey rc4 rdrand_rng rdseed rfc3394 rfc6979 rmd160 rng roughtime rsa salsa20 scrypt seed serpent serpent_simd sessions_sql sha1 sha1_sse2 sha1_x86 sha2_32 sha2_32_x86 sha2_64 sha3 shacal2 shacal2_avx2 shacal2_simd shacal2_x86 shake shake_cipher simd simd_avx2 siphash siv skein sm2 sm3 sm4 socket sodium sp800_108 sp800_56a sp800_56c srp6 stateful_rng stream streebog system_rng thread_utils threefish_512 threefish_512_avx2 tiger tls tls_10 tls_cbc tss twofish utils uuid whirlpool win32_stats x509 x919_mac xmss xtea xts
1> [CMake]    INFO: Using hardlink to link files into build dir (use --link-method to change)
1> [CMake]    INFO: Writing amalgamation header to botan_all.h
1> [CMake]    INFO: Writing amalgamation source to botan_all.cpp
1> [CMake]    INFO: Botan 2.15.0 (revision git:f8d4ba1455b351849fa273d50bd62461daa70954) (unreleased undated) build setup is complete

The files were not altered between the builds

randombit commented 4 years ago

Ah interesting, this would also affect Unix since hard links are not allowed to cross fs boundary.

Workaround pass --link-method=copy

Probably we want to stop using hardlink unless explicitly requested by user. Or alternately test to see if it is possible, and if not fall back to copy.

ncoder-1 commented 4 years ago

I use QTCreator with CMake and can't reproduce, although I have a custom .cmake file only for Botan. Let me know if you need it.

ETA: On Linux.

OptoCloud commented 4 years ago

I use QTCreator with CMake and can't reproduce, although I have a custom .cmake file only for Botan. Let me know if you need it.

ETA: On Linux.

I ended up with this for building the CMake library used by both the server and the client:

cmake_minimum_required(VERSION 3.5)

set(project StaticLib)
project(
    ${project}
    DESCRIPTION "Library that is used by both the server and the client"
    LANGUAGES CXX
)

message("Configuring ${project}...")

if(UNIX AND NOT APPLE)
    set(LINUX TRUE)
    set(OS_STR "Linux")
elseif(WIN32)
    set(WINDOWS TRUE)
    set(OS_STR "Windows")
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(LINUX)
    # 64-bit, threading, and verbose
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -pthread -Wall -Wextra -pedantic")

    if(${CMAKE_BUILD_TYPE} MATCHES "Release")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector -O3 -g0")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g3")
    endif()

    # Very verbose!
    if (VERBOSE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --verbose")
    endif()
elseif(WINDOWS)
    if(${CMAKE_BUILD_TYPE} MATCHES "Release")
        set(WIN_DEBUG_FLAG "/DEBUG:NONE")
        set(WIN_OPTIMIZATION_FLAG "/O2")
    else()
        set(WIN_DEBUG_FLAG "/DEBUG:FULL")
        set(WIN_OPTIMIZATION_FLAG "/Od")
    endif()

    # Stop botan from f****** up
    add_definitions(/DNOMINMAX /DBOTAN_IS_BEING_BUILT)

    # Force to always compile with W4
    if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
        string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
    endif()

    # Force to always compile with MT
    if(CMAKE_CXX_FLAGS MATCHES "/MDd?|/MTd?|/LDd?")
        string(REGEX REPLACE "/MDd?|/MTd?|/LDd?" "/MT" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
    endif()

    # Force to always compile with /O2 or /Od
    if(CMAKE_CXX_FLAGS MATCHES "/O.?")
        string(REGEX REPLACE "/O.?" ${WIN_OPTIMIZATION_FLAG} CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WIN_OPTIMIZATION_FLAG}")
    endif()

    # Force to always compile with DEBUG:XXXX
    if(CMAKE_CXX_FLAGS MATCHES "/DEBUG\:[^\\s]+")
        string(REGEX REPLACE "/DEBUG\:[^\\s]+" ${WIN_DEBUG_FLAG} CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WIN_DEBUG_FLAG}")
    endif()

    # Botan build is pretty big
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif()

if (NOT EXISTS ${CMAKE_BINARY_DIR}/botan_all.h)
    # Set OS specific arguments
    if(LINUX)
        set(BUILD_OS "linux")
        set(BUILD_COMPILER "gcc")
    elseif(WINDOWS)
        set(BUILD_OS "windows")
        set(BUILD_COMPILER "msvc")
    endif()

    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
        set(BUILD_ARCH "x86_64")
    elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
        set(BUILD_ARCH "i386")
    endif()

    # Set python initial arguments
    set(PYTHON_ARGS
        "${CMAKE_CURRENT_SOURCE_DIR}/botan/configure.py"
        "--os=${BUILD_OS}"
        "--cc=${BUILD_COMPILER}"
        "--cpu=${BUILD_ARCH}"
        "--amalgamation"
        "--disable-shared"
        "--link-method=copy"
        "--disable-modules=pkcs11"
        "--without-documentation"
    )

    # Crossing fingers....
    execute_process(
        COMMAND "python" ${PYTHON_ARGS}
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
        RESULT_VARIABLE py_result
        OUTPUT_VARIABLE py_output
    )

    # Print the output
    message("BUILD OUTPUT:\n${py_output}")

    # If it returned something else than 0 it probably didnt succeed
    if (NOT ${py_result} EQUAL 0)
        message(FATAL_ERROR "Failed to build Botan")
    endif()
endif()

add_library(${project} STATIC
    ${CMAKE_BINARY_DIR}/botan_all.cpp
    ${CMAKE_BINARY_DIR}/botan_all.h
    ${CMAKE_CURRENT_SOURCE_DIR}/enums.h
    ${CMAKE_CURRENT_SOURCE_DIR}/constants.h
    ${CMAKE_CURRENT_SOURCE_DIR}/message.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/message.h
    ${CMAKE_CURRENT_SOURCE_DIR}/crypto.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/crypto.h
    ${CMAKE_CURRENT_SOURCE_DIR}/enet/include/enet.h
)

set(LIB_INC_DIRS
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/enet/include
    ${CMAKE_BINARY_DIR}

    CACHE PATH "List of library directories for header includes"
)

include_directories(${LIB_INC_DIRS})

if(WINDOWS)
    target_link_libraries(${project} Crypt32)
endif()