Page 1 of 1

link error on macOS

Posted: Thu Jul 30, 2020 10:35 am
by tcgessner
I am trying to setup a simple HelloWorld wxWidgets project with CMake on macOS.

CMake configures without errors but when I build I get the error, 'error: expected unqualified-id @class NSString, Protocol;'

I'm using macOS 10.15.6, CMake 3.18 and wxWidgets 3.0.5 with Visual Studio Code as the editor.

I'm just getting started trying to understand the build environment. Can anyone point me in the right direction?
Thank you

Here is my source file:

Code: Select all

#include <iostream>

// #include <wx.h>

int main()
    std::cout << "HelloWorld" << std::endl;
Here is my CMake file:

Code: Select all

cmake_minimum_required(VERSION 3.0.0)
project(HelloWorld VERSION 0.1.0)



add_executable(HelloWorld HelloWorld.cpp)

add_library(wx_baseu STATIC IMPORTED)
set_target_properties(wx_baseu PROPERTIES IMPORTED_LOCATION /Users/tim/Onedrive/Programming/wxWidgets-3.0.5/lib/libwx_baseu-3.0.a)

add_library(wx_osx_cocoau_core STATIC IMPORTED)
set_target_properties(wx_osx_cocoau_core PROPERTIES IMPORTED_LOCATION /Users/tim/Onedrive/Programming/wxWidgets-3.0.5/lib/libwx_osx_cocoau_core-3.0.a)

target_link_libraries(HelloWorld wx_baseu wx_osx_cocoau_core)

target_include_directories(HelloWorld PUBLIC /Users/tim/Onedrive/Programming/wxWidgets-3.0.5/include/wx/cocoa)


Re: link error on macOS

Posted: Fri Jul 31, 2020 8:50 am
by tcgessner
I changed the line

target_include_directories(HelloWorld PUBLIC /Users/tim/Onedrive/Programming/wxWidgets-3.0.5/include/wx/cocoa)


target_include_directories(HelloWorld PUBLIC /Users/tim/Onedrive/Programming/wxWidgets-3.0.5/include)

Now it struggles to find all the header files. Since this is pretty simple I must still be doing something wrong.

Any ideas?

Re: link error on macOS

Posted: Sat Aug 01, 2020 3:30 am
Can you build and run "minimal" sample provided by wxWidgets?
Can you open, build and run the "minimal" Xcode project provided by wxWidgets?

If yes - disregard "CMake crap", copy the "minimal sample" folder somewhere, remove minima.cpp, add your source code, fix include and library path and recompile.

Thank you.

Re: link error on macOS

Posted: Sat Aug 01, 2020 5:09 pm
by tcgessner
Yes, I can build and run those. I was trying to use CMake as that seemed to be recommended on the wxWidgets site.

That is a good idea though just to get things moving forward. I will use the existing makefiles.

I would like to understand what I am doing wrong though. It will annoy me I can't make it work!


Re: link error on macOS

Posted: Sat Aug 01, 2020 5:23 pm
Makefile is still recommended way of building everything.
CMake crap should be used for convenience IMHO.

Also, all those options should use wx-config script:

wx-config --cxxflags
wx-config --libs

Thank you.