Results 1 to 2 of 2

Thread: Cannot compile sqlite

  1. #1
    Join Date
    Jul 2025
    Posts
    1
    Platforms
    Windows

    Default Cannot compile sqlite

    Hi everyone,

    I'm new to QtCreator.
    I have a small C++ project that adds chess tournaments/games/players in a SQLite database (for statistics), and I want to develop a UI for it.

    But I have an issue and I dont find a way to resolve it
    I'm getting linker errors like:

    Qt Code:
    1. ${CMAKE_SOURCE_DIR}\file.cpp:34: error: undefined reference to `sqlite3_step'
    To copy to clipboard, switch view to plain text mode 
    This happens for every file that uses SQLite functions.

    I have #include <sqlite3.h> in my code (I also tried #include "sqlite3.h") and everything works well when I compile with g++ g++ -std=c++17 -Wall -Wextra -g -o exe time.o timecontrol.o player.o tournament.o game.o main.o db.o tool.o -lsqlite3 and use ./exe in the shell.


    All the SQLite sources (sqlite3.c, sqlite3.h, sqlite3ext.h) are into an external/sqlite3 directory, and the qcreator projet is in chessdb directory.
    .
    My CMakeLists.txt adds ../external/sqlite3/sqlite3.c to the sources for the executable, like this:
    Qt Code:
    1. if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    2. qt_add_executable(chessdb
    3. MANUAL_FINALIZATION
    4. ${PROJECT_SOURCES}
    5. ../external/sqlite3/sqlite3.c
    6. ../db.cpp ../game.cpp ../player.cpp ../Time.cpp ../TimeControl.cpp ../tool.cpp ../Tournament.cpp
    7. )
    To copy to clipboard, switch view to plain text mode 

    And I include the external directory like that :
    Qt Code:
    1. target_include_directories(chessdb PRIVATE
    2. ${CMAKE_CURRENT_SOURCE_DIR}/../external/sqlite3
    3. )
    4.  
    5. target_link_libraries(chessdb PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
    To copy to clipboard, switch view to plain text mode 



    The file sqlite3.c appears in the source tree in QtCreator, but during build, there is no step compiling sqlite3.c (sqlite3.c.obj is never created).


    What could I be missing in the CMakeLists.txt ?

    Thanks for your answers
    Last edited by d_stranz; 7th July 2025 at 16:55. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Cannot compile sqlite

    I guess you don't know that SQLite is built into Qt as a standard SQL module, so you do not need to compile it separately. Try removing the source and header file references from your CMakeLists.txt and follow the instructions here.

    You'll probably have to change your code to interface to the Qt SQL implementation, but that is pretty straightforward if you follow the programming model. Here is a good basic example.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 14
    Last Post: 1st January 2016, 03:03
  2. [Qt][SQLite] Two problems with SQLite.
    By Xandareva in forum Newbie
    Replies: 6
    Last Post: 6th April 2010, 23:06
  3. Cannot load SQLITE driver on clean target
    By ForestDweller in forum Installation and Deployment
    Replies: 1
    Last Post: 15th December 2008, 00:49
  4. cannot compile the MainWindow example with vs2005
    By billconan in forum Qt Programming
    Replies: 5
    Last Post: 31st May 2008, 18:27
  5. Newbie:cannot compile - moc'ing error
    By publicENEMY in forum Installation and Deployment
    Replies: 2
    Last Post: 1st June 2006, 07:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.