C++基础---string类的data/c_str/copy

本文详细介绍了C++标准库中string类的三种转换方法:data、c_str及copy。通过示例代码展示了如何将string对象转换为C风格字符串,并讨论了它们在实际应用中的差异。

1.string类的data/c_str/copy

1.1 std::string::data

  • 原型: const char *data()const;
  • 功能: string型字符串转化为char型字符串。
  • 说明:将自身转化为一个以空终止符结束(即带”\0“结尾)的char型字符串。
  • 返回值:一个指向字符串数组的指针,字符串数组指针。
  • 代码示例:

    (1)示例代码一:
    
    #include <iostream>
    
    
    #include <string>
    
    using namespace std;
    int main ()
    {
        string str = "Test string";
        char *cstr = "Test string";
    
        if (str.length() == strlen(cstr))
        {
            cout<<"str and cstr have the same length."<<endl;
    
            if (memcmp(cstr, str.data(), str.length()) == 0)
            {
                cout<<"str and cstr have the same content."<<endl;
            }
        }
    
        system("pause");
        return 0;
    }
    =>str and cstr have the same length.
      str and cstr have the same content.
    (2)示例代码二:
    
    #include <iostream>
    
    
    #include <string>
    
    using namespace std;
    int main ()
    {
        string str("Please split this sentence into tokens");
        const char *split = " ";
        char *cstr = new char [str.length()+1];
        strcpy_s(cstr, str.size() + 1, str.data());
    
        //cstr now contains a c-string copy of str
        char *p = 0;
        char *pNext = 0;
        p = strtok_s(cstr, split, &pNext);
        while(p != 0)
        {
            cout<<p<<endl;
            p = strtok_s(NULL, split, &pNext);
        }
    
        delete[] cstr;
        system("pause");
    
        return 0;
    }   
    =>Please
      split
      this
      sentence
      into
      tokens

1.2 std::string::c_str

  • 原型:const char *c_str()const;
  • 功能: string型字符串转化为char型字符串。
  • 说明:将自身转化为一个以空终止符结束(即带”\0“结尾)的char型字符串。
  • 返回值:一个指向字符串数组的指针,字符串数组指针。
  • 代码示例:

    (1)示例代码一:
    
    #include <iostream>
    
    
    #include <string>
    
    using namespace std;
    int main ()
    {
        string str = "Test string";
        char *cstr = "Test string";
    
        if (str.length() == strlen(cstr))
        {
            cout<<"str and cstr have the same length."<<endl;
    
            if (memcmp(cstr, str.c_str(), str.length()) == 0)
            {
                cout<<"str and cstr have the same content"<<endl;
            }
        }
    
        system("pause");
        return 0;
    }
    =>str and cstr have the same length.
      str and cstr have the same content.
    (2)示例代码二:
    
    #include <iostream>
    
    
    #include <string>
    
    using namespace std;
    int main ()
    {
        string str("Please split this sentence into tokens");
        const char *split = " ";
        char *cstr = new char [str.length()+1];
        strcpy_s(cstr, str.size() + 1, str.c_str());
    
        //cstr now contains a c-string copy of str
        char *p = 0;
        char *pNext = 0;
        p = strtok_s(cstr, split, &pNext);
        while (p != 0)
        {
            cout<<p<<endl;
            p = strtok_s(NULL, split, &pNext);
        }
    
        delete[] cstr;
        system("pause");
    
        return 0;
    }
    =>Please
      split
      this
      sentence
      into
      tokens

1.3 std::string::copy

  • 原型:size_t copy (char* s, size_t len, size_t pos = 0) const;
  • 功能: string型字符串转化为char型字符串。
  • 说明:从源字符串以下标为pos(默认为0)处开始拷贝n个字符到char型字符串s中。
  • 返回值:实际拷贝的字符个数。
  • 代码示例:

    
    #pragma warning(disable:4996) //全部关掉
    
    
    #include <iostream>
    
    
    #include <string>
    
    using namespace std;
    int main ()
    {
        char buffer[20];
        string str("Test string...");
        size_t length = str.copy(buffer, 6, 5);
        buffer[length]='\0';
        cout<<"buffer contains: "<<buffer<<endl;
        system("pause");
        return 0;
    }
    =>buffer contains: string

参考文献:
[1] 网络资源: http://www.cplusplus.com/reference/string/string/data/
       http://www.cplusplus.com/reference/string/string/c_str/
       http://www.cplusplus.com/reference/string/string/copy/

