On Tue, Jun 28, 2011 at 11:07:50 +0000, Black, Michael (IS) wrote:
> I'd recommend NOT relying on the system sqlite3.  That way you can control 
> your changes.

Let me express very, very strong disagreement with that. In Linux you should
*always* use system sqlite and specify minimal required version as desired.

That saves space (only one system-wide shared library with the code), memory
(one shared library is only loaded once) and allows upgrading the library
without having to recompile the application, which means when important fix
is made in sqlite, you don't have to recompile all the applications and saves
precious time of your friendly distribution package maintainer.

> Get the amalgamation and put sqlite3.c and sqlite3.h in your project.

That should only be done if you either need to modify it or if you are
building for platform without decent package manager.

> On Monday, June 27, 2011 11:45 PM, Phong Cao [phn...@gmail.com] wrote:
> > I am trying to use g++ to compile my C++ application, which uses sqlite3.
> > After googling for several hours this is what I tried:
> > 
> > g++ -g /home/phongcao/main.cc -o -lsqlite3 /home/phongcao/main `pkg-config
                                     ^ as already pointed out, -o needs an
                                       argument
> > --cflags --libs gtkmm-2.4`

(no, since sqlite is a shared library and pkg-config already lists all
necessary dependencies, you shouldn't need any extra libraries).

> > However, the program was not compiled.

Without also seeing the error message it produced, I can't really help you
(beyond the missing argument to -o, which might well be the main problem
though).

> > I also read on some forums saying that sqlite3 must be compiled with gcc.

You are not compiling sqlite3.

> > But since I am using gtkmm and C++ code for my project I wonder if there
> > is anyway possible to compile sqlite3 using g++? If so, please tell me
> > how.

Compilation of C and/or C++ program has two stages, compiling (from single .c
or .cc to .o) and linking (from bundch of .o to binary or .so). The gcc and
g++ are just wrappers that control both and just launch appropriate programs
for the stages (cpp, cc1 and as for compilation and ld for linking).

The only difference between gcc and g++ is the set of options they pass to
the lower level tools, the gcc being tuned to plain old C and g++ being tuned
to C++, which is superset of those for C.

Since you normally always compile one file at a time, you can compile the .c
sources with gcc and the .cc (or .cpp) sources with g++. If you produced some
of the objects with g++, you should also use g++ to control linking to get
appropraite default libraries (but you can use gcc or ld directly and pass
the necessary options manually).

Ok, what you are doing above is combining both steps in one g++ invocation.
Both gcc and g++ can do it, g++ can accept mixture of .c and .cc files in
this case. It's however not recommended for projects with more than one
source, because the compilation step takes quite long, especially for C++, so
there is a lot of time to be saved by recompiling only those sources that
changed and than linking it all together (using make to find out what needs
to be done).


As I said above, you are not compiling sqlite. It is already provided by the
system and you are only linking it and mixture of C and C++ objects is
correctly linked by g++.

If you decided to use the amalgamation (which I personally don't recommend
for Linux, but you may need it on some other system), you'd compile the
sqlite3.c to sqlite3.o with gcc and than list the sqlite3.o along with all
your other objects for the link. You don't want to list sqlite3.c there,
because you would be compiling each time you change your project when you
actually wont change sqlite3.c at least until next sqlite release.

-- 
                                                 Jan 'Bulb' Hudec <b...@ucw.cz>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to