Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop2] Cross debugging with Visual Studio 2022 and WSL2 #683

Open
steinerthomas opened this issue Feb 10, 2025 · 0 comments
Open

[develop2] Cross debugging with Visual Studio 2022 and WSL2 #683

steinerthomas opened this issue Feb 10, 2025 · 0 comments

Comments

@steinerthomas
Copy link

steinerthomas commented Feb 10, 2025

Finally (and due to conan1-freeze 😉) I had time to migrate from conan1 to conan2.
I'm using a Visual Studio 2022 CMake project with WSL2 (and/or devcontainers). You can find a demo migration project here: https://github.com/steinerthomas/vs-cmake-conan-wsl-template

Debugging/Running the program/tests "native" in WSL2 with the default profile (or in the devcontainers) works well (see example preset wsl-debug).

Unfortunately I can't cross-compile (or cross-debug on remote machines) to other architectures (see example preset remote-debug-showcase) with cmake-conan, because the conan generated presets are not used and so for example linking fails:
https://github.com/steinerthomas/vs-cmake-conan-wsl-template/pull/3/files

See Visual Studio build logs
Starting copying files to remote machine.
Copying 'C:\vs-cmake-conan-wsl-template\conanfile.py' to '/home/thomas/.vs/vs-cmake-conan-wsl-template/conanfile.py'.
Finished copying files (elapsed time 00h:00m:00s:163ms).
 cd /home/thomas/.vs/vs-cmake-conan-wsl-template//out/build/remote-debug-showcase;export CMAKE_BUILD_PARALLEL_LEVEL=8;export REMOTE_DEBUG_MACHINE=192.168.110.10;/usr/bin/cmake --build /home/thomas/.vs/vs-cmake-conan-wsl-template//out/build/remote-debug-showcase --config Debug;

[ 25%] Building CXX object CMakeFiles/MyLib.dir/src/MyLib.cpp.o
[ 50%] Linking CXX static library libMyLib.a
[ 50%] Built target MyLib
[ 75%] Linking CXX executable MyLib_ut
/usr/bin/ld: /home/thomas/.conan2/p/b/libxm740122de5cf93/p/lib/libxml2.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
gmake[2]: *** [tests/CMakeFiles/MyLib_ut.dir/build.make:102: tests/MyLib_ut] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:882: tests/CMakeFiles/MyLib_ut.dir/all] Error 2
gmake: *** [Makefile:101: all] Error 2


Build All failed.

Due to the described problem I can't use cmake-conan conan_provider.cmake because I already have CMakePresets.json in my projects and I can't include the conan generated once.

As also described here https://docs.conan.io/2.12/integrations/visual_studio.html#conan-extension-for-visual-studio:
For CMake-based projects, please refer to the https://github.com/conan-io/cmake-conan.


As a workaround I've created my own conan cmake install wrapper, which basically calls conan install before cmake "CMAKE_PROJECT_INCLUDE_BEFORE": "$env{HOME}/.conan2/extensions/cmake/conan_install.cmake" and set the conan generated toolchain "toolchainFile": "${sourceDir}/out/build/${presetName}/build/Debug/generators/conan_toolchain.cmake":

conan_install.cmake:

set(CONAN_HOST_PROFILE "default" CACHE STRING "conan host profile")
set(CONAN_BUILD_PROFILE "default" CACHE STRING "conan build profile")

message (STATUS "conan install ${CMAKE_SOURCE_DIR} -u -pr:h ${CONAN_HOST_PROFILE} -pr:b ${CONAN_BUILD_PROFILE} -s build_type=${CMAKE_BUILD_TYPE} -of ${CMAKE_BINARY_DIR} ${CONAN_INSTALL_ARGS}")
execute_process(
	COMMAND conan install ${CMAKE_SOURCE_DIR} -u -pr:h ${CONAN_HOST_PROFILE} -pr:b ${CONAN_BUILD_PROFILE} -s build_type=${CMAKE_BUILD_TYPE} -of ${CMAKE_BINARY_DIR} ${CONAN_INSTALL_ARGS}
	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
	RESULT_VARIABLE CONAN_INSTALL_RESULT
)

I know I could also invoke conan install manually, but especially in devcontainers it would be annoying switching beteween muliple target architectures ...


I know there are existing issues: #569, #544
But I think the problem there was the cyclic cache generation which is not a problem anymore with WSL2 (see #544 (comment)).


I hope I could describe my problem in detail.
Maybe I missed something and you can help me out, or probably you have a better idea how to use cmake-conan with existing CMakePresets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant