[英]add_library is not creating a .lib with c sources
I'm trying to use the c wrapper around the crypt blowfish project, from library https://github.com/trusch/libbcrypt also with a cpp wrapper around the two files bcrypt.c and bcrypt.h. 我正在尝试使用来自库https://github.com/trusch/libbcrypt的crypt blowfish项目周围的c包装器以及两个文件bcrypt.c和bcrypt.h的cpp包装器。 I create a bcryptcpp.lib from the sources but when using them with an executable I get undefined symbol errors.
我从源代码创建了一个bcryptcpp.lib,但是当将它们与可执行文件一起使用时,会出现未定义的符号错误。 Here's my cmakelists.txt -
这是我的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"
)
The bcryptcpp.lib that is generated by visual studio is only 2kb. Visual Studio生成的bcryptcpp.lib仅2kb。 Would it be that the c files aren't compiled?
不会编译c文件吗? What could be the issue here?
这里可能是什么问题?
The errors are as follows, generated when compiling a test executable which includes only the 3 headers in the library link mentioned above (BCrypt.hpp, BCrypt.cpp, winbcrypt.h) - 错误如下,是在编译包含上述链接(BCrypt.hpp,BCrypt.cpp,winbcrypt.h)中仅包含3个标头的测试可执行文件时生成的-
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
The output of dumpbin /EXPORTS bcryptcpp.lib
shows no exports, so I'm guessing its wrongly compiled - dumpbin /EXPORTS bcryptcpp.lib
的输出dumpbin /EXPORTS bcryptcpp.lib
显示任何导出,因此我猜测其编译错误-
Dump of file bcryptcpp.lib
File Type: LIBRARY
Summary
20 .chks64
43C .debug$S
74 .debug$T
30 .drectve
For understanding a reason of problem ( CMakeLists.txt or bad linking in another project ) You need to check your .lib file. 为了理解问题的原因( CMakeLists.txt或另一个项目中的链接错误 ),您需要检查.lib文件。 Try to find export symbols in bcryptcpp.lib via dumpbin .
尝试通过dumpbin在bcryptcpp.lib中找到导出符号。 Open a visual command console and run the next command:
打开可视命令控制台并运行下一个命令:
dumpbin /EXPORTS bcryptcpp.lib
If you will see your functions under the exports header it means your library is right compiled and you need to check a library architecture ( x86 , x64 ) - maybe you link a wrong library to your another project. 如果在exports标题下看到函数,则表明您的库已正确编译,并且需要检查库体系结构( x86 , x64 )-也许您将错误的库链接到另一个项目。
In another case, the problem in CMakeLists.txt . 在另一种情况下, CMakeLists.txt中的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.