【发布时间】:2013-10-01 17:24:58
【问题描述】:
我在将 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,但实际上只是因为我不知道它是如何工作的。
谁能告诉我如何正确构建示例?
谢谢 迈克尔
【问题讨论】:
-
你试过把
wx-config --libsafter你的源文件放在命令行吗? -
我肯定会从命令提示符运行
wx-config --cxxflags --libs并验证它是否包含您期望的“-L”(库搜索路径)和“-l”(库文件)条目。可能 wx-config 配置不正确。恕我直言.. -
这很奇怪...为什么我必须把它们放在源文件后面?我正在使用 eclipse 并且默认情况下链接器标志放置在输入之前。更改顺序解决了问题,太棒了,谢谢。顺便说一句:wx-config 的输出正确设置了 -L 和 -l 条目。
标签: c++ linux ubuntu wxwidgets