Libcurl library linking failed linking issue: `
I have created a new component in openwrt. I could build the component along with openwrt Make.
When linking with, the build fails.
"#include <curl/curl.h>
#include <iostream.h>
are included.

CURL *c1;

When i build this code, the build fails with Undefined Reference : curl_easy_init()".

i have included LIBS+=-L~/target..../curl/lib path for linking

Can someone please suggest the solution on accessing the base libraries and linking them with the user defined components in openwrt.
It would be very greatful.

When i build my component, the code is getting compiled with libcurl from ubuntu rather than using libcurl from openwrt.

I am in very much need of help.

You only added the library path with -L, not the library itself. You'll need to pass -lcurl as well.

Also, a ~ might no be resolved to a complete path when processed outside of the shell, so pass a complete, absolute path there (LIBS+=-L/home/yourself/...)

Hi Jow,

if i use -lcurl, my component is getting compiled but not generating .ipk file. it says missing dependencies with

If i dont use -lcurl, then it says undefined references to curl_easy_init().

any settings to be done to link my code with the libcurl library from openwrt. Please help.

I am badly stuck, can someone give inputs to proceed.

because libcurl provides curl_easy_init, so you need -lcurl then try and solve your issue with ipk

Hi, there was a similar problem. I added libcurl.a and everything was going

Can you suggest me on how did you include libcurl.a with some more explanation. I am not able to add it that way to openwrt Makefile.
Thank you.

Yes, this is an OpenWrt buildroot integrity check to ensure that your program package depends on all libraries it requires. To solve that, specify DEPENDS:=+libcurl in your Package/xxx section.

i have added DEPENDS:=+libcurl it is not able to generate .ipk file. Any sample example would help. Any additional settings are env variables to be set ? It is automatically refererring to the libcurl library in /usr/lib/x86.../ When already the libcurl and its ipk are available in openwrt, why to link externally.

Actual error messages as well as your current Makefile are needed to help you here. Statements like "is not able to generate .ipk file" do not help.

My assumption is that your inner application makefile (the non-OpenWrt one) is not cross compile safe and hardcodes things like "gcc" instead of referring to $(CC)

I have code in the path package/samplepgm/src/.
The Makefile inside package/samplepgm/src is as below:

 CURL_LIB = -L~/staging_dir/target-aarch64_cortex-a53_musl/root-brcm2708/usr/lib/
samplepgm: samplepgm.o
      $(CC) $(LDFLAGS) samplepgm.o -o samplepgm $(CURL_LIB) -lcurl
 samplepgm.o: samplepgm.c
      $(CC) $(CFLAGS) -c samplepgm.c
     rm *.o samplepgm

Outer Makefile in the path Package/Samplepgm is as below include $(TOPDIR)/

 include $(INCLUDE_DIR)/
 include $(INCLUDE_DIR)/
define Package/samplepgm
define Package/samplepgm/Default
define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/

define Package/samplepgmc
  $(call Package/samplepgmc/Default)
  TITLE+= (compiler)
define Package/libsamplepgm
   $(call Package/samplepgm/Default
 CURL_LIB:= -L~/staging_dir/target-aarch64_cortex-a53_musl/root-brcm2708/usr/lib/
 define Build/Compile
     $(MAKE) -C $(PKG_BUILD_DIR) $(INC) \
     LIBS+="$(CURL_LIB)" \
     ARCH="$(ARCH)" \
  define Package/samplepgm/install
     $(call Install/samplepgm,$(1))
     $(INSTALL_DIR) $(1)/usr/bin
     $(INSTALL_BIN) $(PKG_BUILD_DIR)/samplepgm $(1)/usr/bin/
 $(eval $(call BuildPackage,samplepgm))

package/samplepgm/Makefile [+] 1,1

Please let me know if there is any mistake. It is referring to /usr/lib libraries. Now, while typing here, i have just removed the below part from outer Makefile and compiled again and now it generated the .ipk file for my component.

define Package/libsamplepgm
$(call Package/samplepgm/Default

Is there a link or doc with proper of explanation on each parameter of the Makefile?

First of all remove the Build/Compile override, remove any CURL_LIB:= assignments, then proceed with make package/samplepgm/{clean,compile} V=sc and post the resulting errors here, if any.

Since you redefined Build/Compile to a manual $(MAKE) invocation, you dropped the passing of $(MAKE_FLAGS) which includes things like CC="$(TARGET_CC)" - this causes your inner Makefile to use the host compiler instead of the OpenWrt toolchain.

Now, its throwing the below error

Package samplepgm is missing dependencies for the following libraries
~openwrt_rpi/openwrt/scripts ~/staging_dir/target-aarch64_cortex-a53_musl/pkginfo

Makefile:81: recipe for target '~/openwrt/bin/packages/aarch64_cortex-a53/base/samplepgm_1.0.1_aarch64_cortex-a53.ipk' failed
make[2]: *** [~/openwrt/bin/packages/aarch64_cortex-a53/base/samplepgm_1.0.1_aarch64_cortex-a53.ipk] Error 1
make[2]: Leaving directory '~/openwrt/package/samplepgm'
Command exited with non-zero status 2
time: package/samplepgm/compile#0.18#0.05#0.21
package/Makefile:107: recipe for target 'package/samplepgm/compile' failed
make[1]: *** [package/samplepgm/compile] Error 2
make[1]: Leaving directory '~/openwrt'
~/openwrt/include/ recipe for target 'package/samplepgm/compile' failed
make: *** [package/samplepgm/compile] Error 2

how can i modify that, should i not have Build/compile at all ?

The default Build/Compile recipe is usually sufficient, you can find its definition in include/

Please ensure that package/samplepgm/src/ is clean and contains only *.c and *.h files (plus scripts, Makefiles etc. that might be required) and no *.o files or even precompiled exectuables.

The samplepgm/src is clean and dont have any .o or exe's. Though it is showing the same error.

Can i take these two parts of the -

144 define Build/Compile/Default
145 +$(MAKE_VARS)
148 $(1);
149 endef
151 define Build/Install/Default
152 $(MAKE_VARS)
155 $(if $(1), $(1), install);
156 endef

Then provide the output of ./staging_dir/toolchain-aarch64_cortex-a53*/bin/readelf -a ./build_dir/target-aarch64_cortex-a53_musl/samplepgm*/samplepgm

You could, but there is no point in copying these recipes 1:1

ok, Thank you so much for your help. Any good link to understand the openwrt build system?

Hi. I did so.

  1. Get source files open wrt.

  2. make menuconfig check libcur and create SDK

  3. Commpiled

  4. Finded path dir with libcur.a and

  5. To Eclipce add libcur Right butto project Settings -> Libraries top window add simle curl
    bottom add path to dir lib my path - /home/source/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/lib

  6. Add Settings-> PATH /home/source/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

  7. Add project files curl.h and etc