I’m stuck with installing tinyxml2 to using vcpkg and link it using CMake
The following steps were taken
- Install vcpkg
- Run
vcpkg add port tinyxml2
- Run
vcpkg
to install tinyxml2 - Run
vcpkg integrate install
For CMake I have the following 2 files
CMakeLists.txt
project(HelloWorld)
set(CMAKE_TOOLCHAIN_FILE "./vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
find_package(tinyxml2 CONFIG REQUIRED)
add_executable(HelloWorld main.cpp)
target_link_libraries(HelloWorld PRIVATE tinyxml2::tinyxml2)
CMakePresets.json
{
"version": 2,
"configurePresets": [
{
"name": "default",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "./vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
Now I’m running cmake --preset=default
and afterwards cmake --build build
This results in the following error
[1/1] Linking CXX executable HelloWorld.exe
FAILED: HelloWorld.exe
C:WINDOWSsystem32cmd.exe /C "cd . && C:msys64ucrt64binc++.exe CMakeFiles/HelloWorld.dir/main.cpp.obj
-o HelloWorld.exe -Wl,--out-implib,libHelloWorld.dll.a -Wl,--major-image-version,0,--minor-image-version,0 vcpkg_installed/x64-windows/debug/lib/tinyxml2.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && C:WINDOWSsystem32cmd.exe /C "cd /D C:Users<user>devcppplaygroundbuild && C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -noprofile -executionpolicy Bypass -file
C:/Users/<user>/dev/cpp/playground/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/<user>/dev/cpp/playground/build/HelloWorld.exe -installedDir C:/Users/<user>/dev/cpp/playground/build/vcpkg_installed/x64-windows/bin -OutVariable out""
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/HelloWorld.dir/main.cpp.obj:main.cpp:(.text+0x2b): undefined reference to `__imp__ZN8tinyxml211XMLDocumentC1EbNS_10WhitespaceE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/HelloWorld.dir/main.cpp.obj:main.cpp:(.text+0x54): undefined reference to `__imp__ZN8tinyxml211XMLDocumentD1Ev'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/HelloWorld.dir/main.cpp.obj:main.cpp:(.text+0x6e): undefined reference to `__imp__ZN8tinyxml211XMLDocumentD1Ev'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
My main.cpp file
#include <iostream>
#include <tinyxml2.h>
using namespace tinyxml2;
int main() {
XMLDocument doc;
std::cout << "Hello";
}
Where did I go wrong when trying to add tinyxml2 via vcpkg?
I even see the header file in vcpkginstalledx64-windowsincludetinyxml2.h
Thanks for any tips