0

I am on MacOS Mojave 10.14. I can compile wxWidget code and have compiled a few demos, etc. The only feature of wxWidget I cannot compile is a wxRichTextCtrl. Whenever I do the following in my main.cpp file I get error:

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

I get this error

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)

I have tried replacing "this" with a wxPanel, but that results in the same error. The full error report from g++ is:

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)

I compile from my terminal using g++ and get my linker options, etc from wx-config --cxxflags and wx-config --libs. I program in xCode. Using gcc instead of g++ results in the same error.

linker
  • 105
  • 5
  • I see you are new to Stack Overflow so Welcome! I haven't used wxwidget, but I have C++ experience. The error is likely the library you need isn't included on the command line, or the statement doesn't match the C++ signature of the function you are calling. I hope someone else will be able to answer this but wanted to welcome you aboard. Best wishes. – PatS Nov 04 '19 at 21:33
  • @linker, try `wx-config --libs,richedit`. Just `wx-config --libs` will give you base and core libraries... – Igor Nov 04 '19 at 21:47
  • "--libs,richedit is undecognized" @Igor – linker Nov 05 '19 at 08:39
  • I compared "wx-config --libs" to "wx-config --libs richedit" and realized that the missing library is: -framework OpenGL /usr/local/lib/libwx_osx_cocoau_richtext-3.1.a. How did you know the name of the library? I cannot find any information on richedit anywhere. Btw, adding '-framework OpenGL /usr/local/lib/libwx_osx_cocoau_richtext-3.1.a' fixed it! @Igor – linker Nov 05 '19 at 08:54
  • @linker, look here: https://docs.wxwidgets.org/trunk/page_libs.html#page_libs_wxrichtext – Igor Nov 05 '19 at 15:34

1 Answers1

2

By default, wx-config --libs returns only the "standard" libraries (which basically were all the existing libraries back when this was implemented) and not all the available libraries to make it possible to add more libraries later without changing anything for the applications that don't need them.

So if you need to use a library not included in this "standard subset", you must specify it explicitly, like this: wx-config --libs std,richtext.

VZ.
  • 21,740
  • 3
  • 39
  • 42