1

I'm trying to use wxWidgets on an arm64 macOS with vcpkg, CMake, and VS Code. Everything is wired up correctly because other vcpkg libraries include, link, and run fine. But, when I try to use wxWidgets there's a linking error.

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.22.0)
project(main VERSION 0.1.0)

add_executable(main main.cpp)
set_property(TARGET main PROPERTY CXX_STANDARD 17)

find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
target_include_directories(main PRIVATE ${wxWidgets_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${wxWidgets_LIBRARIES})

The CMake error I get:

[build] [ 50%] Linking CXX executable main
[build] ld: library not found for -llibjpeg.a>
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)

The value of the wxWidgets_LIBRARIES list (set by find_package(wxWidgets REQUIRED)):

-L/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib;-pthread;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_xrc-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_qa-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_baseu_net-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_html-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_core-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_baseu_xml-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_baseu-3.1.a;-lwx_osx_cocoau_core-3.1;libjpeg.a>;libjpeg.a>;libpng.a>;libpng16d.a>;libz.a>;libz.a>;libtiff.a>;libtiffd.a>;liblzma.a>;liblzma.a>;libjpeg.a>;libjpeg.a>;libz.a>;libz.a>;m;-framework AudioToolbox;-framework WebKit;-lwx_baseu-3.1;libexpat.a>;libexpat.a>;libz.a>;libz.a>;-lwxregexu-3.1;libiconv.tbd;-framework CoreFoundation;-framework Security;-framework Carbon;-framework Cocoa;-framework IOKit;-framework QuartzCore;TIFF::TIFF;expat::expat;ZLIB::ZLIB;png_static

I don't have much experience with CMake, so I don't know what the right angle bracket is for, but is that the problem? Could its being the first non-full-path file in the list mean that it doesn't know where to look?

sr3
  • 389
  • 2
  • 4
  • 15
  • ***but is that the problem?*** I don't believe the problem is CMake related. Does `libjpeg.a` exist on your system? – drescherjm Mar 30 '22 at 00:08
  • @drescherjm Yes all the dependency libs like `libjpeg` for wxWidgets were automatically installed when vcpkg installed wxWidgets. `libjpeg.a` is at `/Users/myname/cpp/vcpkg/installed/arm64-osx/lib/libjpeg.a`. All the others like `libpng.a`, `libz.a`, and so on are there too right next to `libjpeg.a`. – sr3 Mar 30 '22 at 03:09
  • try `git pull` on the vcpkg repository. I had several linking issues with cmake in the past and updating the vcpkg repo magically fixed them. Also make sure that the library is actually installed. I noticed that i sometimes need to install the same package twice for it to appear in `vcpkg list` – Raildex Mar 30 '22 at 07:01
  • @sr3, are trying to cross-compile your application for windows? Or you end goal is to have OSX Bundle? – Igor Mar 30 '22 at 12:20

2 Answers2

0

-L is for directories, and -l is for individual library files. I see you have mixed .a files with directories. You'll need to fix that.

David G
  • 94,763
  • 41
  • 167
  • 253
  • The `wxWidgets_LIBRARIES` variable is automatically set by `find_package(wxWidgets REQUIRED)`. I didn't make it. Are you saying they made an error? – sr3 Mar 29 '22 at 23:46
  • @sr3 Hmm..maybe that's not the issue after all. – David G Mar 30 '22 at 00:16
0

Your best bet is to debug cmake configure with --trace-expand and see who is setting wxWidgets_LIBRARIES to a incomplete and very strange generator expression libjpeg.a>;libjpeg.a>;libpng.a>;libpng16d.a>;

Another suspicious thing is that your library paths contain packages/wxwidgets_arm64-osx which indicates either wrong usage of vcpkg or there is a -config.cmake involved which was not fixed by vcpkg. (everything vcpkg finds via cmake should be living in /installed/<triplet>)

Alexander Neumann
  • 1,479
  • 8
  • 17