Cocos2dx 4.0 Android Studio curl linker error

Continuing the discussion from Cocos2dx 3.17 Android Studio curl linker error:

I’m porting over game code to cocos2dx 4.0 from another engine…

…and I’m having the exact same problem here. I’m completely new to android studio… and cmake… and gradle… so figuring out how to diagnose these kind of issues is really tough.

To summarize the other post, as soon as I include curl in my project, I cannot link:

> 
> cmd.exe /C "cd . && C:\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android16 --gcc-toolchain=C:/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -frtti -fexceptions -fsigned-char -std=c++17 -stdlib=libc++ -Wno-switch -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libMyGame.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libMyGame.so @CMakeFiles\MyGame.rsp  && cd ."
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function ossl_connect_common: error: undefined reference to 'PKCS12_parse'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function ossl_connect_common: error: undefined reference to 'BIO_f_ssl'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function Curl_ossl_version: error: undefined reference to 'OpenSSL_version_num'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function Curl_ossl_seed: error: undefined reference to 'RAND_load_file'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function Curl_ossl_seed: error: undefined reference to 'RAND_file_name'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function Curl_ossl_seed: error: undefined reference to 'RAND_load_file'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function ossl_send: error: undefined reference to 'OpenSSL_version_num'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function servercert: error: undefined reference to 'OCSP_response_status_str'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function servercert: error: undefined reference to 'OCSP_basic_verify'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function servercert: error: undefined reference to 'OCSP_cert_status_str'
> ../../../../../../cocos2d/external/curl/prebuilt/android/x86/libcurl.a(libcurl_la-openssl.o):vtls/openssl.c:function servercert: error: undefined reference to 'OCSP_crl_reason_str'
> clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> ninja: build stopped: subcommand failed.

Any ideas or help or advice would be greatly appreciated!

Thank you,
Mark

If you do a web search for the functions that it is complaining about, then you’ll see that they exist in either the ssl or crypto libraries, which must be linked to Curl in order for it to work.

For example, if you look at external/CMakeLists.txt in the cocos2d-x folder, and you’ll see this:

if(BUILD_EXT_OPENSSL)
    add_subdirectory(openssl)
    target_link_libraries(external ext_ssl)
    target_link_libraries(external ext_crypto)
endif(BUILD_EXT_OPENSSL)

Curl is already included with Cocos2d-x, but I’m not sure if the supplied pre-compiled version is using OpenSSL functionality.

1 Like

Right! I agree with everything you say. In this file, everything is marked as ON, including OPENSSL.

All the external projects that contain source code and need to be built (that are not just prebuilt), do in fact get built and are placed into the cmake build lib folder.

Looking at the build output, I see that these same projects do get linked (like listed below):
[4203/4215] Linking CXX static library lib\libext_clipper.a

And there is also this one:
[4204/4215] Linking CXX static library lib\libexternal.a
(900 bytes? Is that right?)

But the projects that are just using prebuilt… I see no sign of ssl/crypto/curl anywhere at all in the build log. The .a files do ‘exist’ in those external prebuilt directories, but I can’t see any proof of them actually getting used in any way otherwise. Should I be seeing them anyplace else?

Thanks for helping! Time for bed.
Mark

You need to modify cmake files for curl to work on Android with Windows.

  1. In your project main dir add below code project\CMakeLists.txt after line 149
# Add CURL
if(ANDROID)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cocos2d/external/curl/)
    target_link_libraries(${APP_NAME} ext_curl)
endif()
  1. Comment two lines In project\cocos2d\external\CMakeLists.txt at 66 & 69
if(NOT LINUX)
#    add_subdirectory(curl)
    add_subdirectory(png)
    target_link_libraries(external 
#        ext_curl
        ext_png
    )
endif(NOT LINUX)
  1. Replace below line In project\cocos2d\external\curl\CMakeLists.txt at 27
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/android/${ANDROID_ABI}/lib${lib_name}.a"

It should work after that, I do same in 3.17.2

1 Like

Worked perfectly! Thanks for the help. This would have taken me a very long time to figure out.

Mark

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