The following is an example.
include_directories(
directoryPath1
directoryPath2
)The following is an example.
link_directories(
directoryPath3
directoryPath4
)The following is an example.
add_executable(main
directoryPath5
directoryPath6)The following is an example.
target_link_libraries(main
ascendcl
libName1
libName2)
When building code based on the AscendCL APIs, depend on the corresponding library files based on the included header files. If redundant .so files (such as libascendcl.a) are referenced, version functions may be abnormal or compatibility issues may occur during version update.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../../../out")
install(TARGETS main DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
To modify the CMakeLists.txt build script in the Image Classification with Caffe ResNet-50 (Synchronous Inference) sample, set the DDK_PATH and NPU_HOST_LIB environment variables, which point to the AscendCL header file directory and library file directory, respectively.
The following is an example of setting environment variables. ${INSTALL_DIR} indicates the CANN installation directory. For example, in $HOME/Ascend/ascend-toolkit/latest/{arch-os}, arch indicates the OS architecture, and {os} indicates the OS.
export DDK_PATH=${INSTALL_DIR} export NPU_HOST_LIB=${INSTALL_DIR}/{arch-os}/devlib
The .so library files in the ${INSTALL_DIR}/{arch-os}/devlib directory are required to build code using AscendCL APIs, without depending on any .so library files of other components (such as Driver). Therefore, when using the cmake command, set DCMAKE_SKIP_RPATH to TRUE, indicating that the rpath (that is, the ${INSTALL_DIR}/{arch-os}/devlib directory) is not added to the executable file generated during build.
When the app runs with the build succeeded, you can configure the environment variables to link the app with the .so library files in the lib64 directory in the operating environment. At run time, the app is automatically linked with other .so library files that depend on other components.
The following is an example command. ../../../src indicates the directory where the CMakeLists.txt file is located, and -DCMAKE_CXX_COMPILER specify the compiler. Change these parameters based on the actual requirements.
cmake ../../../src -DCMAKE_CXX_COMPILER=g++ -DCMAKE_SKIP_RPATH=TRUE
For details about the CMake parameters, go to https://cmake.org/cmake/help/latest/guide/tutorial/index.html and query the required version.
make
Upload the directories of the AscendCL initialization configuration file (acl.json), executable file, test image, and .om file to the same directory of the operating environment. Then log in to the operating environment, switch to the directory where the executable file is located, and run the executable file. The following command is an example:
./main
If a null pointer is passed to the aclInit API call for AscendCL initialization, the directory of the AscendCL initialization configuration file (acl.json) does not need to be uploaded to the operating environment.
If an error is reported during app running, fix it by referring to Troubleshooting.