raspptop和Linux Mint for Cryptopp程序需要不同的g ++编译选项吗?

时间:2014-11-26 06:02:46

标签: c++ linux g++ raspbian crypto++

这个问题并没有解决我需要解决的具体问题,这是一个关于解决方案原因的问题。

我在C ++中编写了一些依赖于cryptopp库的代码,特别是版本5.6.2。

我打算让这个代码最终在我的Raspberry Pi上运行(运行Raspbian),但它比我的笔记本电脑慢得多,所以我在Linux Mint中完成了所有的开发和测试。

在我的笔记本电脑上编译时,我使用了这个命令:

g++ -o sim-test sim.cpp -lcryptopp

今天我第一次在Raspberry Pi上运行了代码,遇到了问题。

特别是在尝试编译时我得到了这个:

/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libcryptopp.so: undefined reference to `pthread_key_create'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libcryptopp.so: undefined reference to `pthread_getspecific'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libcryptopp.so: undefined reference to `pthread_key_delete'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libcryptopp.so: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status

所以我尝试将pthread添加到路径中并且编译得很好。但是当我运行我的程序时,我立即得到了一个段错误。 GDB的堆栈跟踪相当长,但现在是:

#0  CryptoPP::BufferedTransformation::ChannelPut2 (this=0x6e080, channel=..., begin=0x6d624 "\330<\244\333\177\034a\216", length=8, messageEnd=0, blocking=true) at cryptlib.cpp:356
#1  0xb6e67248 in CryptoPP::StringStore::CopyRangeTo2 (this=<optimized out>, target=..., begin=@0xbefff238: 0, end=18446744073709551615, channel=..., blocking=true) at filters.cpp:1069
#2  0xb6e67198 in CryptoPP::StringStore::TransferTo2 (this=0xbefff4c0, target=..., transferBytes=@0xbefff268: 18446744073709551615, channel=..., blocking=true) at filters.cpp:1059
#3  0xb6e126a8 in TransferMessagesTo2 (blocking=true, channel=..., messageCount=@0xbefff2ac: 0, target=..., this=0xbefff4c0) at cryptlib.cpp:509
#4  CryptoPP::BufferedTransformation::TransferMessagesTo2 (this=0xbefff4c0, target=..., messageCount=@0xbefff2ac: 0, channel=..., blocking=true) at cryptlib.cpp:494
#5  0xb6e12890 in CryptoPP::BufferedTransformation::TransferAllTo2 (this=0xbefff4c0, target=..., channel=..., blocking=<optimized out>) at cryptlib.cpp:555
#6  0x0004ebb8 in CryptoPP::SourceTemplate<CryptoPP::StringStore>::PumpAll2(bool) ()
#7  0x0003668c in CryptoPP::Source::PumpAll() ()
#8  0x000366e4 in CryptoPP::Source::SourceInitialize(bool, CryptoPP::NameValuePairs const&) ()
#9  0x00036a80 in CryptoPP::StringSource::StringSource(std::string const&, bool, CryptoPP::BufferedTransformation*) ()
#10 0x00030a14 in AESEncrypt(std::string&, std::string&, unsigned char*, CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&) ()
#11 0x00032270 in Simulation(std::string&, std::string&, void (*)(CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&, int*), void (*)(CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&, unsigned char**, int*, CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&), void (*)(std::string&, std::string&, unsigned char*, CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&), void (*)(std::string&, std::string&, unsigned char*, CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&), void (*)(std::string&, std::string&, CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&), void (*)(std::string&, std::string&, CryptoPP::SecBlock<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, false> >&), int*, int*, int*) ()
#12 0x000326b0 in main ()

所以我做了一些搜索,我发现了这篇文章:

cryptopp on centos4.8 segmentation fault when link with pthread

提问者在他们的g ++命令中有-static,所以我想我会给它一个镜头,它有效!我的程序运行得很好,没有段错误!

要清楚这是我最后的g ++命令字符串:

g++ -o sim-test sim.cpp -lcryptopp -static -pthread

但之前它在Mint中运行得很好,为什么我需要更改命令字符串才能让它在Raspbian上运行?

我还应该注意到我已经测试了它,这个命令字符串在Mint编译并运行得很好......

0 个答案:

没有答案