SQLite Forum

Creating Static Library using source code
Login

Creating Static Library using source code

(1) By Fresh_Pineapple (aSkyInSandDunes) on 2020-09-18 15:43:41 [link] [source]

I am trying to replace the dafault sqlite3 static library file in mingw with the latest version one.

I downloaded the source code from site (sqlite3.c, shell.c and sqlite.h)

I can use gcc to make a functional CLI program.

Then I created libsqlite3.a using

ar rcs libsqlite3.a object.o
where object.o is object file made using sqlite.c and shell.c
gcc shell.c sqlite.c -o object.o
When I use this new libsqlite3.a instead of older one, it spits out a lot of errors.

This is how I am compiling:

gcc my_c_code.c -o my_c_code -L. -lsqlite3

sqlite3.h, my_c_code.c and libsqlite3.a are in same dir

"my_c_code.c" contains #include "sqlite3.h" instead of #include <sqlite3.h>

I know I am doing something stupid but just can't find it out.

List of errors:

C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Dwarf Error: Could not find abbrev number 3926. ./libsqlite3.a(libsqlite3.o):crtexe.c:(.text+0x4b0): multiple definition of WinMainCRTStartup' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x4b0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.text+0x4e0): multiple definition ofmainCRTStartup' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x4e0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.text+0x510): multiple definition of atexit' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x510): first defined here ./libsqlite3.a(libsqlite3.o):cygming-crtbegin.c:(.text+0x530): multiple definition of__gcc_register_frame' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here ./libsqlite3.a(libsqlite3.o):cygming-crtbegin.c:(.text+0x540): multiple definition of __gcc_deregister_frame' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x10): first defined here ./libsqlite3.a(libsqlite3.o):shell.c:(.text+0xdd6de): multiple definition ofmain' C:UsersPistonAppDataLocalTempccwb2PiZ.o:sq.c:(.text+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d00): multiple definition of .refptr.__native_startup_state' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_state[.refptr.__native_startup_state]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16de0): multiple definition of.refptr.mingw_initltsdyn_force' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdyn_force[.refptr.mingw_initltsdyn_force]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16cb0): multiple definition of .refptr.__imp___initenv' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__imp___initenv[.refptr.__imp___initenv]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d80): multiple definition of.refptr._matherr' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._matherr[.refptr._matherr]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16df0): multiple definition of .refptr.mingw_initltssuo_force' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltssuo_force[.refptr.mingw_initltssuo_force]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d50): multiple definition of.refptr._dowildcard' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._dowildcard[.refptr._dowildcard]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16dc0): multiple definition of .refptr.mingw_initcharmax' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initcharmax[.refptr.mingw_initcharmax]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16ce0): multiple definition of.refptr.__mingw_oldexcpt_handler' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_oldexcpt_handler[.refptr.__mingw_oldexcpt_handler]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d30): multiple definition of .refptr.__xi_a' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_a[.refptr.__xi_a]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d90): multiple definition of.refptr._newmode' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._newmode[.refptr._newmode]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.CRT+0x8): multiple definition of mingw_pcppinit' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XCAA+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16dd0): multiple definition of.refptr.mingw_initltsdrot_force' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdrot_force[.refptr.mingw_initltsdrot_force]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16cf0): multiple definition of .refptr.__native_startup_lock' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_lock[.refptr.__native_startup_lock]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16c90): multiple definition of.refptr.__dyn_tls_init_callback' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__dyn_tls_init_callback[.refptr.__dyn_tls_init_callback]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.data+0x0): multiple definition of __mingw_winmain_nShowCmd' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.data+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.CRT+0x20): multiple definition ofmingw_pcinit' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XIAA+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d70): multiple definition of .refptr._gnu_exception_handler' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._gnu_exception_handler[.refptr._gnu_exception_handler]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16db0): multiple definition of.refptr.mingw_app_type' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_app_type[.refptr.mingw_app_type]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16ca0): multiple definition of .refptr.__image_base__' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__image_base__[.refptr.__image_base__]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d60): multiple definition of.refptr._fmode' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._fmode[.refptr._fmode]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d10): multiple definition of .refptr.__xc_a' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_a[.refptr.__xc_a]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d40): multiple definition of.refptr.__xi_z' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_z[.refptr.__xi_z]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16c50): multiple definition of .refptr._MINGW_INSTALL_DEBUG_MATHERR' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._MINGW_INSTALL_DEBUG_MATHERR[.refptr._MINGW_INSTALL_DEBUG_MATHERR]+0x0): first defined here ./libsqlite3.a(libsqlite3.o):crtexe.c:(.rdata+0x16d20): multiple definition of.refptr.__xc_z' C:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_z[.refptr.__xc_z]+0x0): first defined here collect2.exe: error: ld returned 1 exit status

(2) By Richard Hipp (drh) on 2020-09-18 15:47:59 in reply to 1 [link] [source]

ar rcs libsqlite3.a object.o
where object.o is object file made using sqlite.c and shell.c

I think you need to create the library using just sqlite3.c. The shell.c source file is for a standalone program and should be omitted from the library.

(3) By Fresh_Pineapple (aSkyInSandDunes) on 2020-09-18 16:51:32 in reply to 2 [source]

Hey, thanks for the suggestion but it, unfortunately, didn't work. A suggestion by Discord User rrs#6408 did actually solved the issue. I just needed to add -c while creating my two object file from sqlite3.h and shell.c and then it worked like a charm :)

gcc -c sqlite.c shell.c