0

I'm quite new to C++ and its ecosystem, still learning. Recently I'm trying to learn how to install a library and use it in my project.

I'm following the tutorial in the following link: https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/

I'm ok with the basic usage of vcpkg and follow the tutorial install the sqlite3 library.

And also learned the basis stuff of cmake. As the tutorial goes: The best way to use installed libraries with cmake is via the toolchain file. So I prepared the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)

set(CMAKE_TOOLCHAIN_FILE "C:/Develop/test/cpp/test-vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")

project(test)

set(sqlite3_DIR "C:/Develop/test/cpp/test-vcpkg/vcpkg/installed/x64-windows/share/sqlite3")

find_package(sqlite3 CONFIG REQUIRED)

add_executable(main main.cpp)

target_link_libraries(main sqlite3)

my CMakeLists.txt is a little different from the one in the tutorial, I set the sqlite3_DIR which is not mentioned in the tutorial (if I didn't add it, the build process will fail.)

And the source file is quite simple as following:

#include <sqlite3.h>
#include <stdio.h>

int main()
{
    printf("%s\n", sqlite3_libversion());
    return 0;
}

And I run the build command as the tutorial shows:

cmake .. 

cmake --build .

these two command run through without errors.

I try to open the .sln file generated in the cmake .. process with visual studio, and try to build it, got the following error:

The application was unable to start correctly(0xc000007b)

If I try to the executable file of main.exe which I get during the cmake --build . process. I will get the same error message window.

Any help or ideas?

Chris Bao
  • 2,418
  • 8
  • 35
  • 62
  • After running main.exe, could you run "echo %errorlevel%"? This would show us if the command is executed successfully or has failed. – Erik Nellessen Aug 27 '19 at 13:58
  • the output of `errorlevel` is: -1073741701 – Chris Bao Aug 27 '19 at 22:45
  • Ok, I converted the error code from visual studio (0xc000007b) to binary and interpreted it as a two's complement. It lead to the same value. So visual studio and the console start lead to the same error code. The console start just does not tell you about it. So it looks like the sqlite3 library has not been linked correctly. If I understand your code correctly, the idea is to link the sqlite3 library statically and include it in the .exe, right? Or did you want to link dynamically by providing a DLL somewhere in the file system? – Erik Nellessen Aug 28 '19 at 08:17
  • 1
    I found another difference between your code and the tutorial. Your code says find_package(sqlite3 CONFIG REQUIRED), while the tutorial says find_package(Sqlite3 REQUIRED). You might want to try without the CONFIG keyword. – Erik Nellessen Aug 28 '19 at 08:24
  • One possible explanation could be that the idea is to link the program dynamically against a DLL downloaded by vcpkg. If the DLL cannot be found during runtime, this explains the error. Your need to set sqlite3_DIR explicitly would fit into this explanation. Did you run ".\vcpkg integrate install" as stated in the tutorial? – Erik Nellessen Aug 28 '19 at 08:28
  • first, if I follow the tutorial use `find_package(Sqlite3 REQUIRED)`, then cmake will give this message during the building process: `Found SQLite3: C:/Develop/test/cpp/test-vcpkg/vcpkg/installed/x86-windows/include (found version "3.29.0")`. And then `cmake --build .` process will fail with error: `Cannot open include file: 'sqlite3.h': No such file or d irectory [C:\Develop\test\cpp\test-sqlite3\build\main.vcxproj] `. My platform is x64. If I follow the tutorial, it can't run through. – Chris Bao Aug 28 '19 at 08:38
  • Is the sqlite3.h file present in the directory C:/Develop/test/cpp/test-vcpkg/vcpkg/installed/x86-windows/include? If not, can you look for the file and post the location? The "cmake .." command should generate a Makefile. You can also have a look at the Makefile and look for include directories. These include directories should point to the directory where the sqlite3.h file is. – Erik Nellessen Aug 28 '19 at 10:52

0 Answers0