我得到了以下cmake文件:
cmake_minimum_required(VERSION 3.17)
project(blsbench2)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
INCLUDE_DIRECTORIES(../../Documents/projects/bls-signatures/src)
LINK_DIRECTORIES(../../Documents/projects/bls-signatures/build/src)
LINK_DIRECTORIES(../../Documents/projects/bls-signatures/build/object_blstmp)
INCLUDE_DIRECTORIES(/usr/local/include/relic/)
LINK_DIRECTORIES(/usr/local/lib/)
add_executable(blsbench2 ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(blsbench2 bls relic)
和以下程序
#include <iostream>
#include <bls.hpp>
using namespace bls;
using namespace std;
int main()
{
std::cout << "Hello, World!" << std::endl;
uint8_t seed[] = {0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192,
19, 18, 12, 89, 6, 220, 18, 102, 58, 209,
82, 12, 62, 89, 110, 182, 9, 44, 20, 254, 22};
PrivateKey sk = PrivateKey::FromSeed(seed, sizeof(seed));
PublicKey pk = sk.GetPublicKey();
uint8_t msg[] = {100, 2, 254, 88, 90, 45, 23};
Signature sig = sk.Sign(msg, sizeof(msg));
return 0;
}
我正在使用CLion,并且上面的设置允许我包括库并使用功能自动完成。
当我尝试开始运行程序时出现问题。
/usr/bin/ld: CMakeFiles/blsbench2.dir/main.cpp.o: in function `main':
/home/ray/CLionProjects/blsbench2/main.cpp:16: undefined reference to `bls::PrivateKey::FromSeed(unsigned char const*, unsigned long)'
/usr/bin/ld: /home/ray/CLionProjects/blsbench2/main.cpp:17: undefined reference to `bls::PrivateKey::GetPublicKey() const'
/usr/bin/ld: /home/ray/CLionProjects/blsbench2/main.cpp:21: undefined reference to `bls::PrivateKey::Sign(unsigned char const*, unsigned long) const'
/usr/bin/ld: /home/ray/CLionProjects/blsbench2/main.cpp:16: undefined reference to `bls::PrivateKey::~PrivateKey()'
/usr/bin/ld: /home/ray/CLionProjects/blsbench2/main.cpp:16: undefined reference to `bls::PrivateKey::~PrivateKey()'
/usr/bin/ld: CMakeFiles/blsbench2.dir/main.cpp.o: in function `bls::Signature::~Signature()':
/home/ray/CLionProjects/blsbench2/../../Documents/projects/bls-signatures/src/signature.hpp:101: undefined reference to `bls::AggregationInfo::~AggregationInfo()'
collect2: error: ld returned 1 exit status
我在互联网上搜索了一下,它在一些地方说这是由于缺少.so文件(在这里可能会误解)。但是,该库会生成一个.a文件,该文件应该足够了。
最佳答案
这是由于bls
库是如何构建的。bls::PrivateKey
类在file静态库的一部分 blstmp
中实现。
您可以直接链接到blstmp
库,而不是bls
。这有效:您的程序运行正常。但这有点hacky。
这是由于CMake的问题:在构建依赖于静态库B的库A时,库B的对象文件未复制到库A中。因此,链接到A的程序也应链接到B。是关于CMake邮件列表上的discussion。
但这是bls
库的问题,将其报告给维护人员可能会很有用。
关于c++ -/usr/bin/ld:对静态库的 undefined reference ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62082018/