简体   繁体   中英

How to compile a dynamic library?

I've been searching the web for a couple of days and can't seem to find clear instructions on how to do this.

SQLite doesn't have math functions like, sine, cosine, etc.. I found a library that extends SQLite and adds these functions, but I can't figure out how to compile the library.

http://lhealy.livejournal.com/6306.html

I've tried just about everything (except the solution). I downloaded the SQLite source, configured and used make, then tried to build the dynamic library with the following command within the extension's source directory

gcc -fPIC func_ext.c -shared -o libsqlitefunctions.so -Isqlite3 -Isqlite3/src

I have the sqlite3 source within this directory so the -I flags should be pointing to the correct directory. This is the error that I get.

func_ext.c:91: error: static declaration of ‘acosh’ follows non-static declaration
func_ext.c:99: error: static declaration of ‘asinh’ follows non-static declaration
func_ext.c:107: error: static declaration of ‘atanh’ follows non-static declaration
func_ext.c:403: error: conflicting types for ‘isblank’
/usr/include/ctype.h:242: error: previous definition of ‘isblank’ was here
func_ext.c: In function ‘properFunc’:
func_ext.c:422: warning: pointer targets in passing argument 1 of ‘sqlite3StrDup’ differ in signedness
func_ext.c:422: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘padlFunc’:
func_ext.c:463: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘padrFunc’:
func_ext.c:509: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘padcFunc’:
func_ext.c:556: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘strfilterFunc’:
func_ext.c:607: warning: pointer targets in assignment differ in signedness
func_ext.c:608: warning: pointer targets in assignment differ in signedness
func_ext.c:616: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c:618: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c: In function ‘_substr’:
func_ext.c:654: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c:659: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c:664: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c:665: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c: In function ‘charindexFunc’:
func_ext.c:716: warning: pointer targets in passing argument 1 of ‘_substr’ differ in signedness
func_ext.c:716: warning: pointer targets in passing argument 2 of ‘_substr’ differ in signedness
func_ext.c: In function ‘rightFunc’:
func_ext.c:775: warning: pointer targets in assignment differ in signedness
func_ext.c:779: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c: In function ‘ltrimFunc’:
func_ext.c:833: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘rtrimFunc’:
func_ext.c:851: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘trimFunc’:
func_ext.c:872: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘replaceFunc’:
func_ext.c:914: warning: pointer targets in assignment differ in signedness
func_ext.c:915: warning: pointer targets in assignment differ in signedness
func_ext.c:916: warning: pointer targets in assignment differ in signedness
func_ext.c: In function ‘reverseFunc’:
func_ext.c:975: warning: pointer targets in assignment differ in signedness
func_ext.c:982: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c: In function ‘differenceFunc’:
func_ext.c:1336: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness
func_ext.c:1336: warning: pointer targets in passing argument 1 of ‘sqlite3ReadUtf8’ differ in signedness

Thank you! Sandro

Consider using g++ instead of gcc which automaticaly sets the correct settings when compiling c++. For instance, with the following code:

int f(int x)
{

}

int f(int x, int y)
{

}

int main(int argc, char* argv[])
{

}

... gives the error:

test.c:7: error: conflicting types for ‘f’
test.c:2: error: previous definition of ‘f’ was here

Where as with g++, it's fine. It could be that the code genuinely is attempting to be c and is defining overloads which would be illegal and a bigger problem, but I'd give this a shot first.

These are compiler errors not linker errors.
You need to get your program to compile (in a normal way) before you can think of building it as a shared library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM