How to automatically add library to project xcode in cc 3.5.2?


After i add some libs in build phases->link binary with libraries . I try to build project again by using cocos creator build tool. I opened project xcode again. In build phases->link binary with libraries , it was empty.
Is there any way to fix this problem?

1 Like

You need to edit:
native/engine/ios/CMakeLists.txt

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppTrackingTransparency")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Security")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework StoreKit")

Hope this will solve your issue.

1 Like

I tried it. it didn’t work @stark2022
image

I already know the problem why every time I rebuild, this field is empty. That’s because I chose the option skip xcode update . But I still want to know how if I build a new xcode project it can automatically add the library

The answer from @stark2022 should work.

And here a modernized is way

#...
cc_ios_after_target(${EXECUTABLE_NAME})

target_link_libraries(${EXECUTABLE_NAME} # PUBLIC
  "-framework AppTrackingTransparency"
  "-framework Security"
  "-framework StoreKit"
)

If the skip option is checked and needs to override the Xcode project, you can remove the build/ios folder or the single file build/ios/proj/CMakeCache.txt, to trigger regenerate.

1 Like

@PatriceJiang , will the library be added after building in cocos creator tool with the above command? .
I tried your code but it build failed . Are you sure the following is syntactically correct ?

target_link_libraries(${EXECUTABLE_NAME} PUBLIC
  "-framework AppTrackingTransparency"
  "-framework Security"
  "-framework StoreKit"
)

will the library be added after building in cocos creator tool with the above command?

Yes

Are you sure the following is syntactically correct ?

What kind of error report do you meet? target_link_libraries.

Pls, try whether you can correctly include the corresponding header file. I’m not sure whether your verification method is reliable

Try to remove the keyword PUBLIC to see if you can solve the error reported

1 Like

Sorry, i don’t have experience for ios development :frowning: . i thought that I had to check here @PatriceJiang .
image

If I have some library files which is downloaded . How to automatically add them to project xcode after build @PatriceJiang ?

You can use add_library and target_link_libraries

For example:

# import 
add_library(freetype STATIC IMPORTED GLOBAL)
set_target_properties(freetype PROPERTIES
  IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/libfreetype.a
  INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include/freetype
)
# link
target_link_libraries(${EXECUTABLE_NAME} PUBLIC
freetype 
)