Author Topic: Sqlite installation into Code::Blocks  (Read 44807 times)

geijt

  • Guest
Sqlite installation into Code::Blocks
« on: June 10, 2005, 07:54:42 pm »
Does anyone know how to get SQLite 3.x working in Code::Blocks?

Everytime i try to use SQLite 3.x i receive the following error
Code

.objs\main.o(.text+0x12e7):main.cpp: undefined reference to `sqlite3_open'
.objs\main.o(.text+0x12fb):main.cpp: undefined reference to `sqlite3_errmsg'
.objs\main.o(.text+0x1322):main.cpp: undefined reference to `sqlite3_close'
.objs\main.o(.text+0x135d):main.cpp: undefined reference to `sqlite3_get_table'
.objs\main.o(.text+0x1527):main.cpp: undefined reference to `sqlite3_free_table'
.objs\main.o(.text+0x1532):main.cpp: undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Sqlite installation into Code::Blocks
« Reply #1 on: June 10, 2005, 08:04:17 pm »
I didn't know codeblocks was programmed to use SQLite... don't you mean a program of yours that uses sqlite?

Anyway did you link the libraries correctly? there should be a sqlite.a or something... (not sure what's it named tho).

geijt

  • Guest
Sqlite installation into Code::Blocks
« Reply #2 on: June 10, 2005, 08:23:04 pm »
I mean a program i'm working on..

When i specify libsqlite3.a or libsqlite3 in the 'link libraries' with the path to that file in the 'linker directory' i receive the following error:

Code

collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)


When i delete the path in 'linker directory' i see the following error:

Code

C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lsqlite3
collect2: ld returned 1 exit status

Guillaume

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #3 on: May 23, 2006, 10:19:15 pm »
Hello,

I'm using this topic because I have exactly the same problem.

I would like to use SQLite library in a C::B project

Here is my source code :
Code: cpp
#include <iostream>
#include "sqlite3.h"

typedef struct sqlite3 sqlite3;
sqlite3 *db;

using namespace std;
int main()
{
    int opening = sqlite3_open("tolkien_world.db", &db);
if (opening == 0) {
        cout << "Base ouverte avec succès" << endl;
} else {
cout << "Echec de l'ouverture de la base" << endl;
}
return 0;
}

I have linked "tclsqlite3.dll" in my project (Build options > Linker options), but I have the same error message :
"ld.exe cannot find ltclsqlite3.dll"

If anyone can help me... I don't know what to do to solve this problem

Thank you ;)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5494
Re: Sqlite installation into Code::Blocks
« Reply #4 on: May 23, 2006, 10:24:24 pm »
you need to link with the import library not the dll itself

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Sqlite installation into Code::Blocks
« Reply #5 on: May 23, 2006, 10:25:02 pm »
I have linked "tclsqlite3.dll" in my project (Build options > Linker options), but I have the same error message : "ld.exe cannot find ltclsqlite3.dll"
You cannot link a DLL. "DLL" stands for dynamic link library so they are loaded at run-time. What you want is a static library which you have to build first. So I guess you need to build SQLlite first. What do yopu have from SQLlite? If it's only the DLL than it's not enough anyway for development...?!
With regards, Morten.
BTW: Did you notice that this thread is over a year old?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Sqlite installation into Code::Blocks
« Reply #6 on: May 23, 2006, 10:25:43 pm »
you need to link with the import library not the dll itself
...half a minute faster that I... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

takeshimiya

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #7 on: May 23, 2006, 10:32:37 pm »
I have linked "tclsqlite3.dll" in my project (Build options > Linker options), but I have the same error message : "ld.exe cannot find ltclsqlite3.dll"
You cannot link a DLL. "DLL" stands for dynamic link library so they are loaded at run-time. What you want is a static library which you have to build first. So I guess you need to build SQLlite first. What do yopu have from SQLlite? If it's only the DLL than it's not enough anyway for development...?!

Just something: MingW's linker (ld) can link directly to a .dll that was built by it (just like on linux with gcc(ld)). This way of linking is faster too. So you'll not need any .lib.
See here for a real world example in C::B.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Sqlite installation into Code::Blocks
« Reply #8 on: May 23, 2006, 10:35:09 pm »
You can link with DLLs (for many cases MinGW can do it), but that'sn't the idea (Takeshi was faster).

About your problem: you need to link with libsqlite3.a (just add sqlite3 to the link libraries). Be sure you have the library in the first place and it can be found through the linker directories (it's also in the build options).

If you cannot find that library in the package you downloaded, read more carefully in the SQLite site which one has it, download it and try again.

Guillaume

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #9 on: May 23, 2006, 10:58:08 pm »
Wow !
Thank you for these quick answers

I'm going to try your suggestions
I didn't found some files with .a or .lib, I have downloaded a lot of packages from sqlite.org, but I will search again

BTW: Did you notice that this thread is over a year old?
Yes, I have seen the date, and the message above the answer form, but it was the same problem than me and it was not resolved... so I have supposed that it was the good place...
It's at least a proof that I have used the search tool of this forum ;)

And please excuse my poor english, I'm a French user

Thank you for your help

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Sqlite installation into Code::Blocks
« Reply #10 on: May 23, 2006, 11:12:30 pm »
I didn't found some files with .a or .lib, I have downloaded a lot of packages from sqlite.org, but I will search again
...this: http://www.hwaci.com/sw/sqlite/mingw.html may help.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Sqlite installation into Code::Blocks
« Reply #11 on: May 23, 2006, 11:36:50 pm »
Nice to see you used the search tool :)

Sorry but I was wrong: there's no package with library, but you can do as follows:

1. Download sqlitedll-3_3_5.zip from here.
2. Decompress it in some folder.
3. Open a console and go to that folder.
4. Run this command: dlltool --def sqlite3.def --dllname sqlite3.dll --output-lib libsqlite3.a.
5. Download sqlite-source-3_3_5.zip from here.
6. Decompress it somewhere.
7. Take sqlite3.h from it and place it somewhere.
8. Add to your project the directory where to find the header and where to find the library.
9. Try again.
10. Remember to have the dll in a path pointed by the environment variable PATH or just at one side of your executable.

If you want the static library, you'd have to compile it yourself (I'd use MSYS for it).

I hope I didn't miss anything.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Sqlite installation into Code::Blocks
« Reply #12 on: May 23, 2006, 11:52:35 pm »
Even better:

1. Download the file in step 5.
2. Decompress it somewhere.
3. Copy the attached project (decompress it first) to that folder.
4. Open the project file (with Code::Blocks of course).
5. Click on Build and you'll get libsqlite3.a (static library).

If you don't care too much, just move libsqlite3.a to C:\MinGW\lib (if C:\MinGW is where you have MinGW installed) and sqlite3.h to C:\MinGW\include, or just do as the steps 7 and 8 suggest.

[attachment deleted by admin]

takeshimiya

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #13 on: May 24, 2006, 08:47:33 am »
<- Yes, building sqlite as a static library is better, because it's so tiny that it's not worth a shared library.

Guillaume

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #14 on: June 01, 2006, 10:23:12 am »
I have followed your instructions Ceniza, and my program run !

I have made all steps before posting here, except this :
4. Run this command: dlltool --def sqlite3.def --dllname sqlite3.dll --output-lib libsqlite3.a.
So with the libsqlite3.a, it's better ;)

I will look for documentation on how to compile a static library on the web, because I'm a very newbie in C++ and I don't know nothing about this.

Thank you again for your help, everybody  :)