您应该使用wx-config --cxxflags和wx-config --libs来获取编译所需的包含路径,标志和库。
详细说明:您需要告诉编译器在哪里查找包含文件以及需要链接哪些库。 wx-config是一个便利的程序,它会给你提供这些信息。在我的系统从WX-config中的输出是这样的:
-I/usr/local/lib/wx/include/gtk2-unicode-2.9 -I/usr/local/include/wx-2.9 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -L/usr/local/lib -pthread -lwx_gtk2u_xrc-2.9 -lwx_gtk2u_html-2.9 -lwx_gtk2u_qa-2.9 -lwx_gtk2u_adv-2.9 -lwx_gtk2u_core-2.9 -lwx_baseu_xml-2.9 -lwx_baseu_net-2.9 -lwx_baseu-2.9
让我们借此简约wxWidgets的应用:
gcc OUTPUT_OF_WX-CONFIG test.cpp -o test
:
#include <wx/app.h>
#include <wx/frame.h>
/** Main application class.
* This class is derived from the main wxWidgets application class.
*/
class MyApp : public wxApp
{
public:
/// Initialization function. Called at startup.
virtual bool OnInit();
virtual ~MyApp();
};
DECLARE_APP(MyApp);
IMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
if (!wxApp::OnInit())
return false;
wxFrame* MainFrame = new wxFrame(NULL, wxID_ANY, wxT("MyApp"));
MainFrame->Show();
return true;
}
MyApp::~MyApp() {}
您可以使用下面的调用编译这个其中OUTPUT_OF_WX-CONFIG是上面的标志和库目录,test.cpp包含上述源代码。如果你的wxWidgets安装设置正确,这应该编译并运行良好(将显示一个空的窗口)。
只需少量添加:你可以在它们周围使用wx-config --cxxflags和wx-config --libs作为编译器和链接器标志。 ''被shell的内部命令输出取代。 –
感谢您的帮助,我现在就解决它。gcc 4.6必须使用g ++ -o src src.cpp'wx-config --cxxflags --libs'来编译它。如果我使用g ++'wxconfig --cxxflags --libs'-o xx xx.cpp。它不会成功 – cwh5635