This sample shows how to generate a static library for a simple HIP application. We will evaluate two types of static libraries: the first type exports host functions in a static library generated with --emit-static-lib and is compatible with host linkers, and second type exports device functions in a static library made with system ar.
Please refer to the hip_programming_guide for limitations.
## Static libraries with host functions
### Source files
The static library source files may contain host functions and kernel `__global__` and `__device__` functions. Here is an example (please refer to the directory host_functions).
The main() program source file may link with the above static library using either hipcc or a host compiler (such as g++). A simple source file that calls the host function inside libHipOptLibrary.a:
The static library source files which contain only `__device__` functions need to be created using ar. Here is an example (please refer to the directory device_functions).
hipDevice.cpp:
```
#include <hip/hip_runtime.h>
__device__ int square_me(int A) {
return A*A;
}
```
The above source file may be compiled into a static library, libHipDevice.a, by first compiling into a relocatable object, and then placed in an archive using ar:
The main() program source file can link with the static library using hipcc. A simple source file that calls the device function inside libHipDevice.a: