无法在M1(ARM)上编译Jabcode。

huangapple go评论64阅读模式
英文:

Can't compile Jabcode on M1 (ARM)

问题

我正在尝试在我的装有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

然而,在尝试编译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

出现了以下错误:

Undefined symbols for architecture arm64:
...
ld: symbol(s) not found for architecture arm64

我已经尝试在所有Makefiles中的CFLAGS中添加了-lstdc++,如此处建议:https://stackoverflow.com/questions/11852568/gcc-4-8-on-mac-os-x-v10-8-throws-undefined-symbols-for-architecture-x86-64,但对于jabcode生成了“链接器未使用的输入”警告,并且在尝试编译jacbodeReader或jabcodeWriter时没有解决问题。

我还尝试以x86_64的方式编译,参照此问题:https://stackoverflow.com/questions/71422088/how-can-i-compile-x86-64-asm-code-on-m1-mac-arm,通过在每个Makefile中的CFLAGS中添加了-arch x86_64。错误仍然如上所述,出现了“Undefined symbols for architecture x86_64”以及:

ld: symbol(s) not found for architecture x86_64

如果答案显而易见,请原谅,我不是C/C++和Makefiles方面的专家,也无法在这里找到任何解决方案。

英文:

I'am trying to compile jab code (cf. https://jabcode.org/create) on my MacBook with M1 ARM. I do succeed with the first step of compiling jabcode with the given Makefile:

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

However, when trying to compile the Reader or Writer, I end up with:


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

I already tried to add -lstdc++ to CFLAGS in all Makefiles, as suggested here, which generates warnings of "'linker' input unused" for jabcode and does not resolve the problems when trying to compile jacbodeReader of jabcodeWriter.

Also I tried to compile as x86_64, following this question, by adding -arch x86_64 to CFLAGS in each Makefile. The error remained as above Undefined symbols for architecture x86_64 and


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

Sorry if the answer is obvious, I'm no expert in C/C++ and Makefiles and could not find any solution here.

答案1

得分: 0

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

您正在链接到一个未构建为您的架构的静态tiff库。查看您使用-L标志指向的文件夹。

作者表示他在他的ubuntu机器上进行了测试,所以可能是为amd64架构构建的。

要解决这个问题,您需要获取适用于您的机器并链接的依赖项(tiff是其中之一)。在MacOS上,通常使用homebrew包管理器来完成这个操作。

英文:

I've checked the sources on github and I've checked the flags that you pass to g++ and the answer is quite simple.

You are linking against a static tiff library that wasn't build for your architecture. Look at the folder to which you point with the -L flag.

The author states that he tested it on his ubuntu machine so presumably it is build for the amd64 architecture.

To solve this you need to get the dependencies that you link (tiff is one of them) for your machine and link against it. On MacOS that is usually done using the homebrew package manager.

huangapple
  • 本文由 发表于 2023年1月8日 23:30:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定