Using wxWidget on macOS 10.14.4 with VScode Topic is solved

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
fidoriel
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 09, 2020 6:10 pm

Using wxWidget on macOS 10.14.4 with VScode

Post by fidoriel » Thu Apr 09, 2020 7:07 pm

Hello,

this is my first topic on this forum and it is an absolute beginner question:

One week ago I started rewriting an old python project to c++. I wanted to get to know c++ a little bit better. Until then I just used it for Microcontrollers like Arduino.
I started rewriting the code in c++, which went surprisingly well. As a very simple GUI I used wxPython, so I decided to go with wxWidgets for the c++ version. I used
https://docs.wxwidgets.org/trunk/plat_osx_install.html
to build wxWidgets and the examples. It took around 15 minutes. I decided to skip advanced installing the library because "rarely desirable to install non-Apple software into system directories". "The examples are working very well, so I decided to try to compile a working example. I choose minimal from the examples I opened it up in Visual Studio Code and changed the path from wx/wx.h to an absolute path, as told in wiki. He found the files, but he had problems with dependencies from wx.h e.g. wx/defs.h. I changed the path, from one dependency by removing wx/, it worked. But then the same problem occurred again and again. I could not think that this is a mistake because it worked while building it. So I started to research and read the wiki article again. I was wondering about "use the full path to wx-config under the build directory when building an application using the library". The same instructions can be found in the docs OS X folder. I thought I had done it right by changing the path but then I looked up the wx-config file. And got confused. Now, I do not what to do. I built it once again, the same error.

These are more wx related questions:
Do I have to use wx-config, what does it?
How I set the path correctly?
How I make that the linker will find the build-cocoa-debug folder with the bin?
Do I have to use a Makefile/Builtfile/Bakefile?
In the samples/minimal folder, I do not know what the files are doing.

There I do not know, If they are related to wx but that was used in the examples, so I am going to ask it:
Where is the difference between Make-, Built and Bakefiles?
How do I create an .app Application as seen in the examples?

I am using macOS 10.15.4, VScodium 1.44.0, g++, Apple clang version 11. Xcode and command line tools are installed.
Thank you very much for your help and for this project/forum.

-f-

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

Re: Using wxWidget on macOS 10.14.4 with VScode

Post by ONEEYEMAN » Fri Apr 10, 2020 1:25 am

Hi,
All this is very confusing.

The best way to start with wxWidgets in OSX is:

1. Download and unpack wxWidgets (for example in ~/wxWidgets)
2. OPen the Terminal
3. Do following:

Code: Select all

cd ~/wxWidgets && mkdir buildOSX && cd buildOSX && ../configure && make && cd samples/minimal && make
After this will successfully finished you know that everything is compiled properly and you can start with building your own software.

In order to do that you do:

Code: Select all

cd ~/wxWidgets/buildOSX && ./wx-config --cxxflags
and

Code: Select all

cd ~/wxWidgets/buildOSX && ./wx-config --libs
Then you should be able to build your own program.

Thank you.

P.S.: If you get any issues at any point - please post here and we will be able to help.


To answer your questions:
Do I have to use wx-config, what does it?
wx-config is a little script that will help to indicate where the include folder and the libraries are located and also all additional options from the build.
How I set the path correctly?
You don't have to - wx-config will help here.
How I make that the linker will find the build-cocoa-debug folder with the bin?
Again the wx-config command I posted above will help.
Do I have to use a Makefile/Builtfile/Bakefile?
No, you don't have to.
In the samples/minimal folder, I do not know what the files are doing.
You don't have to know.


There I do not know, If they are related to wx but that was used in the examples, so I am going to ask it:
Where is the difference between Make-, Built and Bakefiles?
Are you familiar with the build system and the Makefile? Basically "make" is the little script that will execute the g++/clang program and build yiour software based on the Makefile rules you or someone put in.

Bakefile is just a way to generate the Makefile.
You don't need to use it.
How do I create an .app Application as seen in the examples?
Just look at how "minimal" sample will be built.

fidoriel
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 09, 2020 6:10 pm

Re: Using wxWidget on macOS 10.14.4 with VScode

Post by fidoriel » Fri Apr 10, 2020 7:16 am

Thank you very much for your fast answer. It has become a lot clearer.

An compiler error still exists:

This is used:

Code: Select all

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

Code: Select all

[email protected] wx % cd "/Users/user/Desktop/cpp/wx/" && g++ helloworld.cpp -o helloworld && "/Users/user/Desktop/cpp/wx/"helloworld
helloworld.cpp:3:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
         ^~~~~~~~~~~~~
1 error generated.
[email protected] wx % 

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

Re: Using wxWidget on macOS 10.14.4 with VScode

Post by ONEEYEMAN » Fri Apr 10, 2020 3:54 pm

Hi,
So I presume that the library and the minimal sample compiled OK.

Now for y0our own project you can either try to create an Xcode project or work from Terminal.

Now about the error:

What is an exact command you used to compile the code?

Thank you.

fidoriel
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 09, 2020 6:10 pm

Re: Using wxWidget on macOS 10.14.4 with VScode

Post by fidoriel » Fri Apr 10, 2020 7:21 pm

I will try to work from terminal.
I used

Code: Select all

g++ helloworld.cpp -o helloworld
to compile.

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

Re: Using wxWidget on macOS 10.14.4 with VScode

Post by ONEEYEMAN » Fri Apr 10, 2020 7:43 pm

Hi,
You should be using:

Code: Select all

g++ helloworld.cpp -o helloworld `~/wxWidgets/buildOSX/wx-config --cxxflags --libs`
Make sure you are using "back-ticks" and not the "apostrophies" (symbol that is found in the top left key on the keyboard) ;-)

Thank you.

fidoriel
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 09, 2020 6:10 pm

Re: Using wxWidget on macOS 10.14.4 with VScode

Post by fidoriel » Fri Apr 10, 2020 7:50 pm

Thank you very much. It worked fine.

Post Reply