An Error Occurs During App Sample Compilation and Running

Symptom

The following problems occur in the app source code obtained by referring to App Samples:

Possible Cause

The {DDK_PATH} and {NPU_HOST_LIB} environment variables may be incorrectly set. In the samples provided in App Samples, these environment variables are used to search for AscendCL API header file and library file, which are the dependency files for the compilation of the app source code.

Solution

  1. Log in to the source code compilation environment and run the following commands to check the values of the {DDK_PATH} and {NPU_HOST_LIB} environment variables:

    • Checking the {DDK_PATH} value:
      echo $DDK_PATH

      Information similar to the following is displayed: (If no information is displayed, the environment variable is not set. Set it by referring to 4.)

      /home/HwHiAiUser/Ascend/ascend-toolkit/latest
    • Checking the {NPU_HOST_LIB} value:
      echo $NPU_HOST_LIB

      Information similar to the following is displayed: (If no information is displayed, the environment variable is not set. Set it by referring to 4.)

      /home/HwHiAiUser/Ascend/ascend-toolkit/latest/runtime/lib64/stub

  2. Check whether the header file exists in the directory specified by {DDK_PATH}.

    The compilation script of the sample searches for the header file on which compilation depends based on the {DDK_PATH}/runtime/include/acl directory. Therefore, you can check whether this directory exists. If yes, check whether the acl.h header file exists in this directory. If either the directory or the header file does not exist, set {DDK_PATH} again by referring to 4.

    • Check whether the directory exists:
      cd /home/HwHiAiUser/Ascend/ascend-toolkit/latest/runtime/include/acl
    • Check whether the acl.h file exists:
      ll acl.h

  3. Check whether the library file exists in the directory specified by {NPU_HOST_LIB}.

    The compilation script of the sample searches for the library file on which compilation depends based on the directory specified by {NPU_HOST_LIB}. Therefore, you can check whether this directory exists. If yes, check whether the libascendcl.so library file exists in this directory. If either the directory or the library file does not exist, set {NPU_HOST_LIB} again by referring to 4.

    • Check whether the directory exists:
      cd /home/HwHiAiUser/Ascend/ascend-toolkit/latest/runtime/lib64/stub
    • Check whether the libascendcl.so file exists:
      ll libascendcl.so

  4. Set the environment variables.

    The compilation script searches for the header file on which compilation depends based on the {DDK_PATH}/runtime/include/acl directory, and searches for the library file based on the directory specified by {NPU_HOST_LIB}. Replace $HOME/Ascend with the actual Ascend-CANN-Toolkit installation path.

    • If the OS architectures of the development and operating environments are the same, set the environment variables as follows:
      export DDK_PATH=$HOME/Ascend/ascend-toolkit/latest
      export NPU_HOST_LIB=$DDK_PATH/runtime/lib64/stub
    • If the OS architectures of the development and operating environments are different, set the environment variables as follows:

      For example, if the development environment uses the x86 architecture and the operating environment uses the AArch64 architecture, cross compilation is involved. In this case, you need to install the software package of the AArch64 architecture in the development environment and set the {DDK_PATH} environment variable to the installation directory of this software package. In this way, the header file and library file in the software package are the same as those in the operating environment, which facilitates code compilation.

      export DDK_PATH=$HOME/Ascend/ascend-toolkit/latest/arm64-linux
      export NPU_HOST_LIB=$DDK_PATH/runtime/lib64/stub
    • You can log in to the corresponding environment and run the uname -a command to query the OS architecture.
    • If you do not know the installation directory of the Ascend-CANN-Toolkit package, run the find -name "filename" command to search for the paths of the acl.h and libascendcl.so files and then set the environment variables.

      If multiple software versions are installed in the environment, select a version as required. By default, the latest directory points to the last installed software version.

      If there are multiple acl.h and libascendcl.so files in the same version, some of them are soft links for compatibility with earlier versions. This helps users compile app source code in earlier versions.