Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compiling properly - help! #144

Closed
hintron opened this issue Oct 3, 2017 · 6 comments
Closed

Not compiling properly - help! #144

hintron opened this issue Oct 3, 2017 · 6 comments
Assignees

Comments

@hintron
Copy link

hintron commented Oct 3, 2017

Hello,

I can't seem to get sqlitecpp to work with my setup. Did I miss something obvious in my usage of sqlitecpp?

My usage:

My makefile downloads sqlitecpp, creates a build directory, cd's into it, runs cmake .., runs make, and then copies the built sqlitecpp lib file and source header files to a local directory called sqlitecpp in my project. I then use those local files in my code like so:

#include "SQLiteCpp/SQLiteCpp.h"
#include "sqlite3.h"

And I build my program like so:

g++ -g Main.cpp SQLConnector.cpp -std=c++11 -I sqlitecpp -lsqlite3 -L sqlitecpp -lSQLiteCpp -o bin/Server

but I get the following errors:

In file included from sqlitecpp/SQLiteCpp/SQLiteCpp.h:23:0,
                 from SQLConnector.cpp:7:
sqlitecpp/SQLiteCpp/Database.h:22:16: error: using typedef-name ‘sqlite3_value’ after ‘struct’
 typedef struct sqlite3_value sqlite3_value;
                ^
In file included from SQLConnector.h:13:0,
                 from SQLConnector.cpp:6:
include_local/sqlite3.h:3327:20: note: ‘sqlite3_value’ has a previous declaration here
 typedef struct Mem sqlite3_value;
                    ^
In file included from sqlitecpp/SQLiteCpp/SQLiteCpp.h:23:0,
                 from SQLConnector.cpp:7:
sqlitecpp/SQLiteCpp/Database.h:22:43: error: invalid type in declaration before ‘;’ token
 typedef struct sqlite3_value sqlite3_value;
                                           ^
sqlitecpp/SQLiteCpp/Database.h:22:43: error: conflicting declaration ‘typedef int sqlite3_value’
In file included from SQLConnector.h:13:0,
                 from SQLConnector.cpp:6:
include_local/sqlite3.h:3327:20: error: ‘sqlite3_value’ has a previous declaration as ‘typedef struct Mem sqlite3_value’
 typedef struct Mem sqlite3_value;
                    ^

To me, it looks like there is some kind of contention with sqlite and sqlitecpp. Any ideas? I am using sqlitecpp 2.2.0 and sqlite3 v. 3.8.7.1. Any help is appreciated. Thanks!

I think this may have something to do with SQLITE_USE_LEGACY_STRUCT (see #131)

@SRombauts
Copy link
Owner

SRombauts commented Oct 4, 2017

Exactly, you are right, you have to set this flag to ON to use an older SQLite3 library. Something like:

cd build 
cmake -DSQLITE_USE_LEGACY_STRUCT=ON -DSQLITECPP_INTERNAL_SQLITE=OFF - DCMAKE_BUILD_TYPE=Release ..
make

@SRombauts
Copy link
Owner

This is a duplicate of the issue #125 Incompatibility in 3.19. 0 and #133

@hintron
Copy link
Author

hintron commented Oct 4, 2017

Ok, here is how I am building it now:

cmake -DSQLITE_USE_LEGACY_STRUCT=ON -DSQLITECPP_INTERNAL_SQLITE=OFF ..

(By default, the SQLITECPP_INTERNAL_SQLITE cmake var is ON, which makes it try to build off the internal sqlite version that comes with sqlitecpp instead of sqlitelib-dev in Ubuntu)

However, I still got the same errors, so I added -DSQLITE_USE_LEGACY_STRUCT to my call to g++, and that solved the header errors. (It seems that the DSQLITE_USE_LEGACY_STRUCT is defined in cmake, but not when I compile it. In the flags.make file, I can see CXX_DEFINES = -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_USE_LEGACY_STRUCT).

But now I get these linking errors:
g++ -g Main.cpp SQLConnector.cpp -std=c++11 -I sqlitecpp -ldl -lpthread -lsqlite3 -L sqlitecpp -lSQLiteCpp -o bin/Server -DSQLITE_USE_LEGACY_STRUCT

sqlitecpp/libSQLiteCpp.a(Database.cpp.o): In function `SQLite::getLibVersion()':
Database.cpp:(.text+0x5): undefined reference to `sqlite3_libversion'
sqlitecpp/libSQLiteCpp.a(Database.cpp.o): In function `SQLite::getLibVersionNumber()':
Database.cpp:(.text+0x10): undefined reference to `sqlite3_libversion_number'
sqlitecpp/libSQLiteCpp.a(Database.cpp.o): In function `SQLite::Database::Database(char const*, int, int, char const*)':
Database.cpp:(.text+0x91): undefined reference to `sqlite3_open_v2'
Database.cpp:(.text+0xc2): undefined reference to `sqlite3_close'
sqlitecpp/libSQLiteCpp.a(Database.cpp.o): In function `SQLite::Database::Database(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
Database.cpp:(.text+0x210): undefined reference to `sqlite3_open_v2'
Database.cpp:(.text+0x241): undefined reference to `sqlite3_close'
sqlitecpp/libSQLiteCpp.a(Database.cpp.o): In function `SQLite::Database::~Database()':
Database.cpp:(.text+0x2fc): undefined reference to `sqlite3_close'
sqlitecpp/libSQLiteCpp.a(Database.cpp.o): In function `SQLite::Database::setBusyTimeout(int)':
Database.cpp:(.text+0x37f): undefined reference to `sqlite3_busy_timeout'
...

Any ideas on what is going on? I know that the library is getting found, but the compiler just doesn't seem to link it properly. Could it have something to do with the order of my libraries?

@hintron
Copy link
Author

hintron commented Oct 4, 2017

Fixed the issue! I needed to put -lSQLiteCpp as the left-most library. Dependent libraries need to go first. (see https://stackoverflow.com/a/409402)

This is what it looks like now:
g++ -g Main.cpp SQLConnector.cpp -std=c++11 -I sqlitecpp -L sqlitecpp -lSQLiteCpp -ldl -lpthread -lsqlite3 -o bin/Server -DSQLITE_USE_LEGACY_STRUCT

Right now I'm specifying -DSQLITE_USE_LEGACY_STRUCT in both the cmake call and my g++ call. Is there any way to avoid specifying it in g++? Or is that just the way it has to be?

@SRombauts
Copy link
Owner

SRombauts commented Oct 5, 2017

Thanks for the update!

For the second point (in relation to #145 CMake flags not passed in), I should find a way to improve that! I am reopening the issue to track this.

@SRombauts SRombauts reopened this Oct 5, 2017
@SRombauts
Copy link
Owner

Well, I am closing after closer review, this since there is nothing I can do here: you need to use CMake all the way to define the variable only on CMake and everything works as expected.

Your problem is you are not using CMake so you need to define every vars by yourself on your command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants