3MFConsortium / lib3mf

lib3mf is an implementation of the 3D Manufacturing Format file standard
http://3mf.io
BSD 2-Clause "Simplified" License
228 stars 92 forks source link

Build broken on Apple Silicon #360

Closed JetForMe closed 3 months ago

JetForMe commented 4 months ago

M1 MacBook Pro macOS: 14.4.1 Xcode: 15.3 Apple clang: 15.0.0 cmake: 3.29.0 lib3mf branch: main

Looking to write a Swift 3MF importer, I tried to build lib3mf from source. I’m not great with cmake, so perhaps I missed a crucial step, but while the code compiles, it fails to link, I think because of an architecture mismatch. Lots and lots of

[100%] Linking CXX executable ../../Test_CPP_Bindings
ld: warning: ignoring file '…/Projects/Personal/3MFQuickLook/lib3mf/build/lib3mf.2.3.1.0.dylib': found architecture 'arm64', required architecture 'x86_64'
Undefined symbols for architecture x86_64:
  "_lib3mf_accessright_getconsumer", referenced from:
      Lib3MF::SecureContentT_ManageAccessRight_Test::TestBody() in SecureContent.cpp.o

I followed these steps to build:

  1. git clone https://github.com/3MFConsortium/lib3mf.git
  2. cd lib3mf
  3. git submodule update --init
  4. chmod a+x cmake/*.sh
  5. cmake/GenerateMake.sh
  6. cd build
  7. make

There were also a number of source-level warnings, and a couple link-related warnings:

[ 95%] Linking C static library libcrypto.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libcrypto.a(empty.c.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libcrypto.a(empty.c.o) has no symbols
[ 95%] Built target crypto
[ 95%] Building C object Tests/libressl/ssl/CMakeFiles/ssl.dir/empty.c.o
[ 95%] Linking C static library libssl.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libssl.a(empty.c.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libssl.a(empty.c.o) has no symbols
alexanderoster commented 4 months ago

Hi @JetForMe,

Thank you for using Lib3MF. I think there is an issue with the crypto library for the tests on Apple Silicon. You do not need those tests for using lib3mf.

You can disable the tests with cmake -DLIB3MF_TESTS=OFF .., or by using cmake-gui

Maybe we should disable them by default, @martinweismann @vijaiaeroastro @3dJan?

JetForMe commented 4 months ago

That does seem to let it successfully build. I have not yet tried to use it.

vijaiaeroastro commented 4 months ago

@alexanderoster We already made this behavior default with VCPKG. We can make the behavior universal if @martinweismann and @gangatp are okay with it.

gangatp commented 4 months ago

if we set this variable SET(CMAKE_OSX_ARCHITECTURES "x86_64") in https://github.com/3MFConsortium/lib3mf/blob/0dc7c6b83c06aa02b33541f4c8d547f16d9adc52/CMakeLists.txt#L242 to CMAKE_OSX_ARCHITECTURES=arm64;x86_64 for enabling universal build for test cases.

JetForMe commented 4 months ago

It seems like the test should either inherit from the main project, or default to the current architecture, no? Since you're likely only going to run the tests locally after building.

gangatp commented 4 months ago

I have PR for removing the setting CMAKE_OSX_ARCHITECTURE for TEST https://github.com/3MFConsortium/lib3mf/pull/362/files

vijaiaeroastro commented 3 months ago

We have these changes merged into develop already. Closing it for now.