LostArtefacts / TR1X

Open source re-implementation of Tomb Raider 1 (1996), along with additional enhancements and bugfixes
https://lostartefacts.dev/
GNU General Public License v3.0
469 stars 32 forks source link

Troubles when building TR1X #1373

Open carlo-bramini opened 1 month ago

carlo-bramini commented 1 month ago

I tried to update my build with latest sources before starting to work on issue #667, but it looks like I cannot compile them anymore. After running meson compile, I got these errors on the console:

$ meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja
[7/202] Compiling C object subprojects/libtrx/liblibtrx.a.p/src_engine_audio_sample.c.o
FAILED: subprojects/libtrx/liblibtrx.a.p/src_engine_audio_sample.c.o
cc -Isubprojects/libtrx/liblibtrx.a.p -Isubprojects/libtrx -I../TR1X/subprojects/libtrx -I../TR1X/subprojects/libtrx/include/libtrx -I../TR1X/subprojects/libtrx/src -I/usr/include/SDL2 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c11 -O0 -g -Wno-unused -DMESON_BUILD -DPCRE2_STATIC -DPCRE2_CODE_UNIT_WIDTH=8 -D_REENTRANT -MD -MQ subprojects/libtrx/liblibtrx.a.p/src_engine_audio_sample.c.o -MF subprojects/libtrx/liblibtrx.a.p/src_engine_audio_sample.c.o.d -o subprojects/libtrx/liblibtrx.a.p/src_engine_audio_sample.c.o -c ../TR1X/subprojects/libtrx/src/engine/audio_sample.c
../TR1X/subprojects/libtrx/src/engine/audio_sample.c: In function ‘Audio_Sample_LoadSingle’:
../TR1X/subprojects/libtrx/src/engine/audio_sample.c:358:44: error: ‘AVCodecContext’ has no member named ‘channels’
  358 |             swr.src_channels = av.codec_ctx->channels;
      |                                            ^~
