Create OSX app from C++ code with wxWidgets

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

Hello,
I am on OSX and have a .cpp code which uses wxWidgets. When I run the executable of this code from command line with

Code: Select all

./executable.o
, a bunch of windows open up, and everything works fine.

I would like to transform this .o executable into an OSX app, which I could then allow other people to use on their Mac. How can I do this?

Thanks!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Create OSX app from C++ code with wxWidgets

Post by doublemax »

I don't work under OSX, so i can't answer any questions regarding this, but maybe it gets you on the right track:
https://wiki.wxwidgets.org/WxMac-specif ... ion_bundle
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create OSX app from C++ code with wxWidgets

Post by ONEEYEMAN »

Hi,
There is no extra magic.
You can just look at wxWidgets minimal sample, build it and do exactly what it does.

Thank you.
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Re: Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

ONEEYEMAN wrote: Mon Feb 14, 2022 12:48 pm Hi,
There is no extra magic.
You can just look at wxWidgets minimal sample, build it and do exactly what it does.

Thank you.
I don’t understand anything of what you wrote
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create OSX app from C++ code with wxWidgets

Post by ONEEYEMAN »

Hi,
Just build the minimal sample that comes with the library.
Or you installed it through the package manager?

Thank you.
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Re: Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

ONEEYEMAN wrote: Mon Feb 14, 2022 2:52 pm Hi,
Just build the minimal sample that comes with the library.
Or you installed it through the package manager?

Thank you.
Hello,
Thank you for your reply. I cded into /wxWidgets-3.1.5/samples/minimal, ran make and looked at the commands which were executed. Then I made this bash script make.sh which runs the same commands for my application

Code: Select all

/Applications/wxWidgets-3.1.5/bk-deps g++ -std=gnu++11 -mmacosx-version-min=10.10 -c -o my_application_my_application.o -I/Applications/wxWidgets-3.1.5/lib/wx/include/osx_cocoa-unicode-static-3.1 -I../../include -D_FILE_OFFSET_BITS=64  -D__WXOSX_COCOA__      -I.  -I./../../samples -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wno-deprecated-declarations -O2 -fno-common -dynamic -fPIC -DPIC   -dynamic -fPIC -DPIC  `wx-config --cxxflags`  -I/usr/local/include/gsl/  ./my_application.cpp


g++ -std=gnu++11 -mmacosx-version-min=10.10 -o my_application  my_application_my_application.o    -L/Applications/wxWidgets-3.1.5/lib      -framework IOKit -framework Carbon -framework Cocoa -framework QuartzCore -framework AudioToolbox -framework System -framework OpenGL  -lwx_osx_cocoau_core-3.1  -lwx_baseu-3.1    -lwxtiff-3.1 -lwxjpeg-3.1 -lwxpng-3.1  -framework WebKit  -lwxregexu-3.1  -framework IOKit -framework Carbon -framework Cocoa -framework QuartzCore -framework AudioToolbox -framework System -framework OpenGL  -lz -framework Security -lpthread -liconv  -lz -framework Security -lpthread -liconv `wx-config --libs` -lgsl -lcblas

rm -rf my_application.app

mkdir -p my_application.app/Contents
mkdir -p my_application.app/Contents/MacOS
mkdir -p my_application.app/Contents/Resources

sed -e "s/IDENTIFIER/`echo . | sed -e 's,\.\./,,g' | sed -e 's,/,.,g'`/" \
        -e "s/EXECUTABLE/my_application/" \
        -e "s/VERSION/3.1.5/" \
        /Applications/wxWidgets-3.1.5/src/osx/carbon/Info.plist.in >my_application.app/Contents/Info.plist

/bin/echo "APPL????" >my_application.app/Contents/PkgInfo
ln -f my_application my_application.app/Contents/MacOS/my_application
cp -f /Applications/wxWidgets-3.1.5/src/osx/carbon/wxmac.icns my_application.app/Contents/Resources/wxmac.icns
The script looks similar to the one suggested by doublemax.

This creates my_application.app, which appears to run correctly. Is there anything wrong with the script that I wrote? Also, the original .cpp code uses some input data files, shall I put these files in my_application.app/Contents/Resources?

Thank you! This looks great.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create OSX app from C++ code with wxWidgets

Post by ONEEYEMAN »

Hi,
I didn't look at the code you wrote, but..
For the reference -

