Opened 13 months ago
Last modified 10 months ago
#6797 new defect
Error when building on macOS (SDL2 -Werror)
Reported by: | Dmitry | Owned by: | |
---|---|---|---|
Priority: | Must Have | Milestone: | Alpha 27 |
Component: | Build & Packages | Keywords: | macOS build errors |
Cc: | Dmitry, John-Mason Shackelford | Patch: | D5092 |
Description
Hi all!
My Environment:
- MacBook Pro 2021
- Chip: M1 Max
- RAM: 32GB
- OS Venture 13.3.1
When I try to build the game: cd libraries/osx and run script ./build-osx-libs.sh -j3 I have some errors:
In file included from /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/SDL_hidapi.c:578: /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:163:23: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] struct input_report *rpt = dev->input_reports; ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:265:11: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] CFIndex str_len = CFStringGetLength(str); ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:304:11: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] CFIndex str_len = CFStringGetLength(str); ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:576:11: warning: variable 'len' set but not used [-Wunused-but-set-variable] size_t len; ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:563:19: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] extern SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device); ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:533:11: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:744:25: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] CFRunLoopSourceContext ctx; ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:850:34: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] struct hid_device_list_node *node = (struct hid_device_list_node *)calloc(1, sizeof(struct hid_device_list_node)); ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:821:10: warning: variable 'len' set but not used [-Wunused-but-set-variable] size_t len; ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:814:11: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); ^ /Users/yanadima/Work/0ad/libraries/osx/sdl2/SDL2-2.0.18/src/hidapi/mac/hid.c:1090:6: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement] int skipped_report_id = 0; ^ 2 warnings and 9 errors generated. CC build/e_rem_pio2.lo CC build/e_sqrt.lo CC build/k_rem_pio2.lo CC build/k_cos.lo CC build/k_sin.lo CC build/k_tan.lo make: *** [build/SDL_hidapi.lo] Error 1 make: *** Waiting for unfinished jobs.... ERROR: SDL2 build failed
Previously I have complete successfully setup Dependencies.
I suspect that the error lies in the wrong choice of the C++ standard, but I can not find where to change it in the script build-osx-libs.sh
I tried to change this variable (in script build-osx-libs.sh) but it didn't help.
CXXFLAGS="$CXXFLAGS $C_FLAGS -stdlib=libc++ -std=c++17"
Help Me Please
Attachments (2)
Change History (21)
comment:1 by , 13 months ago
Milestone: | Backlog → Alpha 27 |
---|
follow-up: 3 comment:2 by , 13 months ago
comment:3 by , 13 months ago
Replying to Ralph Sennhauser:
Looks like your C compiler defaults to an older standard, maybe try
CFLAGS="-std=c99" ./build-osx-libs.sh -j3
Guess you also have plenty cpu cores, so instead of -j3 you might want -j8 or so to speed up compilation.
Thank You for answer! I tried do CFLAGS="-std=c99" ./build-osx-libs.sh -j3
, but still same errors. I also tried -j3 instead of -j10 (I have 10 cores) and the build process became much faster. Thank you!
follow-up: 5 comment:4 by , 13 months ago
- Can you try the latest
SDL
version?
-
libraries/osx/build-osx-libs.sh
a b ZLIB_VERSION="zlib-1.2.11" 24 24 CURL_VERSION="curl-7.71.0" 25 25 ICONV_VERSION="libiconv-1.16" 26 26 XML2_VERSION="libxml2-2.9.10" 27 SDL2_VERSION="SDL2-2. 0.18"27 SDL2_VERSION="SDL2-2.26.5" 28 28 # NOTE: remember to also update LIB_URL below when changing version 29 29 BOOST_VERSION="boost_1_76_0" 30 30 # NOTE: remember to also update LIB_URL below when changing version
follow-up: 6 comment:5 by , 13 months ago
Replying to Langbart:
- Can you try the latest
SDL
version? - Ref: libsdl-org/SDL #6330#!diff --- a/libraries/osx/build-osx-libs.sh +++ b/libraries/osx/build-osx-libs.sh @@ -24,7 +24,7 @@ ZLIB_VERSION="zlib-1.2.11" CURL_VERSION="curl-7.71.0" ICONV_VERSION="libiconv-1.16" XML2_VERSION="libxml2-2.9.10" -SDL2_VERSION="SDL2-2.0.18" +SDL2_VERSION="SDL2-2.26.5" # NOTE: remember to also update LIB_URL below when changing version BOOST_VERSION="boost_1_76_0" # NOTE: remember to also update LIB_URL below when changing version
After this change, the build continued successfully, but I ran into another problem
./build.sh: line 28: die: command not found ERROR: Error building FCollada
Before this error, I had another error during the SpiderMonkey build step. It was necessary to install the cargo port install cargo
. I use macports instead of homebrew, maybe when i installed rust the cargo didn't install.
follow-up: 8 comment:6 by , 13 months ago
Replying to Dmitry:
After this change, the build continued successfully, but I ran into another problem
./build.sh: line 28: die: command not found ERROR: Error building FColladaBefore this error, I had another error during the SpiderMonkey build step. It was necessary to install the cargo
port install cargo
. I use macports instead of homebrew, maybe when i installed rust the cargo didn't install.
- Try the recommendations at the end of this forum post:
- libxml file not found bug when building Fcollada on Mac OSX (7/Aug/20)
- Ref: #5798
PS: If everything works out, you can edit wiki/BuildInstructions#macOS !
comment:7 by , 13 months ago
Priority: | Should Have → Must Have |
---|---|
Summary: | Error when building on macOS → Error when building on macOS (SDL2 -Werror) |
SDL adds "-Wdeclaration-after-statement -Werror=declaration-after-statement" to CFLAGS, so it's not about the C standard used but that likely this diagnostic became supported on recent Apple clang (what I suspect is used here) and so now the build fails.
Updating SDL2 certainly isn't bad but sed-ing / patching out all forced Werror should be done anyway.
follow-ups: 9 10 comment:8 by , 13 months ago
Replying to Langbart:
Replying to Dmitry :
After this change, the build continued successfully, but I ran into another problem
./build.sh: line 28: die: command not found ERROR: Error building FCollada
Before this error, I had another error during the SpiderMonkey build step. It was necessary to install the cargoport install cargo
. I use macports instead of homebrew, maybe when i installed rust the cargo didn't install.
- Try the recommendations at the end of this forum post: - libxml file not found bug when building Fcollada on Mac OSX (7/Aug/20) - Ref: #5798 PS: If everything works out, you can edit [|wiki/BuildInstructions#macOS ] !
I tried to do this, if I understood correctly, then it was about installing libxml2. I tried to install it, I already had it. Just in case, I reinstalled it, but still got the same error when building
17 warnings generated. ./build.sh: line 28: die: command not found ERROR: Error building FCollada
Before this message no errors. I can attach these 17 warnings if it makes sense.
comment:9 by , 13 months ago
Replying to Dmitry:
Replying to Langbart:
Replying to Dmitry :
After this change, the build continued successfully, but I ran into another problem
./build.sh: line 28: die: command not found ERROR: Error building FCollada
Before this error, I had another error during the SpiderMonkey build step. It was necessary to install the cargoport install cargo
. I use macports instead of homebrew, maybe when i installed rust the cargo didn't install.
- Try the recommendations at the end of this forum post: - libxml file not found bug when building Fcollada on Mac OSX (7/Aug/20) - Ref: #5798 PS: If everything works out, you can edit [|wiki/BuildInstructions#macOS ] !
I tried to do this, if I understood correctly, then it was about installing libxml2. I tried to install it, I already had it. Just in case, I reinstalled it, but still got the same error when building
17 warnings generated. ./build.sh: line 28: die: command not found ERROR: Error building FColladaBefore this message no errors. I can attach these 17 warnings if it makes sense.
Yes there are some errors thrown before, they are pretty far before in the output
FCollada/FUtils/FUUri.cpp In file included from FCollada/FUtils/FUStringBuilder.cpp:11: In file included from FCollada/FUtils/FUStringBuilder.hpp:16: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/regex:771: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:18: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:853: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/compressed_pair.h:16: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:227: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/utility:251: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/compare:145: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__compare/compare_partial_order_fallback.h:13: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__compare/partial_order.h:14: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__compare/weak_order.h:14: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__compare/strong_order.h:18: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:593:12: error: reference to unresolved using declaration return isinf(__lcpp_x); ^ FCollada/FUtils/Platforms.h:133:15: note: expanded from macro 'isinf' #define isinf __isinff ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:325:1: note: using declaration annotated with 'using_if_exists' here using ::isinf _LIBCPP_USING_IF_EXISTS; ^ In file included from FCollada/FUtils/FUSemaphore.cpp:10: FCollada/FUtils/FUSemaphore.h:34:11: warning: private field 'semaphoreHandle' is not used [-Wunused-private-field] MPTaskID semaphoreHandle; ^
The output is pretty long, I don't know exactly how much of it is relevant to diagnose where the issue is. Please let me know if we need a longer version of the output
follow-ups: 11 12 comment:10 by , 13 months ago
Replying to Dmitry:
Before this message no errors. I can attach these 17 warnings if it makes sense.
- somewhere at least one error must have been reported in the logs
- The output might be rather long, but you can search for a line with
error: ...
If you unsetted the set -e
it would probably go through, but may fail later.
-
libraries/source/fcollada/build.sh
a b 1 1 #!/bin/sh 2 set -e2 # set -e 3 3 LIB_VERSION="fcollada-3.05+wildfiregames.6" 4 4 JOBS=${JOBS:="-j2"} 5 5 MAKE=${MAKE:="make"}
comment:11 by , 13 months ago
Replying to Langbart:
Replying to Dmitry:
Before this message no errors. I can attach these 17 warnings if it makes sense.
- somewhere at least one error must have been reported in the logs
- The output might be rather long, but you can search for a line with
error: ...
If you unsetted the
set -e
it would probably go through, but may fail later.
libraries/source/fcollada/build.sh
a b 1 1 #!/bin/sh 2 set -e2 # set -e 3 3 LIB_VERSION="fcollada-3.05+wildfiregames.6" 4 4 JOBS=${JOBS:="-j2"} 5 5 MAKE=${MAKE:="make"}
Hi Langbart
I'm also on an M1 Mac having the same issue with the fcollada lib build failing
Please refer to the attachment with the output of the build for the error reference
by , 13 months ago
Attachment: | fcollada_build_errors.txt added |
---|
comment:12 by , 13 months ago
Replying to Langbart:
Replying to Dmitry:
Before this message no errors. I can attach these 17 warnings if it makes sense.
- somewhere at least one error must have been reported in the logs
- The output might be rather long, but you can search for a line with
error: ...
If you unsetted the
set -e
it would probably go through, but may fail later.
libraries/source/fcollada/build.sh
a b 1 1 #!/bin/sh 2 set -e2 # set -e 3 3 LIB_VERSION="fcollada-3.05+wildfiregames.6" 4 4 JOBS=${JOBS:="-j2"} 5 5 MAKE=${MAKE:="make"}
I tried to disable set -e
but got the same error, only new warnings added
17 warnings generated. 32 warnings generated. 17 warnings generated. ./build.sh: line 28: die: command not found
Ok, according to the error, the problem we have is the missing command in the script libraries/source/fcollada/build.sh on line 28
Here this row:
(cd src && rm -rf "output/" && "${MAKE}" clean && CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" && LDFLAGS="$LDFLAGS" "${MAKE}" "${JOBS}") || die "FCollada build failed"
Maybe problem is here?
P.S. In the attachment, I added my output of the build process
comment:13 by , 13 months ago
isinf
is defined in C99 / C++11 in math.h so that should be used. __isinff
is not in the standard but an implementation detail so might have been dropped.
Could you please file a different bug as it's unrelated to the original bug about SDL?
follow-up: 15 comment:14 by , 13 months ago
Testing macOS fcollada build on a GitHub
runner:
- the issue might have been introduced with a change to the
Xcode Command Line Tools
macOS | operating system infos | versions | build fcollada |
---|---|---|---|
13.3.1 | Darwin Mac-1682925976286.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64 | Xcode command line tools version: 14.3.0.0.1.1679647830 Xcode version: 14.2 cmake version: 3.26.3 Apple clang version: 14.0.0 (clang-1400.0.29.202) | Fails |
12.6.5 | Darwin Mac-1682943948433.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Mar 9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64 x86_64 | Xcode command line tools version: 14.2.0.0.1.1668646533 Xcode version: 14.2 cmake version: 3.26.3 Apple clang version: 14.0.0 (clang-1400.0.29.202) | Success |
EDIT1: update the version
numbers from github.com/actions/runner-images - Available Images
Could you try the following and compile again?
-
libraries/source/fcollada/src/FCollada/FUtils/Platforms.h
a b 67 67 #include <wchar.h> 68 68 69 69 #elif defined(__APPLE__) 70 #include <cmath> 70 71 #include <ctype.h> 71 72 #include <wctype.h> 72 73 #include <unistd.h>
EDIT2: In order to compile the game, you must make the following change as well.
-
libraries/source/fcollada/include/FUtils/Platforms.h
a b 67 67 #include <wchar.h> 68 68 69 69 #elif defined(__APPLE__) 70 #include <cmath> 70 71 #include <ctype.h> 71 72 #include <wctype.h> 72 73 #include <unistd.h>
comment:15 by , 13 months ago
Replying to Langbart:
Testing macOS fcollada build on a
GitHub
runner:
- the issue might have been introduced with a change to the
Xcode Command Line Tools
(2397)
macOS operating system infos versions build fcollada 13.3.1 Darwin
Mac-1682925976286.local 22.4.0
Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023;
root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64xcode-select version 2397
cmake version 3.26.3
Apple clang version 14.0.0 (clang-1400.0.29.202)Fails 12.6.5 Darwin
Mac-1682943948433.local 21.6.0
Darwin Kernel Version 21.6.0: Thu Mar 9 20:08:59 PST 2023;
root:xnu-8020.240.18.700.8~1/RELEASE_X86_64 x86_64xcode-select version 2395
cmake version 3.26.3
Apple clang version 14.0.0 (clang-1400.0.29.202)Success
Could you try the following and compile again?
libraries/source/fcollada/src/FCollada/FUtils/Platforms.h
a b 67 67 #include <wchar.h> 68 68 69 69 #elif defined(__APPLE__) 70 #include <cmath> 70 71 #include <ctype.h> 71 72 #include <wctype.h> 72 73 #include <unistd.h>
After this change, I have build successful! Thank you, very much!
3 warnings generated. 19 warnings generated. 17 warnings generated. 17 warnings generated. output/libFColladaSR.a
comment:16 by , 12 months ago
I'm having the same build issue. I'm on a Mac mini with M1 chip.
I changed the SDL 2 version a s mentioned in this discussion, but now I have a boost build error :
cp "bin.v2/tools/boost_install/BoostConfigVersion .cmake" "/Users/sidoali/Desktop/zero-ad-dev/0ad/libraries/osx/boost/lib/cmake/Boost-1.82.0/BoostConfigVersion .cmake" ...failed updating 11 targets... ...skipped 15 targets... ...updated 17017 targets... ERROR: Boost build failed
comment:17 by , 12 months ago
@moolsbytheway
Currently, 0 A.D.
uses boost version 1.76.0.
libraries/osx/build-osx-libs.sh
Line | |
---|---|
27 | SDL2_VERSION="SDL2-2.26.5" |
28 | # NOTE: remember to also update LIB_URL below when changing version |
29 | BOOST_VERSION="boost_1_76_0" |
30 | # NOTE: remember to also update LIB_URL below when changing version |
31 | WXWIDGETS_VERSION="wxWidgets-3.1.4" |
Line | |
---|---|
390 | echo -e "Building Boost..." |
391 | |
392 | LIB_VERSION="${BOOST_VERSION}" |
393 | LIB_ARCHIVE="$LIB_VERSION.tar.bz2" |
394 | LIB_DIRECTORY="$LIB_VERSION" |
395 | LIB_URL="https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/" |
396 | |
397 | mkdir -p boost |
398 | pushd boost > /dev/null |
- the error messages indicated you have 1.82.0 installed under
.../libraries/osx/boost/lib/cmake/Boost-1.82.0/BoostConfigVersion
- currently the latest release of
boost
is 1.82.0- Source: boostorg.jfrog.io
- can you remove your
boost
folder underlibraries/osx/boost
and verify that yourbuild-osx-libs.sh
has both in line 29 and 395 the boost version as shown above and try to compile again.
- currently unable to reproduce your error
comment:18 by , 10 months ago
I have reproduced the error and fix against MacBook Pro i9, Ventura 13.4.1. I have opened https://code.wildfiregames.com/D5092 with the code change.
comment:19 by , 10 months ago
Cc: | added |
---|---|
Patch: | → D5092 |
Looks like your C compiler defaults to an older standard, maybe try
Guess you also have plenty cpu cores, so instead of -j3 you might want -j8 or so to speed up compilation.