Captain Pugsy
Captain Pugsy

Reputation: 11

Sqlite3 build through a vala cmake system

I've been trying to compile a vala application through a cmake build system, but have been running into problems when trying to link the sqlite3 package. When running make I get

CMakeFiles/app.dir/Database/Database.c.o: In function `template_database_construct_from_file':
Database.c:(.text+0x8a): undefined reference to `sqlite3_open'
Database.c:(.text+0xaa): undefined reference to `sqlite3_close'
Database.c:(.text+0x116): undefined reference to `sqlite3_errcode'
Database.c:(.text+0x131): undefined reference to `sqlite3_errmsg'

As well as a bunch of almost identical errors. I can test the code by compiling it through the command line using --pkg sqlite3 and it has compiled without any problems. So why is it not working properly when trying to compile from cmake?

Any help is greatly appreciated. Thank you!

Upvotes: 1

Views: 505

Answers (2)

Felipe Lavratti
Felipe Lavratti

Reputation: 2967

I'd need to see your CMakeLists.txt to better understand your problem.

Still, to link a library to a CMake vala build, do this:

find_package(PkgConfig)
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
set(CFLAGS
    ${SQLITE3_CFLAGS} ${SQLITE3_CFLAGS_OTHER}
    ... )
add_definitions(${CFLAGS})

set(LIBS
    ${SQLITE3_LIBRARIES}
    ... )    
link_libraries(${LIBS})

set(LIB_PATHS
    ${SQLITE3_LIBRARY_DIRS}
    ... )
link_directories(${LIB_PATHS})

("..." stands for the rest of your dependencies)

More complete example is here: https://github.com/felipe-lavratti/vala-cmake-example

Upvotes: 1

Top Sekret
Top Sekret

Reputation: 758

You need to add results of pkg-config --libs sqlite3 to your LDFLAGS or something. Although I don't use CMake, I think this is a problem of your template. I experienced the same problems using Autotools.

Upvotes: 1

Related Questions