V3.17.1 curl_easy_init Linker Error

Hello!

I am getting a linker error when compiling for Android Studio:

  • error: undefined reference to ‘curl_easy_init’

I checked cpptests but it uses cmake, and i need to use ndkbuild as sdkbox plugin is broken with cmake. (see: SDKBox 2.4.3.0 bugfix)

Config below:

Thanks!
Akshay

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

FILE_LIST := $(wildcard \
$(LOCAL_PATH)/hellocpp/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../../GameEngine/*.cpp)

LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_CPPFLAGS := -DSDKBOX_ENABLED
LOCAL_LDLIBS := -landroid \
-llog
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES := PluginFacebook \
sdkbox \
PluginIAP \
PluginSdkboxAds \
PluginAdMob

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cc_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)
$(call import-add-path, $(LOCAL_PATH))
$(call import-module, cocos)
$(call import-module, curl/prebuilt/android)

$(call import-module, ./sdkbox)
$(call import-module, ./pluginfacebook)
$(call import-module, ./pluginiap)
$(call import-module, ./pluginsdkboxads)
$(call import-module, ./pluginadmob)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

Application.mk

APP_STL := c++_static

APP_CPPFLAGS := -frtti \
-DCC_ENABLE_CHIPMUNK_INTEGRATION=1 \
-std=c++11 \
-fsigned-char \
-Wno-extern-c-compat
APP_LDFLAGS := -latomic

APP_ABI := armeabi-v7a
APP_SHORT_COMMANDS := true

ifeq ($(NDK_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
else
APP_CPPFLAGS += -DNDEBUG
APP_OPTIM := release
endif
APP_PLATFORM := android-21

Does this happen if you run cocos new ... and create a new project, compile that our of the box?

Hello @slackmoehrle

Yes it does happen. Steps to reproduce:

  1. run cocos new
  2. Add basic curl code / include curl header
    CURL *curl = curl_easy_init();
    if (curl)
    {
    CCLOG(“Curl OK”);
    }
    else
    {
    CCLOG(“Curl FAIL”);
    }
  3. Change PROP_BUILD_TYPE=ndk-build
  4. Modify Android.mk to add:

$(call import-module, curl/prebuilt/android)

  1. Make Error:
    CocosWorkspace2/CurlTest/proj.android/app/jni/…/…/…/Classes/AppDelegate.cpp:154: error: undefined reference to ‘curl_easy_init’

Thanks

Akshay

And you are including the curl header in AppDelegate?

Yup, AppDelegate is compiling fine.

#include “curl/include/android/curl/curl.h”

I am getting an error at the time of linking. See below:

[armeabi-v7a] Compile++ thumb: MyGame_shared <= main.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= AppDelegate.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= HelloWorldScene.cpp

[armeabi-v7a] StaticLibrary : libccs.a
[armeabi-v7a] StaticLibrary : libc3d.a
[armeabi-v7a] StaticLibrary : flatbuffers.a
[armeabi-v7a] StaticLibrary : libets.a
[armeabi-v7a] StaticLibrary : libaudio.a
[armeabi-v7a] StaticLibrary : libnet.a
[armeabi-v7a] StaticLibrary : libext_vorbisidec.a
[armeabi-v7a] StaticLibrary : libext_pvmp3dec.a
[armeabi-v7a] StaticLibrary : libcc_core.a
[armeabi-v7a] StaticLibrary : librecast.a
[armeabi-v7a] SharedLibrary : libMyGame.so
/Users/akshaybajaj/Documents/CocosWorkspace2/CurlTest/proj.android/app/jni/…/…/…/Classes/AppDelegate.cpp:154: error: undefined reference to ‘curl_easy_init’
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/akshaybajaj/Documents/CocosWorkspace2/CurlTest/proj.android/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libMyGame.so] Error 1

Did you add the curl files to Android.mk?

Hello @slackmoehrle. I’ve just fixed the linker issue at compile time by explicitly adding the curl & crypto modules. See line below:

LOCAL_STATIC_LIBRARIES := cc_static ext_curl ext_crypto

Thank you once again for the amazing support that you guys provide!

1 Like