No_43Sub-string divisibility

本文探讨了如何在0到9的全排列数字中寻找那些具备特定子串除性质的数字,并计算其总和。通过改进算法,将时间复杂度从原来的6秒降低至0.005秒,展示了优化方法的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.

Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:

  • d2d3d4=406 is divisible by 2
  • d3d4d5=063 is divisible by 3
  • d4d5d6=635 is divisible by 5
  • d5d6d7=357 is divisible by 7
  • d6d7d8=572 is divisible by 11
  • d7d8d9=728 is divisible by 13
  • d8d9d10=289 is divisible by 17

Find the sum of all 0 to 9 pandigital numbers with this property.

代码为:
__author__ = 'Administrator'
import itertools,math,time
t=time.time()


soucestr='0123456789'
re_list=[]
totalsum=0
divlist=[2,3,5,7,11,13,17]
matched=0
for numstrlist in itertools.permutations(soucestr):
    numstr=''.join(numstrlist)
    matched=0
    for indexnum in xrange(7,0,-1):
        if not int(numstr[indexnum:indexnum+3])%divlist[indexnum-1]:
            matched+=1
        else:
            break
    if matched==7:
        totalsum+=int(numstr)
        #re_list.append(numstr)
"""
for numstr,templist in re_list:
    print numstr,templist
"""
#print sum([int(numstr) for numstr in re_list])
print time.time()-t
运行结果为:
16695334890
6.16100001335

不过运行结果太慢了,要6 秒钟。太长了。真的。
自己花了差不多一个小时改了下:

这种方法的思路是。把0-1000里能被2,3,5,7,11,14,17整除的数都列出来,然后组合出最终结果。
代码为:

import time
#coding=utf-8
starttime = time.time()
def getlist(sourcestr,numdict,index,divlist,outlist):
    if index==-1:
        print sourcestr
        if len(sourcestr)==9:
            outlist.append(sourcestr)
    else:
        notmatchedset=numdict[divlist[index]]
        if sourcestr:
            notmatchedset={numstr  for numstr in notmatchedset if numstr[0] not in sourcestr and  numstr[-2:]==sourcestr[0:2] }
        if not notmatchedset:
            return
        for numstr in notmatchedset:
            if index==len(divlist)-1:#如果第一次迭代
                getlist(numstr+sourcestr,numdict,index-1,divlist,outlist)

            else:
                getlist(numstr[0]+sourcestr,numdict,index-1,divlist,outlist)

divlist=[2,3,5,7,11,13,17]
soucedict=dict()
for num in divlist:
    soucedict.setdefault(num,set())
for num in range(0,1000):
    numstr='{0:03d}'.format(num)
    if len(str(numstr))>len(set(str(numstr))):
        continue
    else:
        for divnum in divlist:
            if not num%divnum:
                soucedict[divnum].add(numstr)
count=0
outlist=[]
getlist("",soucedict,len(divlist)-1,divlist,outlist)
print sum([int(item) for item in outlist])
print time.time()-starttime
#print '{0:02d}'.format(0)
运行结果为:
406357289
106357289
160357289
460357289
130952867
430952867
1695334890

0.00500011444092

生活就是一个不断发现自己是一个SB的过程。。。。。哭

这个题目就是一个迭代啊。很简单的东西啊我居然想了这么久。。。
牛人的代码为:

import time
#coding=utf-8
starttime = time.time()
def checkStrNum(str1):
    '''str1: string of length 3 or greater'''
    return not(str1[0] in str1[1:]) and str1[1] != str1[2]

pandigital = [];
for num in range(1,1000):
    if num % 17 == 0:
        strnum = str(num)
        if len(strnum) == 2:
            strnum = '0' + strnum
        if checkStrNum(strnum):
            pandigital.append(strnum)

divisors = [13,11,7,5,3,2,1]

for div in divisors:
    auxpandigital = []
    for addNum in range(0,10):
        for numPan in pandigital:
            newPan = str(addNum) + numPan
            if checkStrNum(newPan) and int(newPan[0:3]) % div == 0:
                auxpandigital.append(newPan)
    pandigital = auxpandigital

total = 0
for finalPan in pandigital:
    total += int(finalPan)

print(total)
print time.time()-starttime
#print '{0:02d}'.format(0)
16695334890
0.000999927520752

