Use SQLite to solve the undefined reference to 'sqlite3 _ open' Error

Source: Internet
Author: User

Suppose you have compiled and installed SQLite correctly, and write a test.ProgramTo test:
# Include <stdlib. h>
# Include <stdio. h>
# Include "sqlite3.h"

Int main (void)
{
Sqlite3 * DB = NULL;
Char * zerrmsg = 0;
Int RC;
Rc = sqlite3_open ("test1.db", & dB );
If (RC)
{
Fprintf (stderr, "can't open database: % s \ n", sqlite3_errmsg (db ));
Sqlite3_close (db );
Exit (1 );
}
Else printf ("Open mydata successfully! \ N ");
Sqlite3_close (db );
Return 0;
}

Errors always occur when compiling with GCC. The compilation command is as follows:
Gcc-static-O hello-lsqlite3-L/usr/local/lib-I/usr/local/include hello. c
The error message is as follows:
/Tmp/cckekpx9.o (. Text + 0x37): In function 'main ':
: Undefined reference to 'sqlite3 _ open'
/Tmp/cckekpx9.o (. Text + 0x51): In function 'main ':
: Undefined reference to 'sqlite3 _ errmsg'
/Tmp/cckekpx9.o (. Text + 0x73): In function 'main ':
: Undefined reference to 'sqlite3 _ close'
/Tmp/cckekpx9.o (. Text + 0x9b): In function 'main ':
: Undefined reference to 'sqlite3 _ close'
Collect2: LD returned 1 exit status

Congratulations. The error is not in SQLite or your program, but in GCC. GCC compilation parameters are sequential. The correct compilation command is:
Gcc-O hello-L/usr/local/lib-I/usr/local/include-static hello. C-lsqlite3

To be honest, such a small problem has plagued me for a day! Really ~~~~~~


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.