首页 > 解决方案 > 我该如何解决:找不到-lsqlite3?

问题描述

我正在使用 GCC/G++ 和 VS2019 IDE 在 Windows 10 下编译基于 Linux 的 CMake C++ 项目。

我已经通过 PATH 环境变量安装了sqlite3.dllsqlite3.lib和。lsqlite3.so

在此处输入图像描述

然而,我收到以下错误:

 [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

我该如何解决这个问题?

编辑

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)

标签: c++visual-studiosqlitegcccmake

解决方案


推荐阅读