Is libcurl broken?

Hello all,

I am trying to use curl in a package.

I created a package with the curl lib. However the curl functions I am using are not recognized during compilation! Shouldn't they be in the lib?!

The program I am trying to cross compile is running perfectly in my pc

This is the output of:

make -j1 V=sc package/mqtt_exemplo2/compile
mqtt_exemplo2.o: In function `main':
mqtt_exemplo2.c:(.text.startup+0x2f): undefined reference to `curl_global_init'
mqtt_exemplo2.c:(.text.startup+0x35): undefined reference to `curl_easy_init'
mqtt_exemplo2.c:(.text.startup+0x52): undefined reference to `curl_easy_setopt'
mqtt_exemplo2.c:(.text.startup+0x5b): undefined reference to `curl_easy_perform'
mqtt_exemplo2.c:(.text.startup+0x67): undefined reference to `curl_easy_strerror'
mqtt_exemplo2.c:(.text.startup+0x87): undefined reference to `curl_easy_cleanup'
mqtt_exemplo2.c:(.text.startup+0x8d): undefined reference to `curl_global_cleanup'
collect2: error: ld returned 1 exit status
make[3]: *** [makefile:10: mqtt_exemplo2] Error 1

I found this link with what is a patch to fix a similar problem, but I don't know how to apply it nor if it is current since it is 3 years old.

All the help to make curl work in my package will be deeply appreciated! :slight_smile:

For completeness I share here my package makefile:

include $(TOPDIR)/

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)

# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below

include $(INCLUDE_DIR)/

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/mqtt_exemplo2
  TITLE:=exemplo de MQTT client

# Package description; a more verbose description on what our package does
define Package/mqtt_exemplo2/description
  A simple "mqtt client 2" -application.

# Package preparation instructions; create the build directory and copy the source code. 
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)

# Package build instructions; invoke the GNU make tool to build our package
define Build/Compile
               CC="$(TARGET_CC)" \
           CFLAGS="$(TARGET_CFLAGS)" \

# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/mqtt_exemplo2/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/mqtt_exemplo2 $(1)/usr/bin

# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,mqtt_exemplo2))

My guess is that your compile step is faulty. You are trying to override the default compile logic with your own simplified step. Possibly you have overlooked some variable that is needed.

You could try deleting the whole compile section, as it is usually quite unnecessary.
The default compile us then used.

Hello @hnyman,

Just tried your suggestion and it did compile! Thanks! :slight_smile:

But when I try to install the package it gives me this error:

root@OpenWrt:/tmp# opkg install mqtt_exemplo2_1.0-1_x86_64.ipk 
Installing mqtt_exemplo2 (1.0-1) to root...
Installing libmbedtls12 (2.16.0-2) to root...
Collected errors:
 * opkg_install_pkg: Package size mismatch: libmbedtls12 is 184600 bytes, expecting 184583 bytes
 * opkg_install_cmd: Cannot install package mqtt_exemplo2.

Do you know what is causing this? Was it because I deleted as you suggested?
Without the curl reference, the package was being created and installing without any problems.

When you build your own packages, they and their dependencies need to be transferred to the target and installed. It looks like you’re trying to mix your package with dependencies from the OpenWrt repo

Could this error result from not having the same version of openwrt where I compiled and on the target system where I was trying to install?

My target system is 18.06.1, but I compiled it in 18.06.2 in my PC.

My OS is Ubuntu 18 (I upgraded from 16 some time ago, it is not a fresh install).

When I tried to replicate the openwrt 18.06.1 of the target system in my PC I get this error:

make -j1 V=s toolchain/install

It stops in error:

depbase=`echo lib/fseterr.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc    -I. -I./lib -I. -I./lib -I/home/joao/Documents/myStuff/   -O2 -I/home/joao/Documents/myStuff/  -MT lib/fseterr.o -MD -MP -MF $depbase.Tpo -c -o lib/fseterr.o lib/fseterr.c &&\
mv -f $depbase.Tpo $depbase.Po
lib/fseterr.c: In function 'fseterr':
lib/fseterr.c:77:3: error: #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
  #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
make[6]: *** [Makefile:3461: lib/fseterr.o] Error 1
make[6]: Leaving directory '/home/joao/Documents/myStuff/'
make[5]: *** [Makefile:4522: all-recursive] Error 1
make[5]: Leaving directory '/home/joao/Documents/myStuff/'
make[4]: *** [Makefile:2625: all] Error 2
make[4]: Leaving directory '/home/joao/Documents/myStuff/'
make[3]: *** [Makefile:31: /home/joao/Documents/myStuff/] Error 2
make[3]: Leaving directory '/home/joao/Documents/myStuff/'
Command exited with non-zero status 2
time: tools/bison/compile#9.28#1.00#10.28
make[2]: *** [tools/Makefile:154: tools/bison/compile] Error 2
make[2]: Leaving directory '/home/joao/Documents/myStuff/'
make[1]: *** [tools/Makefile:150: /home/joao/Documents/myStuff/] Error 2
make[1]: Leaving directory '/home/joao/Documents/myStuff/'
make: *** [/home/joao/Documents/myStuff/ toolchain/install] Error 2

Compiling in the 18.06.1 still doesn't work. I am compiling for "linux build system" because I am running it in virtualbox. However compiling in 18.06.2 works and I was able to install and run on the target system.

Many thanks to all that helped me to sort this out in this and the other threads. Specially to @jeff, @hnyman, @joaohcca, @anon50098793, ...

1 Like