FAILED: obj/foundation/multimedia/media_foundation/src/meta/media_foundation/format.o /usr/bin/ccache ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang++ -MMD -MF obj/foundation/multimedia/media_foundation/src/meta/media_foundation/format.o.d -DHST_ANY_WITH_NO_RTTI -DMEDIA_OHOS -DDYNAMIC_PLUGINS -DHST_PLUGIN_PATH=\"/system/lib64/media/media_plugins\" -DHST_PLUGIN_FILE_TAIL=\".z.so\" -DV8_DEPRECATION_WARNINGS -D_GNU_SOURCE -DHAVE_SYS_UIO_H -D__MUSL__ -D_LIBCPP_HAS_MUSL_LIBC -D__BUILD_LINUX_WITH_CLANG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DCOMPONENT_BUILD -D__GNU_SOURCE=1 -DCHROMIUM_CXX_TWEAK_INLINES -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DSOFTBUS_LINUX -DDRIVERS_INTERFACE_DISPLAY_ENABLE -DUSE_GRAPHIC_TEXT_GINE -DACE_ENABLE_GL -DRS_ENABLE_GL -DENABLE_RECORDING_DCL -DRS_DISABLE_EGLIMAGE -DRS_ENABLE_PARALLEL_RENDER -Iobj/third_party/musl/usr/include/aarch64-linux-ohos -Ioverride/third_party -I../.. -Igen -I../../foundation/multimedia/media_foundation/osal/base -I../../foundation/multimedia/media_foundation/plugin -I../../foundation/multimedia/media_foundation/src/buffer/avbuffer/include -I../../foundation/multimedia/media_foundation/src/buffer/avbuffer_queue/include -I../../foundation/multimedia/media_foundation/src/capi/common -I../../base/hiviewdfx/hilog/interfaces/native/innerkits/include -I../../foundation/graphic/graphic_surface/surface/include -I../../foundation/graphic/graphic_2d/utils/sync_fence/export -I../../foundation/graphic/graphic_2d/interface/inner_api/common -I../../third_party/bounds_checking_function/include -I../../third_party/ffmpeg -I../../foundation/multimedia/media_foundation/interface/kits/c -I../../foundation/multimedia/media_foundation/interface/inner_api -I../../foundation/multimedia/media_foundation/interface/inner_api/buffer -I../../foundation/multimedia/media_foundation/interface/inner_api/common -I../../foundation/multimedia/media_foundation/interface/inner_api/meta -I../../foundation/graphic/graphic_surface/interface/inner_api/surface -I../../commonlibrary/c_utils/base/include -I../../base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include -I../../foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include -I../../foundation/systemabilitymgr/samgr/interfaces/innerkits/dynamic_cache/include -I../../base/notification/eventhandler/interfaces/inner_api -I../../base/notification/eventhandler/frameworks/eventhandler/include -I../../foundation/communication/ipc/interfaces/innerkits/ipc_core/include -I../../foundation/communication/dsoftbus/interfaces/kits -I../../foundation/communication/dsoftbus/interfaces/kits/bus_center -I../../foundation/communication/dsoftbus/interfaces/kits/common -I../../foundation/communication/dsoftbus/interfaces/kits/discovery -I../../foundation/communication/dsoftbus/interfaces/kits/transport -I../../foundation/communication/dsoftbus/sdk/transmission/session/cpp/include -I../../foundation/communication/dsoftbus/interfaces/inner_kits/transport -I../../foundation/communication/dsoftbus/core/common/dfx/hisysevent_adapter/include -I../../foundation/communication/dsoftbus/core/common/dfx/interface/include -I../../foundation/communication/dsoftbus/components/nstackx/nstackx_core/dfile/interface -I../../foundation/communication/dsoftbus/components/nstackx/nstackx_util/interface -I../../foundation/graphic/graphic_surface/interfaces/inner_api/surface -I../../foundation/graphic/graphic_surface/interfaces/inner_api/common -I../../foundation/graphic/graphic_surface/interfaces/inner_api/utils -I../../foundation/graphic/graphic_surface/sandbox -I../../foundation/graphic/graphic_surface/scoped_bytrace/include -I../../foundation/graphic/graphic_surface/sync_fence/include -I../../base/hiviewdfx/hilog/interfaces/native/innerkits -I../../foundation/graphic/graphic_2d/utils/log -I../../base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter -I../../foundation/communication/ipc/ipc/native/src/core/include -I../../foundation/communication/ipc/ipc/native/src/mock/include -fno-strict-aliasing -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -funwind-tables -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -flto=thin -fsplit-lto-unit -ffunction-sections -fno-short-enums --target=aarch64-linux-ohos -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 --param=ssp-buffer-size=4 -fstack-protector-strong -fPIC -Wall -Werror -Wextra -Wimplicit-fallthrough -Wthread-safety -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-unneeded-internal-declaration -Wno-error=c99-designator -Wno-error=anon-enum-enum-conversion -Wno-error=sizeof-array-div -Wno-error=implicit-fallthrough -Wno-error=reorder-init-list -Wno-error=range-loop-construct -Wno-error=deprecated-copy -Wno-error=implicit-int-float-conversion -Wno-error=inconsistent-dllimport -Wno-error=unknown-warning-option -Wno-error=sign-compare -Wno-error=int-in-bool-context -Wno-error=return-stack-address -Wno-error=dangling-gsl -Wno-unused-but-set-variable -Wno-deprecated-declarations -Wno-unused-but-set-parameter -Wno-null-pointer-subtraction -Wno-unqualified-std-cast-call -Wno-user-defined-warnings -Wno-unused-lambda-capture -Wno-null-pointer-arithmetic -Wno-enum-compare-switch -O2 -fno-ident -fdata-sections -ffunction-sections -fno-omit-frame-pointer -g2 -ggnu-pubnames -fno-common -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare --param=ssp-buffer-size=4 -fstack-protector-ret-strong -O2 -fPIC -Wall -fexceptions -fno-rtti -Wno-unused-but-set-variable -Wno-format -fsanitize-trap=all -ftrap-function=abort -fsanitize-cfi-cross-dso -flto -fsanitize=cfi -fsanitize-blacklist=../../build/config/sanitizers/cfi_blocklist.txt -fvisibility=default -fsanitize=unsigned-integer-overflow -fsanitize=signed-integer-overflow -fsanitize-blacklist=../../build/config/sanitizers/integer_overflow_blocklist.txt -fno-sanitize-trap=integer,undefined -fno-sanitize-recover=integer,undefined -fsanitize-minimal-runtime -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -Wno-error=deprecated-declarations -DCONFIG_STANDARD_SYSTEM -DBUILD_PUBLIC_VERSION -DCONFIG_ACTV_BINDER -std=c++17 -fno-exceptions -fno-rtti --sysroot=obj/third_party/musl -fvisibility-inlines-hidden -O2 -fPIC -Wall -fexceptions -fno-rtti -Wno-unused-but-set-variable -Wno-format -c ../../foundation/multimedia/media_foundation/src/meta/format.cpp -o obj/foundation/multimedia/media_foundation/src/meta/media_foundation/format.o ../../foundation/multimedia/media_foundation/src/meta/format.cpp:142:76: error: no member named 'c_str' in 'std::string_view' MEDIA_LOG_E("liubing PutIntValue key:%{public}s value:%{public}d", key.c_str(), value);这个错误是啥意思
08-27
S32 add_string(char* str) { logPool* pool = &g_log_pool; if (NULL == str) { return ERROR; } //pthread_mutex_lock(&pool->mutex); int str_len = strlen(str); HUB_MANAGE_ERROR("strlen: %d", str_len); if (str_len >= STRING_SIZE) { //pthread_mutex_unlock(&pool->mutex); return ERROR; } if (pool->count >= pool->capacity) { int index = pool->head; strncpy(pool->slots[index].data, str, STRING_SIZE - 1); pool->slots[index].data[str_len] = '\0'; pool->slots[index].length = str_len; pool->head = (pool->head + 1) % pool->capacity; pool->tail = (pool->tail + 1) % pool->capacity; atomic_thread_fence(memory_order_release); } else { int index = pool->tail; strncpy(pool->slots[index].data, str, STRING_SIZE - 1); pool->slots[index].data[str_len] = '\0'; pool->slots[index].used = 1; pool->slots[index].length = str_len; pool->tail = (pool->tail + 1) % pool->capacity; pool->count++; atomic_thread_fence(memory_order_release); } //pthread_mutex_unlock(&pool->mutex); return OK; } char* pop_oldest_string() { logPool* pool = &g_log_pool; atomic_thread_fence(memory_order_acquire); char* result= NULL; int index = 0; if (pool->count == 0) { return NULL; } //pthread_mutex_lock(&pool->mutex); if (pool->count == 0) { //pthread_mutex_unlock(&pool->mutex); return NULL; } index = pool->head; result = pool->slots[index].data; pool->slots[index].used = 0; pool->slots[index].length = 0; pool->head = (pool->head + 1) % pool->capacity; pool->count--; //pthread_mutex_unlock(&pool->mutex); return result; }这两个函数里的atomic_thread_fence有什么用
11-08
(edgenat) root@autodl-container-b2b911ba00-6b40f8a2:~/autodl-tmp/EdgeNAT-main# cp -r ~/autodl-tmp/NATTEN-main /root/ cd /root/NATTEN-main pip install --no-build-isolation --no-cache-dir . Looking in indexes: http://mirrors.aliyun.com/pypi/simple Processing /root/NATTEN-main Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [14 lines of output] `NATTEN_CUDA_ARCH` not set, but detected CUDA driver with PyTorch. Building for CUDA_ARCH='7.0'. Traceback (most recent call last): File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 175, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/setuptools/build_meta.py", line 374, in prepare_metadata_for_build_wheel self.run_setup() File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 93, in <module> AssertionError: NATTEN only supports CUDA 12.0 and above. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> from file:///root/NATTEN-main note: This is an issue with the package mentioned above, not pip. hint: See above for details. (edgenat) root@autodl-container-b2b911ba00-6b40f8a2:~/NATTEN-main# pip install natten -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.7.1/index.html -i https://mirrors.aliyun.com/pypi/simple/ Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Looking in links: https://download.openmmlab.com/mmcv/dist/cu118/torch2.7.1/index.html Collecting natten Downloading https://mirrors.aliyun.com/pypi/packages/5a/ca/002c2a2bb8503af754831b60b89f86ab5b289605bbcfba65daf9923eaccd/natten-0.21.1.tar.gz (2.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.7/2.7 MB 6.8 MB/s 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: natten Building wheel for natten (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for natten (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [185 lines of output] /tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/torch/_subclasses/functional_tensor.py:279: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:84.) cpu = _conversion_method_template(device=torch.device("cpu")) `NATTEN_CUDA_ARCH` not set, but detected CUDA driver with PyTorch. Building for CUDA_ARCH='7.0'. PyTorch was built with CUDA Toolkit 128 Building NATTEN for the following architecture(s): 7.0 Number of workers: 13 running bdist_wheel running build running build_py creating build/lib.linux-x86_64-cpython-310/natten copying src/natten/__init__.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/_environment.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/_libnatten.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/attn_merge.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/context.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/functional.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/modules.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/profiler.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/token_permute.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/types.py -> build/lib.linux-x86_64-cpython-310/natten copying src/natten/version.py -> build/lib.linux-x86_64-cpython-310/natten creating build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/blackwell_fmha.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/blackwell_fna.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/flex.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/fmha.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/fna.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/hopper_fmha.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/hopper_fna.py -> build/lib.linux-x86_64-cpython-310/natten/backends copying src/natten/backends/reference.py -> build/lib.linux-x86_64-cpython-310/natten/backends creating build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/dry_run.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/formatting.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/ops.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/pretty_printer.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/problem.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils copying src/natten/profiling_utils/profiling.py -> build/lib.linux-x86_64-cpython-310/natten/profiling_utils creating build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/checks.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/device.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/dtype.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/log.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/tensor.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/testing.py -> build/lib.linux-x86_64-cpython-310/natten/utils copying src/natten/utils/tuples.py -> build/lib.linux-x86_64-cpython-310/natten/utils creating build/lib.linux-x86_64-cpython-310/natten/backends/configs copying src/natten/backends/configs/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs copying src/natten/backends/configs/checks.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs creating build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/fna_backward_128x128.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/fna_backward_128x64.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/fna_backward_64x64.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/fna_forward_32x128.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/fna_forward_64x128.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass copying src/natten/backends/configs/cutlass/fna_forward_64x64.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass creating build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass_blackwell copying src/natten/backends/configs/cutlass_blackwell/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass_blackwell creating build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass_hopper copying src/natten/backends/configs/cutlass_hopper/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/cutlass_hopper creating build/lib.linux-x86_64-cpython-310/natten/backends/configs/flex copying src/natten/backends/configs/flex/__init__.py -> build/lib.linux-x86_64-cpython-310/natten/backends/configs/flex running egg_info writing src/NATTEN.egg-info/PKG-INFO writing dependency_links to src/NATTEN.egg-info/dependency_links.txt writing top-level names to src/NATTEN.egg-info/top_level.txt reading manifest file 'src/NATTEN.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching '*.cc' under directory 'csrc' warning: no files found matching '*.inl' under directory 'csrc' warning: no files found matching '*.cpp' under directory 'third_party/cutlass/include' warning: no files found matching '*.cuh' under directory 'third_party/cutlass/include' warning: no files found matching '*.cu' under directory 'third_party/cutlass/include' warning: no files found matching '*.txt' under directory 'third_party/cutlass/include' warning: no files found matching '*.cc' under directory 'third_party/cutlass/include' no previously-included directories found matching 'dev' no previously-included directories found matching 'site' no previously-included directories found matching 'csrc/autogen' no previously-included directories found matching 'tests' no previously-included directories found matching 'assets' no previously-included directories found matching '*/__pycache__' no previously-included directories found matching 'build/*' no previously-included directories found matching 'build_dir/*' no previously-included directories found matching 'CMakeFiles/*' adding license file 'LICENSE' adding license file 'NOTICE' writing manifest file 'src/NATTEN.egg-info/SOURCES.txt' running build_ext -- The CXX compiler identification is GNU 11.3.0 -- The CUDA compiler identification is NVIDIA 11.8.89 with host compiler GNU 11.3.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Detecting CUDA compiler ABI info -- Detecting CUDA compiler ABI info - done -- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - skipped -- Detecting CUDA compile features -- Detecting CUDA compile features - done CMake Error at /tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/cmake/data/share/cmake-4.1/Modules/FindPackageHandleStandardArgs.cmake:227 (message): Could NOT find CUDAToolkit: Found unsuitable version "11.8.89", but required is at least "12.0" (found /usr/local/cuda/targets/x86_64-linux/include) Call Stack (most recent call first): /tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/cmake/data/share/cmake-4.1/Modules/FindPackageHandleStandardArgs.cmake:589 (_FPHSA_FAILURE_MESSAGE) /tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/cmake/data/share/cmake-4.1/Modules/FindCUDAToolkit.cmake:1090 (find_package_handle_standard_args) CMakeLists.txt:6 (find_package) -- Configuring incomplete, errors occurred! Preparing to build LIBNATTEN Auto-generating kernel instantiations Stamping out reference kernels -- reference did not have any previously generated targets; direct copy. -- reference did not have any previously generated targets; direct copy. Stamping out fna kernels -- fna did not have any previously generated targets; direct copy. -- fna did not have any previously generated targets; direct copy. Stamping out fmha kernels -- fmha did not have any previously generated targets; direct copy. -- fmha did not have any previously generated targets; direct copy. Building NATTEN for the following archs: [70] (max: 70) Building with 13 workers. Build directory: /tmp/tmp7ktgpckm IS_LIBTORCH_BUILT_WITH_CXX11_ABI=True Traceback (most recent call last): File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/root/miniconda3/envs/edgenat/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel return _build_backend().build_wheel( File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 435, in build_wheel return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)]) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 423, in _build return self._build_with_temp_dir( File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 404, in _build_with_temp_dir self.run_setup() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 500, in <module> File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 115, in setup return distutils.core.setup(**attrs) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 186, in setup return run_commands(dist) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 202, in run_commands dist.run_commands() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands self.run_command(cmd) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1102, in run_command super().run_command(command) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/command/bdist_wheel.py", line 370, in run self.run_command("build") File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command self.distribution.run_command(command) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1102, in run_command super().run_command(command) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build.py", line 135, in run self.run_command(cmd_name) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command self.distribution.run_command(command) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1102, in run_command super().run_command(command) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/command/build_ext.py", line 96, in run _build_ext.run(self) File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 368, in run self.build_extensions() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 484, in build_extensions self._build_extensions_serial() File "/tmp/pip-build-env-gyhmwhcs/overlay/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py", line 510, in _build_extensions_serial self.build_extension(ext) File "<string>", line 466, in build_extension File "/root/miniconda3/envs/edgenat/lib/python3.10/subprocess.py", line 369, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-fb67jcs4/natten_8921a7027ba34c649a135d215e8392a9/csrc', '-DPYTHON_PATH=/root/miniconda3/envs/edgenat/bin/python3.10', '-DOUTPUT_FILE_NAME=natten/libnatten.cpython-310-x86_64-linux-gnu', '-DNATTEN_CUDA_ARCH_LIST=70-real', '-DNATTEN_IS_WINDOWS=0', '-DIS_LIBTORCH_BUILT_WITH_CXX11_ABI=1']' returned non-zero exit status 1. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for natten Failed to build natten error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> natten
最新发布
11-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值