I did everything according to the vcpkg documentation from the website:https://learn.microsoft.com/en-us/vcpkg/get_started/get-started-vscode?pivots=shell-cmdAdded to the VCPKG_ROOT environment variable with the value C:\Users\takuya\vcpkg , and also added to the path C:\Users\takuya\vcpkg , I did all this after installing vcpkg (cloaking the repository, launching the batch file). After installation, I downloaded the libpqxx library (pkg install libpqxx), and additionally prescribed vcpkg integrate install. All the necessary extensions are installed in vs code, too.The json files are created in vcpkg.json says {"dependencies": ["libpqxx"]}The problem is, cmake builds the build calmly and I can run it, but gcc swears at pqxx/pqxx: There is no such file or directory gcc.
I tried to configure c_cpp_properties.json
{"configurations": [ {"name": "Win32","includePath": ["${workspaceFolder}/**","C:\\Users\\takuya\\vcpkg\\installed\\x64-windows\\include" ],"defines": ["_DEBUG","UNICODE","_UNICODE" ],"windowsSdkVersion": "10.0.22621.0","compilerPath": "C:\\msys64\\ucrt64\\bin\\g++.exe","cStandard": "c17","cppStandard": "c++20" } ],"version": 4}
no matter how hard I tried to specify the path to include, gcc swears anyway.
main.cpp file code:
#include <iostream>#include <pqxx/pqxx> // fatal error: pqxx/pqxx: No such file or directory using namespace std;using namespace pqxx;int main(){ try { connection conn("host=localhost port=5432 dbname=testdb user=postgres password=564789s"); if (conn.is_open()) { cout << "Connected to database successfully!" << endl; } else { cerr << "Failed to connect to database." << endl; } } catch (const exception &e) { cerr << "Error: " << e.what() << endl; return 1; } return 0;}
CMakeLists.txt
make_minimum_required(VERSION 3.10)project(MyProject) set(CMAKE_CXX_STANDARD 20)set(CMAKE_CXX_STANDARD_REQUIRED ON)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" CACHE STRING "")find_package(libpqxx CONFIG REQUIRED)add_executable(main main.cpp) target_link_libraries(main PRIVATE libpqxx::pqxx)
Error:
C:\Users\takuya\Desktop\test\build>C:\msys64\ucrt64\bin\g++.exe -DPQXX_SHARED @CMakeFiles/main.dir/includes_CXX.rsp -g -std=c++20 -o CMakeFiles\main.dir\main.cpp.obj -c C:\Users\takuya\Desktop\test\main.cppC:\Users\takuya\Desktop\test\main.cpp:2:10: fatal error: pqxx/pqxx: No such file or directory 2 | #include <pqxx/pqxx> | ^~~~~~~~~~~compilation terminated.