Compile error OSX - macos

I'm trying to compile a program called PEAR and it seems there is something wrong at this step.
I have Xcode installed.
Bernardos-MacBook-Pro:pear-0.9.0-src bernardo$ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C src all
gcc -c -Wall -fomit-frame-pointer -O3 -lm pear-pt.c -o pear-pt.o
clang: warning: -lm: 'linker' input unused
gcc -c -Wall -fomit-frame-pointer -O3 -lm reader.c -o reader.o
clang: warning: -lm: 'linker' input unused
reader.c:670:1: warning: unused function 'do_cpuid' [-Wunused-function]
do_cpuid(uint32_t selector, uint32_t *data)
^
1 warning generated.
gcc -Wall -fomit-frame-pointer -O3 -lm pear-pt.o args.o statistics.o reader.o -lm -lpthread -o pear
ld: warning: ignoring file args.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): args.o
ld: warning: ignoring file statistics.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): statistics.o
Undefined symbols for architecture x86_64:
"_decode_switches", referenced from:
_main in pear-pt.o
"_stat_test2", referenced from:
_assembly_FORWARD_LONGER in pear-pt.o
_assembly_READS_EQUAL in pear-pt.o
_assembly_REVERSE_LONGER in pear-pt.o
_assembly in pear-pt.o
"_usage", referenced from:
_main in pear-pt.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [pear] Error 1
make: *** [all] Error 2

Related

How to solve the Error of Undefined symbols for architecture arm64 when compiling use gcc

I am trying to use MacBook Air 2022 compile a package. However, when I compiled the Makeile, the error of Undefined symbols for architecture arm64 responsed. I looked for many resolutions but all unhelpful.
The Makefile as follow:
CC = gcc-12 -Os -fopenmp
CFLAGS = -L/usr/local/sac/lib -lsac -lsacio -lm
BIN = ../bin
FDTCC: FDTCC.o sacio.o
${CC} -o ${BIN}/$# $^ ${CFLAGS}
clean:
rm -f \*.o
the whole error as follow:
gcc-12 -Os -fopenmp -o ../bin/FDTCC FDTCC.o sacio.o -L/usr/local/sac/lib -lsac -lsacio -lm
ld: warning: ignoring file /usr/local/sac/lib/libsac.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 /usr/local/sac/lib/libsacio.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:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make: *** [FDTCC] Error 1
My gcc version as follow:
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Could anyone tell me how to slove this error, thanks.

Can't compile Jabcode on M1 (ARM)

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.
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.

nasm and ld: xxx not specified for Mac OS Ventura

I tried to assemble a Hello World but ld is throwing me a couple of errors.
Hello World:
section .data
msg db "Hello world",10
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
nasm & ld:
nasm -f elf64 main.asm
ld main.o -o main
ld gives me these errors:
ld: warning: platform not specified
ld: warning: -arch not specified
ld: warning: No platform min-version specified on command line
ld: warning: ignoring file main.o, building for -unknown but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture unknown:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture unknown
I tried using nasm with macho64
nasm -f macho64 main.asm
and got the following errors from ld:
ld: warning: alignment (1) of atom '_start' is too small and may result in unaligned pointers
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
Thanks in advance

How do I compile my 16 bit Mac assembly code?

So I'm trying to assemble this piece of 16bit assembly code on my Mac (Monterey):
global _main
section .text
_main:
mov ah, 0x0e
mov al, '!'
int 0x10
mov ah, 0x4c
int 0x21
I am using the NASM assembler, and have so far managed to get it assembled into a .com file using the following command:
nasm testing.asm -o test.com -f bin
However when trying to link this into an executable using LD with the following command:
ld -e _main -static -o test test.com -arch x86_64
it comes up with the error:
standing-x86_64 but attempting to link with file built for
unknown-unsupported file format ( 0xB4 0x0E 0xB0 0x21 0xCD 0x10 0xB7
0x0E 0xB5 0x0E 0xB6 0x0E 0xBE 0x0E 0x00 0xBF ) Undefined symbols for
architecture x86_64: "_main", referenced from:
-u command line option ld: symbol(s) not found for architecture x86_64 ```
Does anyone know how to fix this?

How to run x86 .asm on macOS Sierra

I have problem with compilation .asm file on macOS can somebody help me?
Here is my repository:
https://github.com/ondrej-111/Asm.git
I tried to compile it with this commands:
nasm -f elf -d macho64 asm_io.asm
nasm -f elf prvy.asm
gcc -c driver.c
gcc -o prvy driver.o prvy.o asm_io.o
but I always get the same error:
ld: warning: ld: warning: ignoring file asm_io.o, file was built for
unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture
being linked (x86_64): asm_io.oignoring file prvy.o, file was built
for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the
architecture being linked (x86_64): prvy.o
Undefined symbols for architecture x86_64: "_asm_main", referenced
from:
_main in driver.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to
see invocation)
I searched some similar issues but any one helped me to fix it.( I tried this - How can I run this assembly code on OS X?)

Resources