Cocos2d-x didnt compile with box2d

i cant include box2d in cocos2d-x. i compile for android using cmake

add_subdirectory(MyGame/cocos2d/external/Box2D ${PROJECT_BINARY_DIR}/box2d)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
target_link_libraries(${APP_NAME}
cocos2d
box2d
)

this was in one question where it was usefull but for me it gave new errors.

CMake Error at MyGame/cocos2d/external/Box2D/CMakeLists.txt:11 (add_library):
add_library cannot create imported target “ext_box2d” because another
target with the same name already exists.

what i should to do with it? and error was showed twice

You need to disable the built-in Box2D first using this in your CMakeLists.txt:

set(BUILD_EXT_BOX2D OFF CACHE BOOL "Build with internal Box2D support" FORCE)

Make sure it’s added before the include(CocosBuildSet) line. Once you do that, delete the buildfolder/CMakeCache.txt file, and run cmake again to re-generate the project files.

2 Likes

thank you. it work and now i can solve new errors))

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.