SQLite Forum

Compile for Apple Silicon
Login
> Undefined symbols for architecture arm64:

Because you're trying to compile the amalgamation as a standalone executable, which it is not. It's intended to be built as an object file or a library. Though i don't know exactly what the conventions are on your OS, that generally looks something like:

> clang -arch arm64 -arch x86_64 -c -o sqlite3.o  sqlite3.c 

The -c flag tells it to compile but not link. The -o flag tells it the output file name. You end up with an object file (the whole sqlite3 library) which you can then link together with your application's other object files.

If you're trying to build the shell, you'll have further steps to take, but someone familiar with the oddities of your platform will need to suggest what they are.

On my OS that looks something like:

```
[stephan@nuc:~/Downloads/sqlite-amalgamation-3370000]$ ls -la
total 9516
drwxrwxr-x 2 stephan stephan    4096 Nov 27 16:05 .
drwxr-xr-x 8 stephan stephan   12288 Dec  1 03:40 ..
-rw-rw-r-- 1 stephan stephan  704219 Nov 27 16:05 shell.c
-rw-rw-r-- 1 stephan stephan 8385624 Nov 27 16:05 sqlite3.c
-rw-rw-r-- 1 stephan stephan   35995 Nov 27 16:05 sqlite3ext.h
-rw-rw-r-- 1 stephan stephan  595850 Nov 27 16:05 sqlite3.h

[stephan@nuc:~/Downloads/sqlite-amalgamation-3370000]$ clang -c sqlite3.c
[stephan@nuc:~/Downloads/sqlite-amalgamation-3370000]$ clang -c shell.c
[stephan@nuc:~/Downloads/sqlite-amalgamation-3370000]$ clang -o sqlite3 sqlite3.o shell.o

/usr/bin/ld: sqlite3.o: in function `unixDlOpen':
sqlite3.c:(.text+0x662a): undefined reference to `dlopen'
/usr/bin/ld: sqlite3.o: in function `unixDlError':
sqlite3.c:(.text+0x6659): undefined reference to `dlerror'
/usr/bin/ld: sqlite3.o: in function `unixDlSym':
sqlite3.c:(.text+0x66aa): undefined reference to `dlsym'
/usr/bin/ld: sqlite3.o: in function `unixDlClose':
sqlite3.c:(.text+0x66f5): undefined reference to `dlclose'
/usr/bin/ld: sqlite3.o: in function `pthreadMutexAlloc':
sqlite3.c:(.text+0x1ba8d): undefined reference to `pthread_mutexattr_init'
/usr/bin/ld: sqlite3.c:(.text+0x1ba9e): undefined reference to `pthread_mutexattr_settype'
/usr/bin/ld: sqlite3.c:(.text+0x1baba): undefined reference to `pthread_mutexattr_destroy'
/usr/bin/ld: sqlite3.o: in function `pthreadMutexTry':
sqlite3.c:(.text+0x1bb81): undefined reference to `pthread_mutex_trylock'
/usr/bin/ld: sqlite3.o: in function `sqlite3ThreadJoin':
sqlite3.c:(.text+0x37a0c): undefined reference to `pthread_join'
/usr/bin/ld: sqlite3.o: in function `sqlite3ThreadCreate':
sqlite3.c:(.text+0x5859f): undefined reference to `pthread_create'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(Oooops - we need to link in some external dependencies)

[stephan@nuc:~/Downloads/sqlite-amalgamation-3370000]$ clang -o sqlite3 sqlite3.o shell.o -ldl -lpthread

[stephan@nuc:~/Downloads/sqlite-amalgamation-3370000]$ ./sqlite3 
SQLite version 3.37.0 2021-11-27 14:13:22
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> ^D
```

On your OS it will be something very close to that, if not identical.