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
- Define SQLITECPP_COMPILE_DLL as PUBLIC * So that users of the SQLiteCpp lib have it defined automatically * Fixed #432 — committed to calumr/SQLiteCpp by calumr 3 years ago
I think #434 fixes this as we need SQLITECPP_COMPILE_DLL defined for all users of the library.
add_definitionsdoesn’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 asdllexportshould 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!
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_definitionswhich is more clean in modern cmake