gpt4 book ai didi

c++ - add_library 没有使用 c 源代码创建 .lib

转载 作者:太空宇宙 更新时间:2023-11-04 04:13:18 25 4
gpt4 key购买 nike

我正在尝试使用来自库 https://github.com/trusch/libbcrypt 的 crypt blowfish 项目的 c 包装器还有一个 cpp 包装器围绕两个文件 bcrypt.c 和 bcrypt.h。我从源代码创建了一个 bcryptcpp.lib,但是当将它们与可执行文件一起使用时,我得到了 undefined symbol 错误。这是我的 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 个 header (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

最佳答案

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

dumpbin /EXPORTS bcryptcpp.lib

如果您将在 exports header 下看到您的函数,则表示您的库已正确编译,您需要检查库架构(x86x64) - 也许您将错误的库链接到您的另一个项目。

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

关于c++ - add_library 没有使用 c 源代码创建 .lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54825815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com