Your fixed code is correct. tensorrt_cpp_api
is a lib, so link publically will always works no matter it is static or shared.
There are three modes for a target to link another lib, or include a directory: PUBLIC, PRIVATE and INTERFACE. For example: we have lib A and B, and a executable C. B links to A, and C links to B.
Pubic link:
target_link_libraries(B PUBLIC A)
target_link_libraries(C PRIVATE B)
B will link to A, and C will be linked to both A and B.
Private link:
target_link_libraries(B PRIVATE A)
target_link_libraries(C PRIVATE B)
B will link to A, and C will link to only B.
Interface link:
target_link_libraries(B INTERFACE A)
target_link_libraries(C PRIVATE B)
B will not link to A, but C will link to both B and A.
In summary, PUBLIC is contagious, and PRIVATE is not contagious. INTERFACE is only used when B doesn’t actually requires A, but most targets that links to B requires A. INTERFACE is rarely used.