1
首先,這是在Linux上構建的。基於wxObject的類無法鏈接
我們有一個基於wxObjects(我們不使用的GUI對象)的API。我們的課程定義如下:
#include <wx/wx.h>
class apibaseclass : public wxObject
{
apibaseclass();
~apibaseclass();
}
大約五年前這個編譯和鏈接就好了。我一直要求修改,現在我得到以下錯誤:
未定義參考wxObject::wxObject()'/home/lloyd/Projects/wxtestprogram/main.cpp:7: undefined reference to
wxObject :: wxObject()」
這是我用一個理智的測試程序:
#include <iostream>
#include <wx/wx.h>
class blah : public wxObject
{
public:
int x;
blah();
virtual ~blah();
void setvalue(int value);
int getvalue();
};
blah::blah()
{
}
blah::~blah()
{
}
void blah::setvalue(int value)
{
x = value;
}
int blah::getvalue()
{
return x;
}
using namespace std;
int main()
{
class blah *testvalue = new blah();
testvalue->setvalue(15);
wxPrintf(wxT("Hello World 2 %d\r\n"), testvalue->getvalue());
wxString str1 = wxT("Linux");
wxString str2 = wxT("Operating");
wxString str3 = wxT("System");
wxString str;
str = str1 + wxT(" ") + str2 + wxT(" ") + str3;
wxPuts(str);
wxPrintf(wxGetHomeDir());
long int mem = wxGetFreeMemory();
wxPrintf(wxT("Memory: %ld\n"), mem);
return 0;
}
什麼是麻煩的是,如果我取代「公共wxObject」與「公共wxString」,那麼它鏈接就好了。爲什麼我無法訪問wxObject?!?
注:我從來沒有反對比過去libwx_baseu-2.6.so以外的任何鏈接。事實上,當我沒有GUI時,它只能編譯libwx_baseu-2.6,libwx_baseu_net-2.6和libwx_baseu_xml-2.6。
什麼我需要做的事情的建築,並以最少搞亂和大驚小怪再次連接的?
好的,我想通了。使用「wxconfig --cxxflags --libs base」給了我需要的標誌,現在它鏈接並正確地編譯。 –