../TR1X/subprojects/libtrx/src/engine/audio_sample.c:363:23: warning: implicit declaration of function ‘swr_alloc_set_opts’; did you mean ‘swr_alloc_set_opts2’? [-Wimplicit-function-declaration]
  363 |             swr.ctx = swr_alloc_set_opts(
      |                       ^~~~~~~~~~~~~~~~~~
      |                       swr_alloc_set_opts2
../TR1X/subprojects/libtrx/src/engine/audio_sample.c:363:21: warning: assignment to ‘SwrContext *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  363 |             swr.ctx = swr_alloc_set_opts(
      |                     ^
../TR1X/subprojects/libtrx/src/engine/audio_sample.c:466:9: warning: ‘avcodec_close’ is deprecated [-Wdeprecated-declarations]
  466 |         avcodec_close(av.codec_ctx);
      |         ^~~~~~~~~~~~~
In file included from ../TR1X/subprojects/libtrx/src/engine/audio_sample.c:9:
/usr/include/libavcodec/avcodec.h:2387:5: note: declared here
 2387 | int avcodec_close(AVCodecContext *avctx);
      |     ^~~~~~~~~~~~~
[9/202] Compiling C object subprojects/libtrx/liblibtrx.a.p/src_engine_audio_stream.c.o
FAILED: subprojects/libtrx/liblibtrx.a.p/src_engine_audio_stream.c.o
cc -Isubprojects/libtrx/liblibtrx.a.p -Isubprojects/libtrx -I../TR1X/subprojects/libtrx -I../TR1X/subprojects/libtrx/include/libtrx -I../TR1X/subprojects/libtrx/src -I/usr/include/SDL2 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c11 -O0 -g -Wno-unused -DMESON_BUILD -DPCRE2_STATIC -DPCRE2_CODE_UNIT_WIDTH=8 -D_REENTRANT -MD -MQ subprojects/libtrx/liblibtrx.a.p/src_engine_audio_stream.c.o -MF subprojects/libtrx/liblibtrx.a.p/src_engine_audio_stream.c.o.d -o subprojects/libtrx/liblibtrx.a.p/src_engine_audio_stream.c.o -c ../TR1X/subprojects/libtrx/src/engine/audio_stream.c
../TR1X/subprojects/libtrx/src/engine/audio_stream.c: In function ‘Audio_Stream_EnqueueFrame’:
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:153:56: error: ‘AVCodecContext’ has no member named ‘channels’
  153 |         stream->swr.src_channels = stream->av.codec_ctx->channels;
      |                                                        ^~
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:158:27: warning: implicit declaration of function ‘swr_alloc_set_opts’; did you mean ‘swr_alloc_set_opts2’? [-Wimplicit-function-declaration]
  158 |         stream->swr.ctx = swr_alloc_set_opts(
      |                           ^~~~~~~~~~~~~~~~~~
      |                           swr_alloc_set_opts2
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:158:25: warning: assignment to ‘SwrContext *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  158 |         stream->swr.ctx = swr_alloc_set_opts(
      |                         ^
../TR1X/subprojects/libtrx/src/engine/audio_stream.c: In function ‘Audio_Stream_InitialiseFromPath’:
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:329:48: error: ‘AVCodecContext’ has no member named ‘channels’
  329 |     int32_t sdl_channels = stream->av.codec_ctx->channels;
      |                                                ^~
../TR1X/subprojects/libtrx/src/engine/audio_stream.c: In function ‘Audio_Stream_Close’:
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:479:9: warning: ‘avcodec_close’ is deprecated [-Wdeprecated-declarations]
  479 |         avcodec_close(stream->av.codec_ctx);
      |         ^~~~~~~~~~~~~
In file included from ../TR1X/subprojects/libtrx/src/engine/audio_stream.c:11:
/usr/include/libavcodec/avcodec.h:2387:5: note: declared here
 2387 | int avcodec_close(AVCodecContext *avctx);
      |     ^~~~~~~~~~~~~
../TR1X/subprojects/libtrx/src/engine/audio_stream.c: In function ‘Audio_Stream_Mix’:
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:612:37: error: ‘AVCodecContext’ has no member named ‘channels’
  612 |             if (stream->av.codec_ctx->channels == AUDIO_WORKING_CHANNELS) {
      |                                     ^~
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:618:44: error: ‘AVCodecContext’ has no member named ‘channels’
  618 |             } else if (stream->av.codec_ctx->channels == 1) {
      |                                            ^~
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:629:65: error: ‘AVCodecContext’ has no member named ‘channels’
  629 |                     for (int32_t i = 0; i < stream->av.codec_ctx->channels;
      |                                                                 ^~
../TR1X/subprojects/libtrx/src/engine/audio_stream.c:633:62: error: ‘AVCodecContext’ has no member named ‘channels’
  633 |                     src_sample /= (float)stream->av.codec_ctx->channels;
      |                                                              ^~
[12/202] Compiling C object subprojects/libtrx/liblibtrx.a.p/src_strings.c.o
ninja: build stopped: subcommand failed.

It looks like that FFMPEG 6 brutally removed some deprecated functions from the libraries and some items from the structures like AVCodecContext. Perhaps, it would be worth to check the version of FFMPEG with some #ifdef ... #endif so that it will be possible to compile the sources indipendently by API changes like this one, but at the moment I didn't do it. So, I tried to build again an executable for Windows by using FFMPEG 5 instead. This time, the build process was able to compile those files, although it printed on the console some warnings about those deprecated functions, but at the end this was not important at all. Unfortunately, it stopped again with other errors like this one after short time:

[11/206] Generating fake_init with a custom command
FAILED: init.c
/usr/bin/python3 /home/carlo/TR1X/tools/generate_init -o /home/carlo/tr1x-build/init.c
Traceback (most recent call last):
  File "/home/carlo/TR1X/tools/generate_init", line 5, in <module>
    from libtrx.versioning import generate_version
  File "/home/carlo/TR1X/tools/libtrx/versioning.py", line 3, in <module>
    from libtrx.git import Git
  File "/home/carlo/TR1X/tools/libtrx/git.py", line 5, in <module>
    class Git:
  File "/home/carlo/TR1X/tools/libtrx/git.py", line 6, in Git
    def __init__(self, repo_dir: Path | None = None) -> None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

I don't know Python at all, but according to the information into this post:

https://stackoverflow.com/questions/76712720/typeerror-unsupported-operand-types-for-type-and-nonetype

it has been written that str | None syntax is only supported in 3.10 or later. Since I'm stuck with version 3.9 and I have not experience with Python programming, I have no way to bypass this trouble at the moment.

rr- commented 1 month ago

Please use Docker builds to mitigate all of these.

carlo-bramini commented 1 month ago

At the moment, I bypassed the trouble with Python by resurrecting my CMakeLists.txt in my fork and I used it for building the executable. Actually, the CMake script could be also used for doing the same tasks executed by Python without troubles with its version, if someone wants. About support for latest FFMPEG, at the moment the quickest solution is to use version 5 until some #ifdef...#endif will make the code universal.