0

I am compiling a Linux-based CMake C++ project under Windows 10 using GCC/G++ and VS2019 IDE.

I have installed sqlite3.dll, sqlite3.lib, and lsqlite3.so via the PATH environment variable.

enter image description here

Yet, I am getting the following error:

 [297/795] cmd.exe /C "cd . && C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -g -DDEBUG -pthread -O1 -std=c++11 -Wall    -g -DDEBUG -pthread -O1 -std=c++11 -Wall -lsqlite3 src/CMakeFiles/hist.dir/apps/MyLinuxBasedCppProject/hist.cc.obj -o ..\..\..\bin\hist.exe -Wl,--out-implib,..\bin\libhist.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ../bin/libMyLinuxBasedCppProject.a  -Wl,-Bstatic  -lz  -Wl,-Bdynamic  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  FAILED: ../../../bin/hist.exe 
  cmd.exe /C "cd . && C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -g -DDEBUG -pthread -O1 -std=c++11 -Wall    -g -DDEBUG -pthread -O1 -std=c++11 -Wall -lsqlite3 src/CMakeFiles/hist.dir/apps/MyLinuxBasedCppProject/hist.cc.obj -o ..\..\..\bin\hist.exe -Wl,--out-implib,..\bin\libhist.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ../bin/libMyLinuxBasedCppProject.a  -Wl,-Bstatic  -lz  -Wl,-Bdynamic  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsqlite3
C:\Users\pc\source\repos\MyLinuxBasedCppProject\out\build\Mingw64-Debug\collect2.exe : error : ld returned 1 exit status


  [298/795] cmd.exe /C "cd . && C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -g -DDEBUG -pthread -O1 -std=c++11 -Wall    -g -DDEBUG -pthread -O1 -std=c++11 -Wall -lsqlite3 src/CMakeFiles/seqc.dir/apps/MyLinuxBasedCppProject/seqc.cc.obj -o ..\..\..\bin\seqc.exe -Wl,--out-implib,..\bin\libseqc.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ../bin/libMyLinuxBasedCppProject.a  -Wl,-Bstatic  -lz  -Wl,-Bdynamic  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  FAILED: ../../../bin/seqc.exe 
  cmd.exe /C "cd . && C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -g -DDEBUG -pthread -O1 -std=c++11 -Wall    -g -DDEBUG -pthread -O1 -std=c++11 -Wall -lsqlite3 src/CMakeFiles/seqc.dir/apps/MyLinuxBasedCppProject/seqc.cc.obj -o ..\..\..\bin\seqc.exe -Wl,--out-implib,..\bin\libseqc.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ../bin/libMyLinuxBasedCppProject.a  -Wl,-Bstatic  -lz  -Wl,-Bdynamic  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  C:/PROGRA~1/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsqlite3
C:\Users\pc\source\repos\MyLinuxBasedCppProject\out\build\Mingw64-Debug\collect2.exe : error : ld returned 1 exit status

How can I resolve this?

EDIT