Let's say you did this:
Unpack the wxwidgets into ~/wxWidgets-3.1.5 directory
cd ~/wxWidgets-3.1.5
mkdir build-cocoa
cd build-cocoa
../configure <set_of_options>
make

then to build minimal sample you should do:

cd ~/wxWidgets-3.1.5/build-cocoa/samples/minimal
make

Please do that, make sure you can run the sample and do the same with you software.

In terms of you second question - what kind of files are they?

Thanks.
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Re: Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

ONEEYEMAN wrote: Tue Feb 15, 2022 12:52 pm Please do that, make sure you can run the sample and do the same with you software.
I have done it, I can run the sample. How can I do the same with my software? I guess the procedure used for the sample will not work for my software, because there are a number of paths which are different.
In terms of you second question - what kind of files are they?
They are .dat files: text files with containing a bunch of numbers, something like this

Code: Select all

1	0.242
2	2.432
3	23.3424
[...]
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create OSX app from C++ code with wxWidgets

Post by ONEEYEMAN »

Hi,
You wrote:
This creates my_application.app, which appears to run correctly.
so, it looks like everything is OK.

Now for you data files - is your program reads and parses them?
Or they are needed for something else?

Depending on that you might put them in the Resources folder or somewhere else?
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Re: Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

ONEEYEMAN wrote: Wed Feb 16, 2022 3:46 pm Now for you data files - is your program reads and parses them?
Yes, my program reads and parses them!

On a related topic, is it possible to create with a similar make procedure an app for ipad or iphone from the same .cpp code?

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

Re: Create OSX app from C++ code with wxWidgets

Post by ONEEYEMAN »

Hi,
Then you could probably copy them to the Resource folder and then use "GetResourceFolder()" to retrieve their place.

About your other question - you can try to pass "--with-iphone" to configure and see if your program will run on iPhone/iPad.

However, I'm not sure what is the lowest version wxWidgets compatible with.

Thank you.
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Re: Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

ONEEYEMAN wrote: Wed Feb 16, 2022 5:22 pm Hi,
Then you could probably copy them to the Resource folder and then use "GetResourceFolder()" to retrieve their place.
Thank you.
About your other question - you can try to pass "--with-iphone" to configure and see if your program will run on iPhone/iPad.
Ok: where should I add the --with-iphone flag? I tried to add it to the g++ commands which result from the make command, but I get the error

Code: Select all

clang: error: unsupported option '--with-iphone'
Thanks.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create OSX app from C++ code with wxWidgets

Post by ONEEYEMAN »

Hi,
No, you should create another build directory and run configure (with possibly the same arguments as before) adding this option.
And then issue make.

Isn't it how you build the library initially? Or you just run configure from main wxWidgets directory?

If you did - i recommend to kill the whole wxWidgets dir unpack it again, then create 2 build dirs - one for regular and one for iPhone then run appropriate configure & make.

The recommended way to build anything on any ^nix like system is to use build dir and never run that from the source tree.

Thank you.
giulio_seb
Earned some good credits
Earned some good credits
Posts: 108
Joined: Mon Feb 07, 2022 11:53 am

Re: Create OSX app from C++ code with wxWidgets

Post by giulio_seb »

ONEEYEMAN wrote: Thu Feb 17, 2022 2:16 am Hi,
No, you should create another build directory and run configure (with possibly the same arguments as before) adding this option.
And then issue make.

Isn't it how you build the library initially? Or you just run configure from main wxWidgets directory?

If you did - i recommend to kill the whole wxWidgets dir unpack it again, then create 2 build dirs - one for regular and one for iPhone then run appropriate configure & make.

The recommended way to build anything on any ^nix like system is to use build dir and never run that from the source tree.

Thank you.
Hello, I did as you said, and made

Code: Select all

 % ../configure --enable-debug --with-iphone
but I get the error message

Code: Select all

configure: error: building C++ programs doesn't work, check that command line tools from Xcode 7.2.1 or later are installed.
See `config.log' for more details
at the end
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Create OSX app from C++ code with wxWidgets

Post by doublemax »

check that command line tools from Xcode 7.2.1 or later are installed
The error message is quite clear.

Xcode command line tools are not installed by default. There's an option somewhere in Xcode to install them (sorry, can't tell you exactly where).
Use the source, Luke!
Post Reply