[SOLVED] CLion, C++, and SQLite3
Completed
I'm using CLion 2020.3.2 to build a small C++\SQLite3 app. The Compiling is executed by adding the command -l sqlite3 .
Where do I add that command line in CLion?
Please sign in to leave a comment.
You need to add the library to your CMake project. Honestly, the easiest way of including third-party libraries into your CMake project is to use "Conan" - a package manager that generates the CMake files you need for any third party library. Read more about it (and install it) here: https://docs.conan.io/en/latest/installation.html . Just bear in mind that you will need Python 3 and Pip installed.
Here's an example of your project structure. Suppose the root directory of your project is called "my_project". Then in the root of your project, you would a file called "conanfile.txt" with the contents:
Now say you are creating an executable called "my_program", and you have a "main.cpp" file with the code you want to compile, including a few headers from the directory "include/my_program". Then "main.cpp" would look like something like this:
Then your CMakeLists.txt should look like this:
Given that Conan was installed in your machine, you can now tell Conan to "pull" the dependencies into your project. Normally, I would create a "modules" directory and install the Conan dependencies in there:
The stuff above will generate a bunch of "Find****.cmake" files, which tell CMake how to include those dependencies in your project. The final step is just configuring CMake, while telling it where those "find files" are. The command you would type into your terminal/command-line would be the following:
Now, if you are here, you are probably using CLion. So you need to tell CLion about this "-DCMAKE_MODULES_PATH" option. To do this, go to "File -> Settings -> Build, Execution, Deployment -> CMake". In the "CMake Options" field, you need to add "-DCMAKE_MODULE_PATH:FILEPATH=**FULL_PATH_TO_YOUR_BUILD_DIRECTORY**". See my example:

Note that the full path to my build directory was "/home/matheus/coding/my_project/modules" and it must be the same directory where you run the "conan install" command, as that's where the find files will be. After all this, you should be able to use the SQLite3 headers and IntelliSense should work just fine! Let me know if it worked for you.
I fixed it with one line, by adding
`
`
to my CMakeLists.txt
https://stackoverflow.com/questions/41268589/c-c-undefined-reference-for-sqlite3s-functions-using-clion-with-cmake
Indeed, you linked your system's SQLite with CMake. But the issue is if I tried to compile your program on my machine, not only will it not work as I don't have SQLite3, but what happens if the person compiling has a different version of SQLite and links against it? That's why you should use a package manager, it solves all these problems for you.
Plus, whatever third-party library you want to add to your project should be available on the Conan repository. Two extra lines (one in your "conanfile.txt" and one in your "CMakeLists.txt" will be enough to add any extra library). No system installation required, conan will manage it for you.
fmc just as a general advice as well: less lines of code != better solutions!
Matheusgarcia28 - Thank you for your clear instructions on how to complete the process you mentioned. I haven't tried it yet, but I will later today. Very, very good information you gave. Thank you.