add_library没有使用c源创建.lib

问题描述 投票:1回答:1

我正试图在crypt blowfish项目周围使用c包装器,从库https://github.com/trusch/libbcrypt到ccry包装器周围的两个文件bcrypt.c和bcrypt.h。我从源代码创建了一个bcryptcpp.lib但是当它与可执行文件一起使用时,我得到了未定义的符号错误。这是我的cmakelists.txt -

# BCrypt CPP
enable_language(ASM)

set(CMAKE_ASM_FLAGS "${CXXFLAGS} -x assembler-with-cpp")

include_directories( ${CMAKE_CURRENT_SOURCE_DIR})
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3)

set(BCRYPT_SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/BCrypt.hpp
    ${CMAKE_CURRENT_SOURCE_DIR}/BCrypt.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/WinBCrypt.hpp
    ${CMAKE_CURRENT_SOURCE_DIR}/bcrypt.c
    ${CMAKE_CURRENT_SOURCE_DIR}/bcrypt.h
    ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3/crypt_blowfish.c
    ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3/crypt_blowfish.h
    ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3/crypt_gensalt.c
    ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3/crypt_gensalt.h
    ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3/wrapper.c
    ${CMAKE_CURRENT_SOURCE_DIR}/crypt_blowfish-1.3/x86.S
)

add_library(bcryptcpp
    STATIC
        ${BCRYPT_SOURCES})

set_target_properties(bcryptcpp
    PROPERTIES
        VERSION "${PROJECT_VERSION}"
        PUBLIC_HEADER BCrypt.hpp
        LINKER_LANGUAGE CXX
        FOLDER "BCrypt"
)

visual studio生成的bcryptcpp.lib只有2kb。是不是编译了c文件?这可能是什么问题?

编译测试可执行文件时生成的错误如下,其中只包含上述库链接中的3个头文件(BCrypt.hpp,BCrypt.cpp,winbcrypt.h) -

Severity    Code    Description Project File    Line    Suppression State
Error   LNK1120 3 unresolved externals  BCryptTest  C:\Program Files (x86)\Horizon\test\Debug\BCryptTest.exe    1   
Error   LNK2019 unresolved external symbol _bcrypt_gensalt referenced in function "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl BCrypt::generateHash(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?generateHash@BCrypt@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@H@Z)    BCryptTest  C:\Users\sagun\horizon-cpp\build\src\Tests\BCryptTest.obj   1   
Error   LNK2019 unresolved external symbol _bcrypt_hashpw referenced in function "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl BCrypt::generateHash(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?generateHash@BCrypt@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@H@Z) BCryptTest  C:\Users\sagun\horizon-cpp\build\src\Tests\BCryptTest.obj   1   
Error   LNK2019 unresolved external symbol _bcrypt_checkpw referenced in function "public: static bool __cdecl BCrypt::validate_password(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?validate_password@BCrypt@@SA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) BCryptTest  C:\Users\sagun\horizon-cpp\build\src\Tests\BCryptTest.obj   1   

dumpbin /EXPORTS bcryptcpp.lib的输出显示没有出口,所以我猜错了编译 -

Dump of file bcryptcpp.lib

File Type: LIBRARY

  Summary

          20 .chks64
         43C .debug$S
          74 .debug$T
          30 .drectve
c++ c cmake bcrypt
1个回答
0
投票

要了解问题的原因(CMakeLists.txt或另一个项目中的错误链接)您需要检查.lib文件。尝试通过dumpbin在bcryptcpp.lib中查找导出符号。打开可视命令控制台并运行下一个命令:

dumpbin /EXPORTS bcryptcpp.lib

如果您将在导出标题下看到您的函数,则表示您的库已正确编译,您需要检查库体系结构(x86,x64) - 也许您将错误的库链接到另一个项目。

在另一种情况下,CMakeLists.txt中的问题。

© www.soinside.com 2019 - 2024. All rights reserved.