-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
323 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: "Wxwidgets macOS guide to compile universal binaries" | ||
date: 2023-10-25T14:00:23+02:00 | ||
description: A tutorial that actually works. | ||
draft: false | ||
tags: [tutorial, macOS, wxwidgets] | ||
--- | ||
|
||
## Introduction | ||
|
||
I wanted to publish my wxwidgets project "D2R Runeword Calculator" which I already blogged about, to the macOS App Store. In order to do this with wxwidgets, you are advised to create statically-linked binaries that run both on x86_64 and arm64. But the instructions in the wxwidgets tutorials are outdated and lack crucial information. It took me a few hours, but I figured out how it can be done on macOS Ventura (13.6). The wxwidgets version I will be using is 3.2.3, which was released on October 10, 2023. | ||
|
||
## Guide | ||
|
||
### Step 1 - Acquire latest source code of wxwidgets | ||
|
||
Just go to their [website](https://www.wxwidgets.org/downloads/) and download the latest stable "Source for Linux, macOS, etc". Then unpack it. | ||
|
||
### Step 2 - Building | ||
|
||
It took me lots of tries to find a command that would work but there it is: | ||
|
||
```zsh | ||
cd wxWidgets-3.2.3 && mkdir build-cocoa-static && cd build-cocoa-static && ../configure CXXFLAGS="-std=c++17" --enable-debug --disable-shared --with-osx_cocoa --with-libiconv --with-macosx-version-min=13.6 --enable-macosx_arch=x86_64,arm64 && make -j | ||
``` | ||
|
||
This will take a long time, but it ensures that you get statically linked binaries that target both x86_64 and arm64 macOS. If you want to use a different C++ standard than 17, feel free to remove the part CXXFLAGS="-std=c++17" (I don't think it's needed). | ||
|
||
### Step 3 - Installing | ||
|
||
After the previous command terminates, just one more command is required to install wxwidgets: | ||
|
||
```zsh | ||
sudo make install | ||
``` | ||
|
||
### Step 4 - Compiling your project | ||
|
||
Now just cd to your project folder and run: | ||
|
||
```zsh | ||
g++ -arch x86_64 -arch arm64 -mmacosx-version-min=13.6 -std=c++17 *.cpp -w `wx-config --cxxflags --libs` -o myExecutable | ||
``` | ||
|
||
The parameters "-arch x86_64 -arch arm64" ensure universal compilation. I kept getting warnings about some .dylibs (dynamic libaries) which are irrelevant, so I added "-w" to silence these warnings. I used "-mmacosx-version-min=13.6" because I am running Ventura 13.6 and the value here should be the same one as you used in the configure command; otherwise, you keep getting warnings about how it's linked against 13.0 or whatever. I use "-std=c++17" because that is the C++ version I am targeting. | ||
|
||
You can verify that your binary works on x86_64 and arm64 by using the command: | ||
|
||
```zsh | ||
lipo -archs <yourBinary> | ||
``` | ||
|
||
## Conclusion | ||
|
||
This seems like a short and simple tutorial, but it is extremely frustrating to get to the point where things are working as they should. The wxwidgets tutorials are mostly outdated or lack crucial information. Then Brew baited me into trying that approach, but it kept ignoring my edits (the default is dynamic linking, which I don't want), and even after everything was set up it was not clear to me that -arch arm64 needs to be added to the command. I am glad that everything is working now, and the next steps are packaging the binary into a .App file that can be published on the App Store. I already noticed that the wxwidgets tutorial for building on XCode is already outdated, so I will see how that goes and maybe write another post after I am successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
public/posts/wxwidget-macos-universal-binary/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<!DOCTYPE html> | ||
<html><head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Wxwidgets macOS guide to compile universal binaries - Blog for Tech Enjoyers</title><link rel="icon" type="image/png" href=https://www.pngmart.com/files/23/Nerd-Emoji-PNG.png /><meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="A tutorial that actually works." /> | ||
<meta property="og:image" content=""/> | ||
<meta property="og:title" content="Wxwidgets macOS guide to compile universal binaries" /> | ||
<meta property="og:description" content="A tutorial that actually works." /> | ||
<meta property="og:type" content="article" /> | ||
<meta property="og:url" content="https://example.com/posts/wxwidget-macos-universal-binary/" /><meta property="article:section" content="posts" /> | ||
<meta property="article:published_time" content="2023-10-25T14:00:23+02:00" /> | ||
<meta property="article:modified_time" content="2023-10-25T14:00:23+02:00" /> | ||
<meta name="twitter:card" content="summary"/> | ||
<meta name="twitter:title" content="Wxwidgets macOS guide to compile universal binaries"/> | ||
<meta name="twitter:description" content="A tutorial that actually works."/> | ||
<script src="https://example.com/js/feather.min.js"></script> | ||
|
||
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@1,500&display=swap" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet"> | ||
|
||
|
||
<link rel="stylesheet" type="text/css" media="screen" href="https://example.com/css/main.11f18f89079b6a945895b72d837341dfd89f35ac277810cdb01c507ea0faeb47.css" /> | ||
<link id="darkModeStyle" rel="stylesheet" type="text/css" href="https://example.com/css/dark.c95c5dcf5f32f8b67bd36f7dab66680e068fce2b303087294114aabf7a7c080b.css" disabled /> | ||
|
||
|
||
|
||
</head><body> | ||
<div class="content"><header> | ||
<div class="main"> | ||
<a href="https://example.com/">Blog for Tech Enjoyers</a> | ||
</div> | ||
<nav> | ||
|
||
<a href="/posts">Posts</a> | ||
|
||
<a href="/about">About</a> | ||
|
||
<a href="/tags">Tags</a> | ||
|
||
| <a id="dark-mode-toggle" onclick="toggleTheme()" href=""></a> | ||
<script src="https://example.com/js/themetoggle.js"></script> | ||
|
||
</nav> | ||
</header> | ||
<main> | ||
|
||
<article> | ||
<div class="title"> | ||
<h1 class="title">Wxwidgets macOS guide to compile universal binaries</h1> | ||
<div class="meta">Posted on Oct 25, 2023</div> | ||
</div> | ||
|
||
|
||
<aside> | ||
<hr> | ||
Table of Contents: | ||
<nav id="TableOfContents"> | ||
<ul> | ||
<li><a href="#introduction">Introduction</a></li> | ||
<li><a href="#guide">Guide</a> | ||
<ul> | ||
<li><a href="#step-1---acquire-latest-source-code-of-wxwidgets">Step 1 - Acquire latest source code of wxwidgets</a></li> | ||
<li><a href="#step-2---building">Step 2 - Building</a></li> | ||
<li><a href="#step-3---installing">Step 3 - Installing</a></li> | ||
<li><a href="#step-4---compiling-your-project">Step 4 - Compiling your project</a></li> | ||
</ul> | ||
</li> | ||
<li><a href="#conclusion">Conclusion</a></li> | ||
</ul> | ||
</nav> | ||
<hr> | ||
</aside> | ||
|
||
|
||
<section class="body"> | ||
<h2 id="introduction">Introduction</h2> | ||
<p>I wanted to publish my wxwidgets project “D2R Runeword Calculator” which I already blogged about, to the macOS App Store. In order to do this with wxwidgets, you are advised to create statically-linked binaries that run both on x86_64 and arm64. But the instructions in the wxwidgets tutorials are outdated and lack crucial information. It took me a few hours, but I figured out how it can be done on macOS Ventura (13.6). The wxwidgets version I will be using is 3.2.3, which was released on October 10, 2023.</p> | ||
<h2 id="guide">Guide</h2> | ||
<h3 id="step-1---acquire-latest-source-code-of-wxwidgets">Step 1 - Acquire latest source code of wxwidgets</h3> | ||
<p>Just go to their <a href="https://www.wxwidgets.org/downloads/">website</a> and download the latest stable “Source for Linux, macOS, etc”. Then unpack it.</p> | ||
<h3 id="step-2---building">Step 2 - Building</h3> | ||
<p>It took me lots of tries to find a command that would work but there it is:</p> | ||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>cd wxWidgets-3.2.3 <span style="color:#f92672">&&</span> mkdir build-cocoa-static <span style="color:#f92672">&&</span> cd build-cocoa-static <span style="color:#f92672">&&</span> ../configure CXXFLAGS<span style="color:#f92672">=</span><span style="color:#e6db74">"-std=c++17"</span> --enable-debug --disable-shared --with-osx_cocoa --with-libiconv --with-macosx-version-min<span style="color:#f92672">=</span>13.6 --enable-macosx_arch<span style="color:#f92672">=</span>x86_64,arm64 <span style="color:#f92672">&&</span> make -j | ||
</span></span></code></pre></div><p>This will take a long time, but it ensures that you get statically linked binaries that target both x86_64 and arm64 macOS. If you want to use a different C++ standard than 17, feel free to remove the part CXXFLAGS="-std=c++17" (I don’t think it’s needed).</p> | ||
<h3 id="step-3---installing">Step 3 - Installing</h3> | ||
<p>After the previous command terminates, just one more command is required to install wxwidgets:</p> | ||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>sudo make install | ||
</span></span></code></pre></div><h3 id="step-4---compiling-your-project">Step 4 - Compiling your project</h3> | ||
<p>Now just cd to your project folder and run:</p> | ||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>g++ -arch x86_64 -arch arm64 -mmacosx-version-min<span style="color:#f92672">=</span>13.6 -std<span style="color:#f92672">=</span>c++17 *.cpp -w <span style="color:#e6db74">`</span>wx-config --cxxflags --libs<span style="color:#e6db74">`</span> -o myExecutable | ||
</span></span></code></pre></div><p>The parameters “-arch x86_64 -arch arm64” ensure universal compilation. I kept getting warnings about some .dylibs (dynamic libaries) which are irrelevant, so I added “-w” to silence these warnings. I used “-mmacosx-version-min=13.6” because I am running Ventura 13.6 and the value here should be the same one as you used in the configure command; otherwise, you keep getting warnings about how it’s linked against 13.0 or whatever. I use “-std=c++17” because that is the C++ version I am targeting.</p> | ||
<p>You can verify that your binary works on x86_64 and arm64 by using the command:</p> | ||
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-zsh" data-lang="zsh"><span style="display:flex;"><span>lipo -archs <yourBinary> | ||
</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2> | ||
<p>This seems like a short and simple tutorial, but it is extremely frustrating to get to the point where things are working as they should. The wxwidgets tutorials are mostly outdated or lack crucial information. Then Brew baited me into trying that approach, but it kept ignoring my edits (the default is dynamic linking, which I don’t want), and even after everything was set up it was not clear to me that -arch arm64 needs to be added to the command. I am glad that everything is working now, and the next steps are packaging the binary into a .App file that can be published on the App Store. I already noticed that the wxwidgets tutorial for building on XCode is already outdated, so I will see how that goes and maybe write another post after I am successful.</p> | ||
|
||
</section> | ||
|
||
<div class="post-tags"> | ||
|
||
|
||
<nav class="nav tags"> | ||
<ul class="tags"> | ||
|
||
<li><a href="/tags/tutorial">tutorial</a></li> | ||
|
||
<li><a href="/tags/macos">macOS</a></li> | ||
|
||
<li><a href="/tags/wxwidgets">wxwidgets</a></li> | ||
|
||
</ul> | ||
</nav> | ||
|
||
|
||
</div> | ||
</article> | ||
|
||
|
||
|
||
</main> | ||
<footer> | ||
<div style="display:flex"></div> | ||
<div class="footer-info"> | ||
2023 <a | ||
href="https://github.com/athul/archie">Archie Theme</a> | Built with <a href="https://gohugo.io">Hugo</a> | ||
</div> | ||
</footer> | ||
|
||
|
||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.