Compiling amalgamation with gcc
(1) By curmudgeon on 2021-01-18 10:05:44 [link]
I'm using ubuntu 20.04 via windows 10 wsl. When I try to compile sqlite3.c in bash I get these errors. tom@sp4:~/sqlite$ ls temp shell.c sqlite3.c sqlite3.h sqlite3ext.h tom@sp4:~/sqlite$ cd temp tom@sp4:~/sqlite/temp$ gcc -I ~/sqlite sqlite3.c -o sqlite.o /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x24): undefined reference to `main' /usr/bin/ld: /tmp/ccVahWO8.o: in function `pthreadMutexAlloc': sqlite3.c:(.text+0x45bf): undefined reference to `pthread_mutexattr_init' /usr/bin/ld: sqlite3.c:(.text+0x45d0): undefined reference to `pthread_mutexattr_settype' /usr/bin/ld: sqlite3.c:(.text+0x45ef): undefined reference to `pthread_mutexattr_destroy' /usr/bin/ld: /tmp/ccVahWO8.o: in function `pthreadMutexTry': sqlite3.c:(.text+0x46c4): undefined reference to `pthread_mutex_trylock' /usr/bin/ld: /tmp/ccVahWO8.o: in function `sqlite3ThreadCreate': sqlite3.c:(.text+0x954b): undefined reference to `pthread_create' /usr/bin/ld: /tmp/ccVahWO8.o: in function `sqlite3ThreadJoin': sqlite3.c:(.text+0x95e1): undefined reference to `pthread_join' /usr/bin/ld: /tmp/ccVahWO8.o: in function `unixDlOpen': sqlite3.c:(.text+0x124d1): undefined reference to `dlopen' /usr/bin/ld: /tmp/ccVahWO8.o: in function `unixDlError': sqlite3.c:(.text+0x124f4): undefined reference to `dlerror' /usr/bin/ld: /tmp/ccVahWO8.o: in function `unixDlSym': sqlite3.c:(.text+0x12547): undefined reference to `dlsym' /usr/bin/ld: /tmp/ccVahWO8.o: in function `unixDlClose': sqlite3.c:(.text+0x12581): undefined reference to `dlclose' collect2: error: ld returned 1 exit status tom@sp4:~/sqlite/temp$ Can anyone tell me why?
(2) By anonymous on 2021-01-18 11:05:52 in reply to 1 [link]
gcc -I ~/sqlite sqlite3.c -o sqlite.o gcc tried to make an executable file. If you want an object file you have to pass a -c option to stop gcc rigth after assembling the object file. gcc -c -I ~/sqlite sqlite3.c -o sqlite.o
(3) By curmudgeon on 2021-01-18 13:17:21 in reply to 2 [link]
Thank you anon. I had the wrong pwd in any case. My code should have read gcc -I ~/sqlite/temp sqlite3.c -o sqlite.o and gcc -c -I ~/sqlite/temp sqlite3.c -o sqlite.o works fine.
(4) By curmudgeon on 2021-01-18 14:09:52 in reply to 1 [link]
Similar to above why does gcc -I ~/sqlite sqlite3.c shell.c -o sqlite3 produce errors. Does shell.c have other dependencies apart from sqlite3.c? tom@sp4:~/sqlite$ ls LICENSE.md art config.sub fts5.h lemon manifest.uuid parse.h sqlite.pc.in sqlite3ext.h Makefile autoconf configure fts5parse.c lempar.c mkkeywordhash parse.out sqlite3.1 sqlite3session.h Makefile.in compat configure.ac fts5parse.h libsqlite3.la mkso.sh parse.sql sqlite3.c src Makefile.linux-gcc config.guess contrib fts5parse.out libtool mksourceid parse.y sqlite3.h test Makefile.msc config.h doc fts5parse.sql ltmain.sh mptest shell.c sqlite3.lo tool README.md config.h.in ext fts5parse.y magic.txt opcodes.c spec.template sqlite3.o tsrc VERSION config.log fossil install-sh main.mk opcodes.h sqlite.fossil sqlite3.pc vsixtest aclocal.m4 config.status fts5.c keywordhash.h manifest parse.c sqlite.o sqlite3.pc.in tom@sp4:~/sqlite$ gcc -I ~/sqlite sqlite3.c shell.c -o sqlite3 /usr/bin/ld: /tmp/ccYlh56d.o: in function `pthreadMutexAlloc': sqlite3.c:(.text+0x45c4): undefined reference to `pthread_mutexattr_init' /usr/bin/ld: sqlite3.c:(.text+0x45d5): undefined reference to `pthread_mutexattr_settype' /usr/bin/ld: sqlite3.c:(.text+0x45f4): undefined reference to `pthread_mutexattr_destroy' /usr/bin/ld: /tmp/ccYlh56d.o: in function `pthreadMutexTry': sqlite3.c:(.text+0x46c9): undefined reference to `pthread_mutex_trylock' /usr/bin/ld: /tmp/ccYlh56d.o: in function `sqlite3ThreadCreate': sqlite3.c:(.text+0x9556): undefined reference to `pthread_create' /usr/bin/ld: /tmp/ccYlh56d.o: in function `sqlite3ThreadJoin': sqlite3.c:(.text+0x95ec): undefined reference to `pthread_join' /usr/bin/ld: /tmp/ccYlh56d.o: in function `unixDlOpen': sqlite3.c:(.text+0x1251d): undefined reference to `dlopen' /usr/bin/ld: /tmp/ccYlh56d.o: in function `unixDlError': sqlite3.c:(.text+0x12540): undefined reference to `dlerror' /usr/bin/ld: /tmp/ccYlh56d.o: in function `unixDlSym': sqlite3.c:(.text+0x12593): undefined reference to `dlsym' /usr/bin/ld: /tmp/ccYlh56d.o: in function `unixDlClose': sqlite3.c:(.text+0x125cd): undefined reference to `dlclose' collect2: error: ld returned 1 exit status tom@sp4:~/sqlite$
(5) By Keith Medcalf (kmedcalf) on 2021-01-18 14:50:11 in reply to 4 [link]
Because you need link the pthread and dl libaries.
(6) By anonymous on 2021-01-18 15:01:38 in reply to 4 [link]
gcc -I ~/sqlite sqlite3.c shell.c -o sqlite3 -ldl -pthread
(7) By curmudgeon on 2021-01-18 15:56:51 in reply to 6
Thanks Keith and anon.