Author Topic: Sqlite installation into Code::Blocks  (Read 44748 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: 5491
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  :)

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Sqlite installation into Code::Blocks
« Reply #15 on: June 01, 2006, 02:27:40 pm »
Guillaume: Just download the attached project of my previous post (SQLite3.zip), follow the 5 steps there and you'll get the static version of the library built with Code::Blocks :)

DaveK

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #16 on: August 02, 2006, 08:27:51 pm »
Why on Earth this is giving me grief is beyond me. i'm having the same issue of getting sqlite3 installed on CodeBlocks.

Everything goes well until it starts to link. Here is the result from the Build Log
Code
mingw32-g++.exe -LD:\CodeBlocks\wx263\lib\gcc_dll -LC:\MinGW\lib  -o bin\Release\ROSIn.exe obj\Release\newcharacterwizardmain.o obj\Release\main.o   -s  -lwxmsw26u -lgdi32 D:\CodeBlocks\sqlite3\libsqlite3.a D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a  -mwindows

here is the resulting issues
Code
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0xa5):SqliteDatabaseLayer.cpp: undefined reference to `wxCSConv::wxCSConv(wchar_t const*)'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0xd3):SqliteDatabaseLayer.cpp: undefined reference to `wxCSConv::~wxCSConv()'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x10d):SqliteDatabaseLayer.cpp: undefined reference to `wxCSConv::~wxCSConv()'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x1e5):SqliteDatabaseLayer.cpp: undefined reference to `wxCSConv::wxCSConv(wchar_t const*)'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x213):SqliteDatabaseLayer.cpp: undefined reference to `wxCSConv::~wxCSConv()'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x24d):SqliteDatabaseLayer.cpp: undefined reference to `wxCSConv::~wxCSConv()'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x31a):SqliteDatabaseLayer.cpp: undefined reference to `sqlite3_open'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x35a):SqliteDatabaseLayer.cpp: undefined reference to `sqlite3_errcode'
D:\CodeBlocks\wx263\databaselayer\databaselayer\lib\libdatabaselayer_sqlite.a(databaselayer_sqlite_lib_SqliteDatabaseLayer.o)(.text+0x37f):SqliteDatabaseLayer.cpp: undefined reference to `sqlite3_errmsg'
and so on....

I followed the steps above, and I have a static library for sqlite and even for sqlitedatabaselayer. The dll for sqlite3 is located in the same directory as my executable. The .h file and .a files are copied into the MinGW directories. The static libraries are linked and I have even added some directory information to the build options.
Code
Directories/Compiler: D:\CodeBlocks\wx263\include, D:\CodeBlocks\wx263\lib\gcc_dll\mswu, D:\CodeBlocks\wx263\contrib\include,
D:\CodeBlocks\wx263\databaselayer\databaselayer\include,
D:\CodeBlocks\sqlite3\src,
D:\CodeBlocks\wx263\databaselayer\databaselayer\src
Directories/Linker: D:\CodeBlocks\wx263\lib\gcc_dll

Does anyone know what i could be missing? Obviously sqlitedatabaselayer.cpp is calling objects that I thought should be a part of libdatabaselayer_sqlite.a library. Any ideas?

Thanks!

DeanCB

  • Guest
Re: Sqlite installation into Code::Blocks
« Reply #17 on: December 19, 2013, 12:28:39 am »
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]

Good day, thank you for explaining this. I have the same problem as the OP and encountered this thread through Google.


Alas, your solution is not working for me. Step 3 onwards doesnt make sense. What do you mean copy project to that folder?

I have downloaded the source files and am trying to make a library out of it and I cant make an ".a" file.

« Last Edit: December 19, 2013, 12:30:38 am by DeanCB »

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: Sqlite installation into Code::Blocks
« Reply #18 on: December 21, 2013, 10:25:24 am »
Ah! Zombie thread rising from the dead! Quick, someone kill it with fire!

lol

Seriously though, this thread is from 2005... Anything advice in it is likely useless by now.

But If your using wxWidgets you shouldn't be trying to use SQLite3 directly anyway. There is a wxWidgets addon called wxSQLite3 that is a wrapper for the SQLite3 library and will make things far easier. You can find it here:

http://wxcode.sourceforge.net/components/wxsqlite3/
« Last Edit: December 21, 2013, 10:50:27 am by ouch »