-- ROMFS: Adding boards/px4/fmu-v5/extras/px4_io-v2_default.bin -> /etc/extras/px4_io-v2_default.bin -- Configuring done -- Generating done -- Build files have been written to: /home/me/下载/px4-autopilot-1.15.4/build/px4_fmu-v5_default [1/1299] Generating git version header FAILED: src/lib/version/build_git_version.h cd /home/me/下载/px4-autopilot-1.15.4 && /usr/bin/python3 /home/me/下载/px4-autopilot-1.15.4/src/lib/version/px_update_git_header.py /home/me/下载/px4-autopilot-1.15.4/build/px4_fmu-v5_default/src/lib/version/build_git_version.h --validate Error: the git tag 'c49f4c2142' does not match the expected format. The expected format is 'v<PX4 version>[-<custom version>]' <PX4 version>: v<major>.<minor>.<patch>[-rc<rc>|-beta<beta>|-alpha<alpha>|-dev] <custom version>: <major>.<minor>.<patch>[-rc<rc>|-beta<beta>|-alpha<alpha>|-dev] Examples: v1.9.0-rc3 (preferred) v1.9.0-beta1 v1.9.0-1.0.0 v1.9.0-1.0.0-alpha2 See also https://docs.px4.io/main/en/dev_setup/building_px4.html#building-for-nuttx [2/1299] Generating ../../../platforms/nuttx/NuttX/nuttx/.config ninja: build stopped: subcommand failed. make: *** [Makefile:227:px4_fmu-v5_default] 错误 1如何修改代码避免此错误############################################################################ # # Copyright (c) 2017 - 2024 PX4 Development Team. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name PX4 nor the names of its contributors may be # used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ #============================================================================= # CMAKE CODING STANDARD FOR PX4 # # Structure # --------------------------------------------------------------------------- # # * Common functions should be included in px_base.cmake. # # * OS/ board specific fucntions should be include in # px_impl_${PX4_PLATFORM}.cmake # # Formatting # --------------------------------------------------------------------------- # # * Use hard indents to match the px4 source code. # # * All function and script arguments are upper case. # # * All local variables are lower case. # # * All cmake functions are lowercase. # # * For else, endif, endfunction, etc, never put the name of the statement # # Functions/Macros # --------------------------------------------------------------------------- # # * Use px4_parse_function_args to parse functions and check for required # arguments. Unless there is only one argument in the function and it is clear. # # * Never use macros. They allow overwriting global variables and this # makes variable declarations hard to locate. # # * If a target from add_custom_* is set in a function, explicitly pass it # as an output argument so that the target name is clear to the user. # # * Avoid use of global variables in functions. Functions in a nested # scope may use global variables, but this makes it difficult to # reuse functions. # # Included CMake Files # --------------------------------------------------------------------------- # # * All variables in config files must have the prefix "config_". # # * Never set global variables in an included cmake file, # you may only define functions. This excludes config and Toolchain files. # This makes it clear to the user when variables are being set or targets # are being created. # # * Setting a global variable in a CMakeLists.txt file is ok, because # each CMakeLists.txt file has scope in the current directory and all # subdirectories, so it is not truly global. # # * All toolchain files should be included in the cmake # directory and named Toolchain-"name".cmake. # # Misc # --------------------------------------------------------------------------- # # * If referencing a string variable, don't put it in quotes. # Don't do "${PX4_PLATFORM}" STREQUAL "posix", # instead type ${PX4_PLATFORM} STREQUAL "posix". This will throw an # error when ${PX4_PLATFORM} is not defined instead of silently # evaluating to false. # #============================================================================= cmake_minimum_required(VERSION 3.9 FATAL_ERROR) set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE FILEPATH "PX4 source directory" FORCE) set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE FILEPATH "PX4 binary directory" FORCE) list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake) include(px4_parse_function_args) #============================================================================= # git # include(px4_git) execute_process( COMMAND git describe --exclude ext/* --always --tags OUTPUT_VARIABLE PX4_GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${PX4_SOURCE_DIR} ) set(PX4_GIT_TAG "v1.15.4") # git describe to X.Y.Z version string(REPLACE "." ";" VERSION_LIST ${PX4_GIT_TAG}) # major version list(GET VERSION_LIST 0 PX4_VERSION_MAJOR) string(REPLACE "v" "" PX4_VERSION_MAJOR ${PX4_VERSION_MAJOR}) # minor version list(GET VERSION_LIST 1 PX4_VERSION_MINOR) # patch version list(GET VERSION_LIST 2 PX4_VERSION_PATCH) string(REPLACE "-" ";" PX4_VERSION_PATCH ${PX4_VERSION_PATCH}) list(GET PX4_VERSION_PATCH 0 PX4_VERSION_PATCH) # # Capture only the hash part after 'g' string(REGEX MATCH "g([a-f0-9]+)$" GIT_HASH "${PX4_GIT_TAG}") set(PX4_GIT_HASH ${CMAKE_MATCH_1}) define_property(GLOBAL PROPERTY PX4_MODULE_LIBRARIES BRIEF_DOCS "PX4 module libs" FULL_DOCS "List of all PX4 module libraries" ) define_property(GLOBAL PROPERTY PX4_KERNEL_MODULE_LIBRARIES BRIEF_DOCS "PX4 kernel side module libs" FULL_DOCS "List of all PX4 kernel module libraries" ) define_property(GLOBAL PROPERTY PX4_MODULE_PATHS BRIEF_DOCS "PX4 module paths" FULL_DOCS "List of paths to all PX4 modules" ) define_property(GLOBAL PROPERTY PX4_SRC_FILES BRIEF_DOCS "src files from all PX4 modules & libs" FULL_DOCS "SRC files from px4_add_{module,library}" ) #============================================================================= # configuration # include(px4_add_module) set(config_module_list) set(config_kernel_list) # Find Python find_package(PythonInterp 3) # We have a custom error message to tell users how to install python3. if(NOT PYTHONINTERP_FOUND) message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n" " Ubuntu: sudo apt install python3 python3-dev python3-pip\n" " macOS: brew install python") endif() option(PYTHON_COVERAGE "Python code coverage" OFF) if(PYTHON_COVERAGE) message(STATUS "python coverage enabled") set(PYTHON_EXECUTABLE coverage run -p) endif() include(px4_config) include(kconfig) message(STATUS "PX4 config: ${PX4_CONFIG}") message(STATUS "PX4 platform: ${PX4_PLATFORM}") if($ENV{CLION_IDE}) # CLion automatically executes some compiler commands after configuring the # project. This would fail on NuttX, as visibility.h tries to (indirectly) # include nuttx/config.h, which at that point does not exist yet add_definitions(-DPX4_DISABLE_GCC_POISON) endif() if(${PX4_PLATFORM} STREQUAL "posix") if(ENABLE_LOCKSTEP_SCHEDULER) add_definitions(-DENABLE_LOCKSTEP_SCHEDULER) message(STATUS "PX4 lockstep: enabled") else() message(STATUS "PX4 lockstep: disabled") endif() endif() # external modules set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location") if(NOT EXTERNAL_MODULES_LOCATION STREQUAL "") get_filename_component(EXTERNAL_MODULES_LOCATION "${EXTERNAL_MODULES_LOCATION}" ABSOLUTE) endif() set_property(GLOBAL PROPERTY PX4_MODULE_CONFIG_FILES) include(platforms/${PX4_PLATFORM}/cmake/px4_impl_os.cmake) list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake) if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/init.cmake") include(init) endif() #============================================================================= # project definition # project(px4 CXX C ASM) # CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage) if(NOT CMAKE_BUILD_TYPE) if(${PX4_PLATFORM} STREQUAL "nuttx") set(PX4_BUILD_TYPE "MinSizeRel") else() set(PX4_BUILD_TYPE "RelWithDebInfo") endif() set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE) endif() if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage")) set(MAX_CUSTOM_OPT_LEVEL -O0) elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer") set(MAX_CUSTOM_OPT_LEVEL -O1) elseif(CMAKE_BUILD_TYPE MATCHES "Release") set(MAX_CUSTOM_OPT_LEVEL -O3) else() if(px4_constrained_flash_build) set(MAX_CUSTOM_OPT_LEVEL -Os) else() set(MAX_CUSTOM_OPT_LEVEL -O2) endif() endif() set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;AddressSanitizer;UndefinedBehaviorSanitizer") message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}") # Check if LTO option and check if toolchain supports it if(LTO) include(CheckIPOSupported) check_ipo_supported() message(AUTHOR_WARNING "LTO enabled: LTO is highly experimental and should not be used in production") set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) endif() set(package-contact "px4users@googlegroups.com") set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR}) #============================================================================= # gold linker - use if available (posix only for now) if(${PX4_PLATFORM} STREQUAL "posix") include(CMakeDependentOption) CMAKE_DEPENDENT_OPTION(USE_LD_GOLD "Use GNU gold linker" ON "NOT WIN32;NOT APPLE" OFF ) if(USE_LD_GOLD) execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) if("${LD_VERSION}" MATCHES "GNU gold") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold") else() set(USE_LD_GOLD OFF) endif() endif() endif() #============================================================================= # Setup install paths if(${PX4_PLATFORM} STREQUAL "posix") # This makes it possible to dynamically load code which depends on symbols # inside the px4 executable. set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_ENABLE_EXPORTS ON) if(CMAKE_BUILD_TYPE MATCHES "Coverage") include(coverage) endif() include(sanitizers) # Define GNU standard installation directories include(GNUInstallDirs) if (NOT CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE) endif() endif() include(ccache) #============================================================================= # get chip and chip manufacturer # px4_os_determine_build_chip() if(NOT PX4_CHIP_MANUFACTURER) message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP_MANUFACTURER") endif() if(NOT PX4_CHIP) message(FATAL_ERROR "px4_os_determine_build_chip() needs to set PX4_CHIP") endif() #============================================================================= # build flags # include(px4_add_common_flags) px4_add_common_flags() px4_os_add_flags() #============================================================================= # board cmake init (optional) # if(EXISTS ${PX4_BOARD_DIR}/cmake/init.cmake) include(${PX4_BOARD_DIR}/cmake/init.cmake) endif() #============================================================================= # message, and airframe generation # include(px4_metadata) add_subdirectory(msg EXCLUDE_FROM_ALL) px4_generate_airframes_xml(BOARD ${PX4_BOARD}) #============================================================================= # external projects # set(ep_base ${PX4_BINARY_DIR}/external) set_property(DIRECTORY PROPERTY EP_BASE ${ep_base}) # add external project install folders to build # add the directories so cmake won't warn execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/lib) link_directories(${ep_base}/Install/lib) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ep_base}/Install/include) include_directories(${ep_base}/Install/include) #============================================================================= # external modules # set(external_module_paths) if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "") message(STATUS "External modules: ${EXTERNAL_MODULES_LOCATION}") add_subdirectory("${EXTERNAL_MODULES_LOCATION}/src" external_modules) foreach(external_module ${config_module_list_external}) add_subdirectory(${EXTERNAL_MODULES_LOCATION}/src/${external_module} external_modules/${external_module}) list(APPEND external_module_paths ${EXTERNAL_MODULES_LOCATION}/src/${external_module}) endforeach() endif() #============================================================================= # Testing - Automatic unit and integration testing with CTest # # optionally enable cmake testing (supported only on posix) option(CMAKE_TESTING "Configure test targets" OFF) if(${PX4_CONFIG} STREQUAL "px4_sitl_test") set(CMAKE_TESTING ON) endif() if(CMAKE_TESTING) include(CTest) # sets BUILD_TESTING variable endif() # enable test filtering to run only specific tests with the ctest -R regex functionality set(TESTFILTER "" CACHE STRING "Filter string for ctest to selectively only run specific tests (ctest -R)") # if testing is enabled download and configure gtest list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/cmake/gtest/) include(px4_add_gtest) if(BUILD_TESTING) include(gtest) add_custom_target(test_results COMMAND GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} --output-on-failure -T Test -R ${TESTFILTER} USES_TERMINAL DEPENDS px4 examples__dyn_hello USES_TERMINAL COMMENT "Running tests" WORKING_DIRECTORY ${PX4_BINARY_DIR}) set_target_properties(test_results PROPERTIES EXCLUDE_FROM_ALL TRUE) endif() #============================================================================= # subdirectories # add_library(parameters_interface INTERFACE) add_library(kernel_parameters_interface INTERFACE) add_library(events_interface INTERFACE) add_library(kernel_events_interface INTERFACE) include(px4_add_library) add_subdirectory(src/lib EXCLUDE_FROM_ALL) add_subdirectory(platforms/${PX4_PLATFORM}/src/px4) add_subdirectory(platforms EXCLUDE_FROM_ALL) if(EXISTS "${PX4_BOARD_DIR}/CMakeLists.txt") add_subdirectory(${PX4_BOARD_DIR}) endif() foreach(module ${config_module_list}) add_subdirectory(src/${module}) endforeach() # add events lib after modules and libs as it needs to know all source files (PX4_SRC_FILES) add_subdirectory(src/lib/events EXCLUDE_FROM_ALL) # metadata needs PX4_MODULE_CONFIG_FILES add_subdirectory(src/lib/metadata EXCLUDE_FROM_ALL) # must be the last module before firmware add_subdirectory(src/lib/parameters EXCLUDE_FROM_ALL) if(${PX4_PLATFORM} STREQUAL "nuttx" AND NOT CONFIG_BUILD_FLAT) target_link_libraries(parameters_interface INTERFACE usr_parameters) target_link_libraries(kernel_parameters_interface INTERFACE parameters) target_link_libraries(events_interface INTERFACE usr_events) target_link_libraries(kernel_events_interface INTERFACE events) else() target_link_libraries(parameters_interface INTERFACE parameters) target_link_libraries(events_interface INTERFACE events) endif() # firmware added last to generate the builtin for included modules add_subdirectory(platforms/${PX4_PLATFORM}) #============================================================================= # uORB graph generation: add a custom target 'uorb_graph' # set(uorb_graph_config ${PX4_BOARD}) set(graph_module_list "") foreach(module ${config_module_list}) set(graph_module_list "${graph_module_list}" "--src-path" "src/${module}") endforeach() add_custom_command(OUTPUT ${uorb_graph_config} COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/uorb_graph/create.py ${graph_module_list} --src-path src/lib --merge-depends --exclude-path src/examples --exclude-path src/lib/parameters # FIXME: enable & fix --file ${PX4_SOURCE_DIR}/Tools/uorb_graph/graph_${uorb_graph_config} WORKING_DIRECTORY ${PX4_SOURCE_DIR} COMMENT "Generating uORB graph" ) add_custom_target(uorb_graph DEPENDS ${uorb_graph_config}) include(bloaty) include(doxygen) include(metadata) include(package) # install python requirements using configured python add_custom_target(install_python_requirements COMMAND ${PYTHON_EXECUTABLE} -m pip install --break-system-packages --requirement ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt DEPENDS ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt USES_TERMINAL ) if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/finalize.cmake") include(finalize) endif()
最新发布
08-15
SmartEQ_Android_SO /Users/qingguo/Desktop/nounou/lib/iOSlib/fiemwork/SmartEQ_Android_SO/SmartEQ_Android_SO/smarteq_android_so.h /Users/qingguo/Desktop/nounou/lib/iOSlib/fiemwork/SmartEQ_Android_SO/SmartEQ_Android_SO/smarteq_android_so.h:9:10 'vector' file not found /Users/qingguo/Desktop/nounou/lib/iOSlib/fiemwork/SmartEQ_Android_SO/SmartEQ_Android_SO/smarteq_android_so.h:20:10 'QtCore/qglobal.h' file not found /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c++_arm64-apple-ios18.2_gnu++20/Test/Test.framework/Headers/Test.h /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c++_arm64-apple-ios18.2_gnu++20/Test/Test.framework/Headers/Test.h:1:9 (fatal) could not build module 'SmartEQ_Android_SO' /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c_arm64-apple-ios18.2_gnu17/Test/Test.framework/Headers/Test.h /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c_arm64-apple-ios18.2_gnu17/Test/Test.framework/Headers/Test.h:1:9 (fatal) could not build module 'SmartEQ_Android_SO' /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c_arm64-apple-ios18.2_gnu17/Test/Test.m /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c_arm64-apple-ios18.2_gnu17/Test/Test.m:1:9 (fatal) could not build module 'Test' /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c++_arm64-apple-ios18.2_gnu++20/Test/Test.mm /Users/qingguo/Library/Developer/Xcode/DerivedData/SmartEQ_Android_SO-aidlvwfzcntypmdixnaalvklpymc/Build/Intermediates.noindex/SmartEQ_Android_SO.build/Debug-iphoneos/SmartEQ_Android_SO.build/VerifyModule/SmartEQ_Android_SO_objective-c++_arm64-apple-ios18.2_gnu++20/Test/Test.mm:1:9 (fatal) could not build module 'Test' 在编库的时候出现问题
04-04
<think>嗯,用户遇到了在编译SmartEQ_Android_SO库时的错误。首先,我需要仔细看看他提供的错误信息。第一个错误是'smarteq_android_so.h'里的'vector'文件找不到。这通常是因为C++标准库头文件没有被正确包含。可能是在iOS项目中,没有使用C++的编译设置,或者头文件没有包含正确的命名空间。 接下来是'QtCore/qglobal.h'找不到,这说明项目可能依赖了Qt库,但Xcode里没有配置Qt的路径或者Qt本身没有被正确安装。Qt通常在Android或桌面应用中使用,而iOS可能不支持直接使用Qt,特别是如果这是一个跨平台库的话,可能需要调整配置。 然后,后面的错误都是关于无法构建模块'SmartEQ_Android_SO'和'Test'。这可能是因为前面的头文件错误导致后续模块无法生成。通常,如果头文件有问题,整个编译过程就会中断,导致后续的模块验证失败。 用户可能在尝试将Android库移植到iOS,或者这个库本身是跨平台的,但iOS的配置不正确。需要检查项目的头文件搜索路径,确保C++标准库被正确引用,以及Qt库是否存在或是否需要替换为iOS兼容的代码。另外,Objective-C和C++混编时可能需要调整编译器的设置,比如使用Objective-C++,或者检查头文件的包含方式是否正确,避免命名冲突。 还有可能,用户没有在Xcode中启用C++支持,比如设置CLANG_CXX_LIBRARY为libc++,或者在项目的Build Settings里添加必要的C++编译标志。对于'vector'头文件的问题,可能需要检查是否使用了正确的include语句,比如#include <vector>,并且是否在Objective-C文件中正确使用了.mm扩展名以支持C++代码。 对于Qt相关的错误,如果项目确实依赖Qt,可能需要将Qt的路径添加到Header Search Paths中,或者考虑在iOS项目中移除Qt依赖,改用其他方法。因为Qt在iOS上的支持可能有限,或者需要特定的构建配置。 最后,模块构建失败可能由多个累积错误导致,需要逐步解决每一个报错,从最开始的错误开始处理,因为后面的错误可能是由前面的问题引发的。建议用户先解决'vector'和'QtCore/qglobal.h'的问题,再重新编译,看看后续错误是否消失。</think>您遇到的编译错误主要集中在头文件缺失和模块构建失败,这些问题通常由以下原因引起: $\boxed{问题分析及解决方案}$ 一、C++标准库缺失('vector' file not found) $\boxed{步骤1}$ 检查文件后缀名 - 确保包含C++代码的.m文件已改为.mm扩展名(Objective-C++) - 在Xcode中检查文件类型:选中文件 → 右侧属性面板 → Type改为"Objective-C++ Source" $\boxed{步骤2}$ 配置编译器设置 1. 项目设置 → Build Settings 2. 搜索"Apple Clang - Language" 3. 设置以下参数: - C++ Language Dialect → GNU++20 - C++ Standard Library → libc++ 二、Qt库缺失('QtCore/qglobal.h' file not found) $\boxed{步骤3}$ 处理跨平台依赖 1. 此错误表明项目包含Android/Qt特定代码 2. iOS平台解决方案: - 方案A:移除Qt依赖项 ```cpp // 注释或删除所有QT相关代码 // #include <QtCore/qglobal.h> // Q_DECL_EXPORT → 改为 __attribute__((visibility("default"))) ``` - 方案B:添加Qt for iOS框架(复杂,需重新编译Qt) 三、模块构建失败(could not build module) $\boxed{步骤4}$ 修复头文件架构 1. 验证头文件兼容性: ```objc #if __has_include("smarteq_android_so.h") #import "smarteq_android_so.h" #else // 添加兼容性声明 #endif ``` 2. 设置模块映射: - 创建module.modulemap文件: ```swift framework module SmartEQ_Android_SO { header "smarteq_android_so.h" export * } ``` 3. 在Build Settings中设置: - DEFINES_MODULE → YES - MODULEMAP_FILE → 指定模块映射文件路径 四、架构验证问题(VerifyModule失败) $\boxed{步骤5}$ 关闭模块验证(临时方案) 1. 项目设置 → Build Settings 2. 搜索以下选项并设为NO- Validate Workspace → NO - CLANG_ENABLE_MODULES → NO - ONLY_ACTIVE_ARCH → YES $\boxed{附加建议}$ 1. 使用lipo检查二进制架构: ```bash lipo -info /path/to/SmartEQ_Android_SO.a ``` 确保包含arm64架构 2. 清理构建缓存: ```bash rm -rf ~/Library/Developer/Xcode/DerivedData ``` 3. 示例兼容性头文件写法: ```cpp #if defined(__ANDROID__) #include <vector> #elif defined(__APPLE__) #include <vector> #endif ``` 这些错误表明项目存在跨平台兼容性问题,建议优先解决C++标准库配置问题,再处理Qt依赖项。如果项目需要长期维护,建议分离平台相关代码到独立模块。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值