【问题标题】:wxwidget wxRichTextCtrl compiled results in ld: symbol(s) not foundwxwidget wxRichTextCtrl 编译结果为 ld: symbol(s) not found
【发布时间】:2020-03-01 05:20:38
【问题描述】:

我使用的是 MacOS Mojave 10.14。我可以编译 wxWidget 代码并编译了一些演示等。我无法编译的 wxWidget 的唯一功能是 wxRichTextCtrl。每当我在 main.cpp 文件中执行以下操作时,都会出现错误:

wxRichTextCtrl* richTextCtrl = new wxRichTextCtrl(this, -1, wxT(""), wxDefaultPosition,
    wxSize(250, 150), wxTE_MULTILINE);

我收到此错误

Undefined symbols for architecture x86_64:
"wxRichTextCtrl::wxRichTextCtrl(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)", referenced from:
  MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&) in main-498ba7.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试用 wxPanel 替换“this”,但这会导致同样的错误。 g++ 的完整错误报告是:

Apple clang version 11.0.0 (clang-1100.0.33.5)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin    /clang" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated- objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp- elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 512.4 -v -resource-dir /Applications  /Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0 -I/usr/local/lib/wx/include/osx_cocoa-unicode-static-3.1 -I /usr/local/include/wx-3.1 -D _FILE_OFFSET_BITS=64 -D __WXMAC__ -D __WXOSX__ -D __WXOSX_COCOA__ -stdlib=libc++ -internal-isystem /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-   header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-   compilation-dir /Users/user/Downloads/wxWidgets-3.1.3/build/osx -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/f3/lvdll7257lq_4_fcysmprc700000gn/T/main-b50747.o -x c++ main.cpp
clang -cc1 version 11.0.0 (clang-1100.0.33.5) default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/wx/include/osx_cocoa-unicode-static-3.1
 /usr/local/include/wx-3.1
 /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin  /../include/c++/v1
 /usr/local/include
 /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib  /clang/11.0.0/include
 /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -o out -L/usr/local/lib -framework IOKit -framework Carbon -framework         Cocoa -framework AudioToolbox -framework System -framework OpenGL /usr/local/lib/libwx_osx_cocoau_xrc-3.1.a /usr/local/lib/libwx_osx_cocoau_qa-3.1.a /usr/local/lib/libwx_baseu_net-3.1.a /usr/local/lib/libwx_osx_cocoau_html-3.1.a /usr/local/lib/libwx_osx_cocoau_core-3.1.a /usr/local/lib/libwx_baseu_xml-3.1.a /usr/local/lib/libwx_baseu-3.1.a -framework WebKit -lwxregexu-3.1 -lwxscintilla-3.1 -lexpat -lpng -ljpeg -ltiff -lz -framework Security -lpthread -liconv -llzma /var/folders/f3/lvdll7257lq_4_fcysmprc700000gn/T/main-b50747.o -lc++ -lSystem /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "wxRichTextCtrl::wxRichTextCtrl(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)", referenced from:
      MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&) in main-b50747.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我使用 g++ 从终端编译并从 wx-config --cxxflags 和 wx-config --libs 获取链接器选项等。我在 xCode 中编程。使用 gcc 而不是 g++ 会导致同样的错误。

【问题讨论】:

  • 我知道您是 Stack Overflow 的新手,所以欢迎您!我没用过wxwidget,但是我有C++经验。该错误可能是您需要的库未包含在命令行中,或者该语句与您正在调用的函数的 C++ 签名不匹配。我希望其他人能够回答这个问题,但希望欢迎您加入。最良好的祝愿。
  • @linker,试试wx-config --libs,richedit。只需wx-config --libs 即可为您提供基础库和核心库...
  • "--libs,richedit 无法识别" @Igor
  • 我将“wx-config --libs”与“wx-config --libs richedit”进行了比较,发现缺少的库是:-framework OpenGL /usr/local/lib/libwx_osx_cocoau_richtext-3.1。一种。你是怎么知道图书馆的名字的?我在任何地方都找不到关于richedit 的任何信息。顺便说一句,添加 '-framework OpenGL /usr/local/lib/libwx_osx_cocoau_richtext-3.1.a' 修复了它! @伊戈尔

标签: c++ gcc compiler-errors wxwidgets richtextctrl


【解决方案1】:

默认情况下,wx-config --libs 仅返回“标准”库(基本上是实现此功能时的所有现有库)而不是所有可用库,以便以后可以添加更多库而无需更改任何内容不需要它们的应用程序。

因此,如果您需要使用未包含在此“标准子集”中的库,则必须明确指定它,例如:wx-config --libs std,richtext

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 2020-08-02
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多