[GH-ISSUE #315] Compile libxlsxwriter for arm64 on macOS #255

Closed
opened 2026-05-05 12:02:40 -06:00 by gitea-mirror · 16 comments
Owner

Originally created by @Dirk- on GitHub (Nov 11, 2020).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/315

Originally assigned to: @jmcnamara on GitHub.

What do I have to do in order to use libxlsxwriter.a in an universal (arm64 and x86_64) macOS app? I do have Xcode 12.2 Release Candidate available, so I should have the right tools, but I am not sure where and how to mess with the makefile.

Apple Developer Documentation gives some hints, but I will probably break things when trying to adapt this.

Originally created by @Dirk- on GitHub (Nov 11, 2020). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/315 Originally assigned to: @jmcnamara on GitHub. What do I have to do in order to use libxlsxwriter.a in an universal (arm64 and x86_64) macOS app? I do have Xcode 12.2 Release Candidate available, so I should have the right tools, but I am not sure where and how to mess with the makefile. [Apple Developer Documentation](https://developer.apple.com/documentation/xcode/building_a_universal_macos_binary) gives some hints, but I will probably break things when trying to adapt this.
gitea-mirror 2026-05-05 12:02:41 -06:00
Author
Owner

@jmcnamara commented on GitHub (Nov 11, 2020):

I don't know but you could try something like this:

make clean
CFLAGS="-target x86_64-apple-macos10.12" make V=1
mv lib/libxlsxwriter.a libxlsxwriter_x86_64.a

make clean
CFLAGS="-target arm64-apple-macos11" make V=1
mv lib/libxlsxwriter.a lib/libxlsxwriter_arm64.a
mv libxlsxwriter_x86_64.a lib

lipo -create -output lib/libxlsxwriter.a lib/libxlsxwriter_x86_64.a lib/libxlsxwriter_arm64.a

If you figure it out please post an update to leave people know.

<!-- gh-comment-id:725470106 --> @jmcnamara commented on GitHub (Nov 11, 2020): I don't know but you could try something like this: ``` make clean CFLAGS="-target x86_64-apple-macos10.12" make V=1 mv lib/libxlsxwriter.a libxlsxwriter_x86_64.a make clean CFLAGS="-target arm64-apple-macos11" make V=1 mv lib/libxlsxwriter.a lib/libxlsxwriter_arm64.a mv libxlsxwriter_x86_64.a lib lipo -create -output lib/libxlsxwriter.a lib/libxlsxwriter_x86_64.a lib/libxlsxwriter_arm64.a ``` If you figure it out please post an update to leave people know.
Author
Owner

@Dirk- commented on GitHub (Nov 11, 2020):

Thanks for the quick reply! The commands work, I just had to move libxlsxwriter_x86_64.a somewhere else before the second make clean.

I got some warnings about third_party files being ignored, I will look into this and post my findings.

<!-- gh-comment-id:725495270 --> @Dirk- commented on GitHub (Nov 11, 2020): Thanks for the quick reply! The commands work, I just had to move `libxlsxwriter_x86_64.a` somewhere else before the second `make clean`. I got some warnings about third_party files being ignored, I will look into this and post my findings.
Author
Owner

@jmcnamara commented on GitHub (Nov 12, 2020):

Thanks. I've modified the instruction above to account for that. Could you post the warnings from the compilation.

I'm stuck on macOS 10.14 so I'm not sure if I can compile the arm64-apple-macos11 target. I'll download Xcode 12.2 and check in a few days.

<!-- gh-comment-id:725954087 --> @jmcnamara commented on GitHub (Nov 12, 2020): Thanks. I've modified the instruction above to account for that. Could you post the warnings from the compilation. I'm stuck on macOS 10.14 so I'm not sure if I can compile the arm64-apple-macos11 target. I'll download Xcode 12.2 and check in a few days.
Author
Owner

@Dirk- commented on GitHub (Nov 12, 2020):

I get these warnings:

cc  -dynamiclib -fPIC -install_name /usr/local/lib/libxlsxwriter.dylib  -o libxlsxwriter.dylib ../third_party/minizip/ioapi.so ../third_party/minizip/zip.so ../third_party/tmpfileplus/tmpfileplus.so ../third_party/md5/md5.so app.so chart.so chartsheet.so comment.so content_types.so core.so custom.so drawing.so format.so hash_table.so packager.so relationships.so shared_strings.so styles.so theme.so utility.so vml.so workbook.so worksheet.so xmlwriter.so -lz
ld: warning: ignoring file ../third_party/minizip/zip.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file ../third_party/minizip/ioapi.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file ../third_party/tmpfileplus/tmpfileplus.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file ../third_party/md5/md5.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file chart.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file app.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file comment.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file content_types.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file core.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file hash_table.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file custom.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file packager.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file drawing.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file format.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file chartsheet.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file styles.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file relationships.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file shared_strings.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utility.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file theme.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file worksheet.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file workbook.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file vml.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file xmlwriter.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64

Since they all refer to shared object library files and libxlsxwriter.dylib I think I can ignore them for my needs (only need the static library).

According to the release notes, Xcode 12 requires macOS 10.15.4 or later, so I am afraid it will not work on your system.

<!-- gh-comment-id:726104667 --> @Dirk- commented on GitHub (Nov 12, 2020): I get these warnings: cc -dynamiclib -fPIC -install_name /usr/local/lib/libxlsxwriter.dylib -o libxlsxwriter.dylib ../third_party/minizip/ioapi.so ../third_party/minizip/zip.so ../third_party/tmpfileplus/tmpfileplus.so ../third_party/md5/md5.so app.so chart.so chartsheet.so comment.so content_types.so core.so custom.so drawing.so format.so hash_table.so packager.so relationships.so shared_strings.so styles.so theme.so utility.so vml.so workbook.so worksheet.so xmlwriter.so -lz ld: warning: ignoring file ../third_party/minizip/zip.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file ../third_party/minizip/ioapi.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file ../third_party/tmpfileplus/tmpfileplus.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file ../third_party/md5/md5.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file chart.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file app.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file comment.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file content_types.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file core.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file hash_table.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file custom.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file packager.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file drawing.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file format.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file chartsheet.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file styles.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file relationships.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file shared_strings.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file utility.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file theme.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file worksheet.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file workbook.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file vml.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file xmlwriter.so, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 Since they all refer to shared object library files and `libxlsxwriter.dylib` I think I can ignore them for my needs (only need the static library). According to the release notes, Xcode 12 requires macOS 10.15.4 or later, so I am afraid it will not work on your system.
Author
Owner

@jmcnamara commented on GitHub (Nov 14, 2020):

According to the release notes, Xcode 12 requires macOS 10.15.4 or later, so I am afraid it will not work on your system.

When I tried to upgrade to Catalina I remembered why I hadn't done it previously. I use Excel 2011 for Mac to generate the screenshots for the docs and that is a 32bit app which isn't compatible with new versions of macOS. So I created a VM with macOS11 and Xcode 12.3 and used that to debug the issue.

Anyway, I've pushed a fix to the main branch with a new make target called universal_binary:

$ make universal_binary

$ lipo -archs lib/libxlsxwriter.a
x86_64 arm64

$ lipo -archs lib/libxlsxwriter.dylib
x86_64 arm64

You can try it and let me know how you get on.

<!-- gh-comment-id:727268580 --> @jmcnamara commented on GitHub (Nov 14, 2020): > According to the release notes, Xcode 12 requires macOS 10.15.4 or later, so I am afraid it will not work on your system. When I tried to upgrade to Catalina I remembered why I hadn't done it previously. I use Excel 2011 for Mac to generate the screenshots for the docs and that is a 32bit app which isn't compatible with new versions of macOS. So I created a VM with macOS11 and Xcode 12.3 and used that to debug the issue. Anyway, I've pushed a fix to the main branch with a new make target called `universal_binary`: ```sh $ make universal_binary $ lipo -archs lib/libxlsxwriter.a x86_64 arm64 $ lipo -archs lib/libxlsxwriter.dylib x86_64 arm64 ``` You can try it and let me know how you get on.
Author
Owner

@Dirk- commented on GitHub (Nov 15, 2020):

It builds on my system without a warning and the universal binary lib works in my project for the x86_64 side. I cannot tell if the arm64 version works since I do not have an Apple Silicon Mac yet.

Thank you very much!

<!-- gh-comment-id:727526995 --> @Dirk- commented on GitHub (Nov 15, 2020): It builds on my system without a warning and the universal binary lib works in my project for the x86_64 side. I cannot tell if the arm64 version works since I do not have an Apple Silicon Mac yet. Thank you very much!
Author
Owner

@Dirk- commented on GitHub (Nov 15, 2020):

@jmcnamara I reopened the issue for information. Feel free to close it, I do not know what you normally do with questions.

<!-- gh-comment-id:727527323 --> @Dirk- commented on GitHub (Nov 15, 2020): @jmcnamara I reopened the issue for information. Feel free to close it, I do not know what you normally do with questions.
Author
Owner

@jmcnamara commented on GitHub (Nov 15, 2020):

I'll leave it open until I add some corresponding documentation and then I'll close it. Thanks for the report and the testing.

<!-- gh-comment-id:727558710 --> @jmcnamara commented on GitHub (Nov 15, 2020): I'll leave it open until I add some corresponding documentation and then I'll close it. Thanks for the report and the testing.
Author
Owner

@evanmiller commented on GitHub (Nov 17, 2020):

With CMake it is sufficient to set

//Build architectures for OSX
CMAKE_OSX_ARCHITECTURES:STRING=x86_64;arm64

in your CMakeCache.txt. This will ensure that all builds are universal binaries. Lipo etc are unnecessary.

<!-- gh-comment-id:728568978 --> @evanmiller commented on GitHub (Nov 17, 2020): With CMake it is sufficient to set ``` //Build architectures for OSX CMAKE_OSX_ARCHITECTURES:STRING=x86_64;arm64 ``` in your CMakeCache.txt. This will ensure that all builds are universal binaries. Lipo etc are unnecessary.
Author
Owner

@jmcnamara commented on GitHub (Nov 17, 2020):

@evanmiller Thanks That's much cleaner. I'll add that to the docs.

I could put the x86 part in the CMakeLists.txt file and users could add the arm64 part as needed:

CMAKE_OSX_ARCHITECTURES:STRING=x86_64

Do you see any issue with that?

<!-- gh-comment-id:728745178 --> @jmcnamara commented on GitHub (Nov 17, 2020): @evanmiller Thanks That's much cleaner. I'll add that to the docs. I could put the x86 part in the CMakeLists.txt file and users could add the arm64 part as needed: ``` CMAKE_OSX_ARCHITECTURES:STRING=x86_64 ``` Do you see any issue with that?
Author
Owner

@evanmiller commented on GitHub (Nov 17, 2020):

@jmcnamara At this point I'd actually make x86_64;arm64 the default. The newest non-beta Xcode supports it, and it appears that all future Apple hardware will be ARM. Universal binaries are backwards compatible, so this setting won't affect deployment to older operating systems.

The only downside I see is it might result in complaints and confusion from people who haven't updated to Xcode 12.2 yet.

<!-- gh-comment-id:728842610 --> @evanmiller commented on GitHub (Nov 17, 2020): @jmcnamara At this point I'd actually make `x86_64;arm64` the default. The newest non-beta Xcode supports it, and it appears that all future Apple hardware will be ARM. Universal binaries are backwards compatible, so this setting won't affect deployment to older operating systems. The only downside I see is it might result in complaints and confusion from people who haven't updated to Xcode 12.2 yet.
Author
Owner

@jmcnamara commented on GitHub (Nov 18, 2020):

@evanmiller I think the warnings/errors with Xcode < 12.2 would be too confusing for users so I probably won't add this to the CMakeLists.txt file.

Instead I'll document it as follows:

cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
<!-- gh-comment-id:729623720 --> @jmcnamara commented on GitHub (Nov 18, 2020): @evanmiller I think the warnings/errors with Xcode < 12.2 would be too confusing for users so I probably won't add this to the CMakeLists.txt file. Instead I'll document it as follows: ``` cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ```
Author
Owner

@jmcnamara commented on GitHub (Mar 22, 2021):

Added docs on how to compile a universal binary version of libxlsxwriter: https://libxlsxwriter.github.io/getting_started.html#gsg_universal

<!-- gh-comment-id:804256958 --> @jmcnamara commented on GitHub (Mar 22, 2021): Added docs on how to compile a universal binary version of libxlsxwriter: https://libxlsxwriter.github.io/getting_started.html#gsg_universal
Author
Owner

@Whaat commented on GitHub (Dec 31, 2021):

Using 'make universal_binary' with current version gives a fatal error:
lib/libxlsxwriter_x86_64.dylib and lib/libxlsxwriter_arm64.dylib have the same architectures (arm64) and can't be in the same fat output file.

After seeing this error, I tried building the universal binary using cmake and it appears to have worked.

<!-- gh-comment-id:1003405706 --> @Whaat commented on GitHub (Dec 31, 2021): Using 'make universal_binary' with current version gives a fatal error: lib/libxlsxwriter_x86_64.dylib and lib/libxlsxwriter_arm64.dylib have the same architectures (arm64) and can't be in the same fat output file. After seeing this error, I tried building the universal binary using cmake and it appears to have worked.
Author
Owner

@jmcnamara commented on GitHub (Jan 1, 2022):

@Whaat Thanks for the report. I can see the issue and will fix it soon.

<!-- gh-comment-id:1003608416 --> @jmcnamara commented on GitHub (Jan 1, 2022): @Whaat Thanks for the report. I can see the issue and will fix it soon.
Author
Owner

@jmcnamara commented on GitHub (Jan 3, 2022):

@Whaat I've pushed a fix to main.

<!-- gh-comment-id:1004309388 --> @jmcnamara commented on GitHub (Jan 3, 2022): @Whaat I've pushed a fix to main.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#255
No description provided.