我尝试在Visual Studio 2022中制作一个跨平台的imgui项目,从Android开始,一开始我无法正确地包含一些Android库,所以在学习了几个教程之后,我最终得到了这个CMakeLists.txt:
# CMakeList.txt : CMake project for CMakeProject3 (imgui Cross-platform), include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project ("CMakeProject3 (imgui Cross-platform)")
list(APPEND CMAKE_PREFIX_PATH "C:/Users/HP/source/repos/CMakeProject3 (imgui Cross-platform)/build/vcpkg_installed/x64-windows/share/")
find_package(imgui REQUIRED)
# Add source to this project's executable.
add_executable (CMakeTarget "CMakeProject3 (imgui Cross-platform).cpp" "CMakeProject3 (imgui Cross-platform).h" "imgui_android.cpp" "imgui_impl_android.cpp" "imgui_impl_android.h")
target_include_directories(CMakeTarget PRIVATE "C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/android/"
"C:/Microsoft/AndroidNDK/android-ndk-r23c/sources/android/native_app_glue/")
target_link_libraries(CMakeTarget
PRIVATE
imgui::imgui
)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET CMakeTarget PROPERTY CXX_STANDARD 20)
endif()
# TODO: Add tests and install targets if needed.
它部分工作,但根据Android imgui的例子,它需要
#include <android/log.h>
#include <android_native_app_glue.h>
#include <android/asset_manager.h>
我改为:
#include "log.h"
#include "android_native_app_glue.h"
#include "asset_manager.h"
它开始给予无法打开源文件的几个错误。错误是poll.h,pthread.h,sched.h,android/configuration.h等。在我看来,我需要完全包含android ndk,但
include(AndroidNdkGdb)
include(AndroidNdkModules)
即使我安装了安卓ndk和sdk,在cmake中也会出现错误。
我希望能够在我的visual studio 2022跨平台项目中使用android库。
1条答案
按热度按时间erhoui1w1#
我通过将CMakeLists.txt更新为以下内容修复了错误: