3

我在将 wxWidget 示例应用程序 ( http://www.wxwidgets.org/docs/tutorials/hello.htm ) 与存储在 main.cpp 中的链接时遇到问题。我尝试使用以下方法编译和链接它:

g++ `wx-config --cxxflags --libs` main.cpp 

我得到的输出如下:

/tmp/ccFHWUaX.o: In function `wxCreateApp()':
main.cpp:(.text+0x31): undefined reference to `wxAppConsole::CheckBuildOptions(char const*, char const*)'
/tmp/ccFHWUaX.o: In function `main':
main.cpp:(.text+0x91): undefined reference to `wxEntry(int&, char**)'
/tmp/ccFHWUaX.o: In function `MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&)':
main.cpp:(.text+0x1d2): undefined reference to `wxFrameNameStr'
main.cpp:(.text+0x267): undefined reference to `wxEmptyString'
main.cpp:(.text+0x2ea): undefined reference to `wxEmptyString'
main.cpp:(.text+0x366): undefined reference to `wxMenuBar::wxMenuBar()'
main.cpp:(.text+0x3d1): undefined reference to `wxFrameBase::SetMenuBar(wxMenuBar*)'
main.cpp:(.text+0x3da): undefined reference to `wxStatusLineNameStr'
main.cpp:(.text+0x407): undefined reference to `wxFrame::CreateStatusBar(int, long, int, wxString const&)'
main.cpp:(.text+0x44f): undefined reference to `wxFrameBase::SetStatusText(wxString const&, int)'
main.cpp:(.text+0x533): undefined reference to `wxFrame::~wxFrame()'
(and many lines more...)

WxWidgets-2.8 使用 ubuntu 存储库安装,其库位于 /usr/lib/x86_64-linux-gnu。我还尝试使用以下方法构建指定库路径:

-L/usr/lib/x86_64-linux-gnu/

但是,这不会改变输出。我将我的问题归咎于 multiarch,但实际上只是因为我不知道它是如何工作的。

有人可以告诉我如何正确构建样本吗?

谢谢迈克尔

4

1 回答 1

4

使用静态链接时,库必须始终使用来自它们的符号在目标文件之后,否则它们会被链接器简单地忽略,因为在它第一次看到它们时不需要它们。所以us2012是正确的,你需要wx-config在你的源文件后面加上part。

您也可以使用共享的 wxWidgets 库,那么顺序就无关紧要了。但是使用正确的顺序仍然是一个好习惯,不管怎样,它对静态库和共享库都有效。

于 2013-09-29T10:56:04.317 回答