find_package(sqlite3)
if (SQLITE3_FOUND)
  message("Sqlite3 found")
  include_directories(${SQLite3_INCLUDE_DIRS})
  SET(CMAKE_CXX_FLAGS_RELEASE " -DSQLITE3 ${CMAKE_CXX_FLAGS_RELEASE}")
  SET(CMAKE_CXX_FLAGS_DEBUG " -DSQLITE3 ${CMAKE_CXX_FLAGS_DEBUG}")
  SET(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -LC:\\Users\\pc\\Downloads\\SQLite 64bit")
  SET(CMAKE_SHARED_LINKER_FLAGS "-lsqlite3 -LC:\\Users\\pc\\Downloads\\SQLite 64bit" )
else()
  message("Sqlite3 not found")
endif (SQLITE3_FOUND)
user366312
  • 16,949
  • 65
  • 235
  • 452
  • I guess that the appropriate `-L`... is missing which defines the file path where to look for libraries. If the library is in the same folder, I would try `-L.`. – Scheff's Cat Oct 30 '21 at 12:51
  • @Scheff'sCat, what is `-L` ? – user366312 Oct 30 '21 at 12:54
  • FYI: [SO: usr/bin/ld: cannot find -l](https://stackoverflow.com/a/16710346/7478597), [SO: cpp: usr/bin/ld: cannot find -l](https://stackoverflow.com/a/30601010/7478597) – Scheff's Cat Oct 30 '21 at 12:54
  • Sorry, this is a command line argument of g++. `-l` (lower case L) to specify a library, `-L` (upper case L) to specify a file path where to look for libraries. – Scheff's Cat Oct 30 '21 at 12:55
  • 2
    It's true that, very often, trying to cram Linux/Unix originated software, like gcc, into a foreign operating system that wasn't designed to run Linux/Unix-originated code, turns out to be a major, major time sink. Even experienced developers will struggle with this, not to mention those who are new to C++. Most of the time it takes much less time to simply install Linux from scratch, and get a fully working, fully configured, modern C++ compiler. It took me just an hour and a half, last time. Now, I'd just buy a Lenovo laptop with preloaded Linux. How much time did you already spend on this? – Sam Varshavchik Oct 30 '21 at 12:57
  • I just noticed on the second glance that you already mentioned CMake at the beginning of your question. In this case, the fix should be applied to the `CMakeLists.txt` probably. I agree with @Sam that this might be not that easy with MinGW which somehow tries to marry the tool chain common on Linux with the Windows world. Though, in general, CMake is a good choice if something is intended to be compiled on distinct platforms. At least, it works smooth on my side with VS in Windows, and g++ in a VM with Debian. But, for each side the usual native tools are applied which is easier to manage... – Scheff's Cat Oct 30 '21 at 13:09
  • 1
    If everything else fails, simply compiling `sqlite.c` as a part of your project should work. – HolyBlackCat Oct 30 '21 at 13:18
  • The `SET` commands are looking strange. (Where did you find these?) I'm used to: 1. use `find_package()` (as you did), 2. denote the resp. dependency in the `target_link_libraries()` for the project where the lib. should be used. As I have no experience with `sqlite3` I googled and found [SO: How can I link CMake and SQLite without an external script?](https://stackoverflow.com/a/41642102/7478597) and [FindSQLite3](https://cmake.org/cmake/help/latest/module/FindSQLite3.html) (where the target `SQLite3::SQLite3` is mentioned). – Scheff's Cat Oct 30 '21 at 13:18
  • Your `sqlite3.lib` link leads to a build instructions that use MSVC, not GCC. Mixing libraries/apps compiled with different compilers usually doesn't end well. You should rebuild it with GCC. – HolyBlackCat Oct 30 '21 at 13:19
  • Is there any specific reason to compile this with MinGW? Otherwise, you could have used the native tool chain of VS2019 as well, it might have been easier to manage. – Scheff's Cat Oct 30 '21 at 13:25
  • @Scheff'sCat, *Is there any specific reason to compile this with MinGW?* --- I tried Clang and VC++. They produced a lot more error messages. GCC seems to work with the least amount of error messages. – user366312 Oct 30 '21 at 13:32
  • @HolyBlackCat, good point!! Thanks. – user366312 Oct 30 '21 at 13:33
  • @Scheff'sCat *The SET commands are looking strange. (Where did you find these?)* --- from my university's Github repo. – user366312 Oct 30 '21 at 13:33
  • Googling a bit further (and concerning SQLite3 in the native tool chain of VS2019), I also found [SQLite Forum / Compiling amalgamation with Visual Studio 2019](https://sqlite.org/forum/info/720df5a7542ee960) – Scheff's Cat Oct 30 '21 at 13:41
  • Just out of curiosity... How did this end up? Did you get it running? – Scheff's Cat Oct 31 '21 at 06:29
  • 2
    @Scheff'sCat, https://github.com/alex85k/sqlite3-cmake --- I used this to compile lib file. then copied header files, lib files, and exe files to MinGW directory and that worked. – user366312 Oct 31 '21 at 06:57

0 Answers0