link error on macOS

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
tcgessner
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 30, 2020 10:14 am

link error on macOS

Post 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
Tim

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)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include(CTest)
enable_testing()

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)


set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Last edited by catalin on Thu Jul 30, 2020 7:03 pm, edited 1 time in total.
Reason: code tags
tcgessner
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 30, 2020 10:14 am

Re: link error on macOS

Post by tcgessner »

I changed the line

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

to

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?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: link error on macOS

Post by ONEEYEMAN »

Hi,
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.
tcgessner
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 30, 2020 10:14 am

Re: link error on macOS

Post 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!

Thanx
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: link error on macOS

Post by ONEEYEMAN »

Hi,
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.
Post Reply