使用Boost中的random_device时出现链接错误

时间:2020-07-21 14:02:46

标签: c++ boost clang++

我已经使用brew安装 E: Error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. W: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. W: Unable to resolve superclass of Lano; (9320) W: Link of class 'Lano;' failed E: Could not find class 'ano', referenced from method amw.a W: VFY: unable to resolve new-instance 10218 (Lano;) in Lamw; D: VFY: replacing opcode 0x22 at 0x0006 W: Unable to resolve superclass of Lano; (9320) W: Link of class 'Lano;' failed D: DexOpt: unable to opt direct call 0xa2ef at 0x0a in Lamw;.a W: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:381) W: at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302) W: at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:270) W: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:162) W: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) W: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) W: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) W: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) W: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) W: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) W: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) W: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) W: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) W: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) W: at okhttp3.RealCall.execute(RealCall.java:77) W: at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) W: at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42) W: at io.reactivex.Observable.subscribe(Observable.java:11194) W: at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34) W: at io.reactivex.Observable.subscribe(Observable.java:11194) W: at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96) W: at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:463) W: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) W: at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) W: at java.util.concurrent.FutureTask.run(FutureTask.java:234) W: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) W: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) W: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) W: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) W: at java.lang.Thread.run(Thread.java:856) W: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. W: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:276) W: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:197) W: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:584) W: at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method) W: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378) W: ... 37 more W: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. W: ... 42 more Boost,在random_device旁边一切正常。

这是我写的:

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
toggle.setDrawerIndicatorEnabled(false);
    toggle.setHomeAsUpIndicator(R.drawable.ic_custom_drawer_icon);

这就是我从编译器中得到的:

x86_64体系结构的未定义符号:

“ boost :: random :: random_device :: random_device()”,引用自: _main in main.cpp.o

“ boost :: random :: random_device :: ~~ random_device()”,引用自: _main in main.cpp.o

“ boost :: random :: random_device :: operator()()”,引用自: _main in main.cpp.o

ld:架构x86_64找不到符号

clang:错误:链接器命令失败,退出代码为1(使用-v查看 调用)

我正在使用CMake进行链接。而且我也将其安装在MacOSX 10.15上,并得到了相同的链接错误。

这是我的CMake的一部分:

#include <iostream>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/discrete_distribution.hpp>
#include <boost/random/random_device.hpp>

int main() {
    boost::random::random_device rand_dev;
    boost::mt19937 gen(rand_dev());
    double probabilities[]{0, 0.99, 0.01, 0};
    boost::random::discrete_distribution<> dist(probabilities);
    std::cout << dist(gen);

    return 0;
}

2 个答案:

答案 0 :(得分:0)

在链接器输入中添加-lboost_random作为编译器命令行参数:

g++  -o  test  test.cpp  -lboost_random

答案 1 :(得分:0)

使用以下代码编辑您的CMakeLists.txt:

find_package(Boost 1.72 COMPONENTS random)
if(Boost_FOUND) 
    include_directories(${Boost_INCLUDE_DIRS}) 
    target_link_libraries(test_boost ${Boost_LIBRARIES}) 
endif()