【发布时间】:2019-02-22 11:10:31
【问题描述】:
我正在尝试使用库 https://github.com/trusch/libbcrypt 中的 crypt 河豚项目周围的 c 包装器,以及两个文件 bcrypt.c 和 bcrypt.h 周围的 cpp 包装器。我从源代码创建了一个 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
【问题讨论】:
-
enable_language(ASM)仅启用汇编程序。您是否有project()调用,默认情况下启用 C 和 C++ 语言?为什么你认为 2KB 大小的库对于 6 个源文件来说太小了? “将它们与可执行文件一起使用时,我得到未定义的符号错误” - 将这些错误添加到问题帖子中。没有它,我们只能猜测出了什么问题。 -
抱歉,已添加到问题中。也是的,我有一个 project(),其中包括 c、c++。这个 cmake 文件只是一个包含。谢谢。