I am not able to embedd the sqlite3 amalgamation in a simple cmake hello world executable.
In a nutshell: test.h
and test.cpp
are just working, so why are sqlite.h
and sqlite.c
not?
Also, using qmake
(Qt's build system) it simply works, and I think the described steps are 100% the same.
main.cpp.obj:-1: error: LNK2019: unresolved external symbol sqlite3_open referenced in function main
Project dir
CMakeLists.txt
main.cpp
sqlite/
|- sqlite3.c
|- sqlite3.h
test/
|- test.c
|- test.h
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(sqlite_test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sqlite ${CMAKE_CURRENT_SOURCE_DIR}/test)
add_executable(sqlite_test main.cpp sqlite/sqlite3.h sqlite/sqlite3.c test/test.h test/test.cpp)
qmake .pro file for comparison which just works
TEMPLATE = app
TARGET = sqlite_qmake
INCLUDEPATH += $$PWD/sqlite $$PWD/test
HEADERS += \
$$PWD/sqlite/sqlite3.h \
$$PWD/test/test.h
SOURCES += \
main.cpp \
$$PWD/sqlite/sqlite3.c \
$$PWD/test/test.cpp
test.h
#ifndef TEST_H
#define TEST_H
void sayhello();
#endif // TEST_H
test.cpp
#include "test.h"
#include <iostream>
void sayhello(){
std::cout << "Hello Universe!" << std::endl;
}
main.cpp
#include <iostream>
#include "sqlite3.h"
#include "test.h"
int main()
{
cout << "Hello World!" << endl;
sayhello();
sqlite3 *db = nullptr;
int rc = sqlite3_open("index.db", &db);
if (rc != SQLITE_OK){
return -1;
}
return 0;
}
That's because you have to explicitly say what languages you're going to work with. Just add C
in the LANGUAGES
list in the project
command:
project(sqlite_test LANGUAGES CXX C)