【问题标题】:Can't compile Jabcode on M1 (ARM)无法在 M1 (ARM) 上编译 Jabcode
【发布时间】:2023-01-09 05:52:26
【问题描述】:

我正在尝试在我的带有 M1 ARM 的 MacBook 上编译 jab 代码(参见https://jabcode.org/create)。使用给定的 Makefile 编译 jabcode 的第一步确实成功了:

gcc -c -I. -I./include -O2 -std=c11 binarizer.c -o binarizer.o
gcc -c -I. -I./include -O2 -std=c11 decoder.c -o decoder.o
gcc -c -I. -I./include -O2 -std=c11 detector.c -o detector.o
detector.c:51:7: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
                                         fabs(state_count[1] - state_count[3]) < layer_tolerance; //layer 1 and layer 3 shall be of the same size
                                         ^
detector.c:51:7: note: use function 'abs' instead
                                         fabs(state_count[1] - state_count[3]) < layer_tolerance; //layer 1 and layer 3 shall be of the same size
                                         ^~~~
                                         abs
1 warning generated.
gcc -c -I. -I./include -O2 -std=c11 encoder.c -o encoder.o
gcc -c -I. -I./include -O2 -std=c11 image.c -o image.o
gcc -c -I. -I./include -O2 -std=c11 interleave.c -o interleave.o
gcc -c -I. -I./include -O2 -std=c11 ldpc.c -o ldpc.o
gcc -c -I. -I./include -O2 -std=c11 mask.c -o mask.o
gcc -c -I. -I./include -O2 -std=c11 pseudo_random.c -o pseudo_random.o
gcc -c -I. -I./include -O2 -std=c11 sample.c -o sample.o
gcc -c -I. -I./include -O2 -std=c11 transform.c -o transform.o
ar cru build/libjabcode.a binarizer.o decoder.o detector.o encoder.o image.o interleave.o ldpc.o mask.o pseudo_random.o sample.o transform.o
ranlib build/libjabcode.a

但是,在尝试编译 Reader 或 Writer 时,我最终得到:


gcc -c -I. -I../jabcode -I../jabcode/include -O2 -std=c11 jabwriter.c -o jabwriter.o
gcc jabwriter.o -L../jabcode/build -ljabcode -L../jabcode/lib -ltiff -lpng16 -lz -lm -O2 -std=c11 -o bin/jabcodeWriter
ld: warning: ignoring file ../jabcode/lib/libpng16.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ../jabcode/lib/libtiff.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ../jabcode/lib/libz.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
"\_TIFFClose", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFDefaultStripSize", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFOpen", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFSetField", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFWriteScanline", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_png_image_begin_read_from_file", referenced from:
\_readImage in libjabcode.a(image.o)
"\_png_image_finish_read", referenced from:
\_readImage in libjabcode.a(image.o)
"\_png_image_free", referenced from:
\_readImage in libjabcode.a(image.o)
"\_png_image_write_to_file", referenced from:
\_saveImage in libjabcode.a(image.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: \*\*\* \[bin/jabcodeWriter\] Error 1

我已经尝试将 -lstdc++ 添加到所有 Makefile 中的 CFLAGS,正如 here 所建议的那样,它会为 jabcode 生成“'链接器'输入未使用”的警告,并且在尝试编译 jabcodeWriter 的 jacbodeReader 时不会解决问题。

我还尝试通过在每个 Makefile 中将 -arch x86_64 添加到 CFLAGS 来编译为 x86_64,遵循 this question。错误仍然如上Undefined symbols for architecture x86_64 和


ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

抱歉,如果答案很明显,我不是 C/C++ 和 Makefile 方面的专家,也无法在这里找到任何解决方案。

【问题讨论】:

    标签: gcc cmake arm apple-m1


    【解决方案1】:

    我检查了 github 上的源代码,也检查了您传递给 g++ 的标志,答案很简单。

    您正在链接不是为您的体系结构构建的静态 tiff 库。查看您使用 -L 标志指向的文件夹。

    作者说他在他的 ubuntu 机器上测试了它,所以推测它是为 amd64 架构构建的。

    要解决此问题,您需要为您的机器获取链接的依赖项(tiff 是其中之一)并链接到它。在 MacOS 上,通常使用 homebrew 包管理器完成。

    【讨论】:

    • 非常感谢,会试试这个!
    • 不客气,祝你工作顺利
    猜你喜欢
    • 1970-01-01
    • 2021-09-14
    • 2023-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多