SQLiteCpp: unresolved external symbol error

vcpkg package management program version 2023-06-15-8c254a5fb6c503615834fc66bd0717664a339a2e Microsoft Visual Studio Community 2022 (64-bit) - CurrentVersion 17.6.4 msvc console project sqlitecpp 3.3.0

When I install the library using vcpkg and run the test code in VisualStudio, I get the following unresolved external symbol error.

********.obj error LNK2001: The external symbol "int const SQLite::OPEN_READONLY" (?OPEN_READONLY@SQLite@@@3HB) is unresolved
********.exe : fatal error LNK1120: 1 unresolved external reference

How can I resolve this?

If only the sqlite3 library is used from vcpkg, there is no error.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I think #434 fixes this as we need SQLITECPP_COMPILE_DLL defined for all users of the library. add_definitions doesn’t do this in cmake, it just defines it for SQLiteCpp and nothing else.

Defining this means that users of the library get #define SQLITECPP_API __declspec(dllimport), which is correct as dllexport should only be used when building the library itself:

https://stackoverflow.com/questions/57999/what-is-the-difference-between-dllexport-and-dllimport

I have tested this on our code (we use vcpkg with dynamic libs) and it seems to fix the linker errors.

@ninjaoflight I figure out that it works for me if I use an old vcpkg commit. So, for now it’s fine, if I have more problems I will open an issue or report it to vcpkg as suggested. Thank you for the answer!

I think #434 fixes this as we need SQLITECPP_COMPILE_DLL defined for all users of the library. add_definitions doesn’t do this in cmake, it just defines it for SQLiteCpp and nothing else.

Defining this means that users of the library get #define SQLITECPP_API __declspec(dllimport), which is correct as dllexport should only be used when building the library itself:

https://stackoverflow.com/questions/57999/what-is-the-difference-between-dllexport-and-dllimport

I have tested this on our code (we use vcpkg with dynamic libs) and it seems to fix the linker errors.

good insight, I know this change works with cmake+vcpkg works, however I do not know if it works under vsbuild+vcpkg, I think the patch would need an additional command but I am not sure

edit: I also think that is a good Idea to use target_compile_definitions which is more clean in modern cmake