2016-06-19 97 views
0

我使用創建共享庫的鏈接未定義參考

arm-linux-gnueabi-g++ -Wall -fPIC -c -I../../../onvifgen -I. *.cpp -include openssl/all.h -fpermissive -DWITH_OPENSSL 
arm-linux-gnueabi-g++ -shared -fPIC -Wl,-soname,libonvif.so.1 -o libonvif.so.1.0 *.o 
ln -sf libonvif.so.1.0 libonvif.so.1 
ln -sf libonvif.so.1.0 libonvif.so 

構建一個共享庫當我嘗試使用我得到了很多的

../../../../binaries/lib/libonvif.so: undefined reference to 

該庫是命令我使用

arm-linux-gnueabi-g++ -I../../../../binaries/include -I../../../include -fpermissive -include ../../../../binaries/include/openssl/all.h -w -o test1 onvifclient.cpp -L../../../../binaries/lib -lonvif -lssl -lcrypto -lpthread -DWITH_OPENSSL 

如命令中所示-lonvif位於輸入文件onvifclient.cpp之後,因此鏈接器應該找到它。

使用來自相同目標文件的靜態庫文件.o作品和鏈接程序生成可執行文件。

我在SO上找到的所有答案都與訂購有關。

更多的錯誤:

../../../../binaries/lib/libonvif.so: undefined reference to `ReceiverBindingService::CreateReceiver(_trv__CreateReceiver*, _trv__CreateReceiverResponse*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `PullPointSubscriptionBindingService::PullMessages(_tev__PullMessages*, _tev__PullMessagesResponse*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `ReceiverBindingService::GetReceiver(_trv__GetReceiver*, _trv__GetReceiverResponse*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `RecordingBindingService::GetRecordingJobState(_trc__GetRecordingJobState*, _trc__GetRecordingJobStateResponse*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `PullPointSubscriptionBindingService::Renew_(_wsnt__Renew*, _wsnt__RenewResponse*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `MediaBindingService::GetVideoEncoderConfigurations(_trt__GetVideoEncoderConfigurations*, _trt__GetVideoEncoderConfigurationsResponse*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `wsddService::Resolve(wsdd__ResolveType*)' 
../../../../binaries/lib/libonvif.so: undefined reference to `MediaBindingService::GetAudioDecoderConfiguration_(_trt__GetAudioDecoderConfiguration*, _trt__GetAudioDecoderConfigurationResponse*)' 
+ 100+ more errors but other functions. 

所有這些功能都在cpp文件中發現和確定的權利。

使用nm libonvif.so -C| grep MediaBindingService::GetVideoEncoderConfigurations

我得到的結果folwing。

 U MediaBindingService::GetVideoEncoderConfigurations(_trt__GetVideoEncoderConfigurations*, _trt__GetVideoEncoderConfigurationsResponse*) 
    U MediaBindingService::GetVideoEncoderConfigurations_(_trt__GetVideoEncoderConfigurations*, _trt__GetVideoEncoderConfigurationsResponse*) 

MediaBindingService::GetVideoEncoderConfigurations是在類中定義爲純虛函數:

virtual int GetVideoEncoderConfigurations(_trt__GetVideoEncoderConfigurations *trt__GetVideoEncoderConfigurations, _trt__GetVideoEncoderConfigurationsResponse *trt__GetVideoEncoderConfigurationsResponse) =0; 

回答

1

使共享庫的方法是正確的。 問題是我沒有身體的功能。 它解決了虛擬功能是純虛擬的。

virtual void function_name() = 0; 

代替

virtual void function_name(); 

靜態庫允許功能,而無需主體;共享庫沒有。