![](/img/trans.png)
[英]How to avoid sub-library aggregation during webrtc compilation on Windows?
[英]Undefined references to functions in sub-library
首先,對於問題的所有部分,我在Linux上使用g ++ 4.7的c ++ 11。
我的問題的設置:我創建了一個在其他程序中使用的共享庫(稱為“ libA”)。 該庫中的某個部分未在界面中公開,因為它與程序無關。 但是,現在,我想直接在另一個庫(“ libB”)中使用此先前隱藏的部分。
因此,我的計划是從libA的隱藏部分創建一個新的庫。 這將是“ libSub”。 然后,libsub被同時包含在libA和libB中。 兩者都編譯沒有錯誤。 但是,當我現在嘗試編譯依賴於libA的程序時,出現很多錯誤,提示存在來自libSub的函數的未定義引用。
為了使結構更清晰:
// Sub.hpp
class Sub{
private:
// private variables
public:
// interface functions
};
// A.hpp
class Sub; //forward declaring the sub-class
class A{
private:
std::shared_ptr<Sub> s;
// more private variables
public:
// some interface functions
};
// A.cpp
#include <Sub.hpp> // include the declaration of the Sub class
// definitions of the member functions of A
// program.cpp
#include A.hpp
a=A();
這些庫放置在本地文件夾中,因為我想避免將它們安裝到常規的lib文件夾中。 我想將它們全部安裝到全局lib-folder可以解決問題。
問題是:是否有辦法擺脫錯誤並仍然使用本地文件夾? 如果是這樣,怎么辦?
您是否嘗試過僅單獨編譯?
// A.hpp
class Sub; //forward declaring the sub-class
class A{
private:
Sub s;
// more private variables
public:
// some interface functions
};
Sub
是一個不完整的類型, A
將無法編譯,因為您需要定義該類。 查看此內容以了解如何使用前向聲明。
我假設您首先需要在其他庫中包含libSub的頭文件。 舉一個小例子,如果有更多問題,請回來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.