OpenWrt compiling package depended on libcurl

Hi Guys,

This will be my first post in a year working with Openwrt.

Well I have been working on a project and I have fully developed my Code functioning on TCP.
It is mostly a pc-ble-driver.

I want to use libcurl.

I have added it in menuconfig libraries-> libcurl and added into DEPENDS: in Makefile (+libcurl)

But I get undefined Reference on compiling package or make -j1 V=s

I have just used an example code and added it to my code to test if all compilation works but I failed on the first step itself.

Try adding the following to your package Makefile to review the exact link command.

MAKE_FLAGS+=VERBOSE=1

Please also check your project CMakeLists.txt has configured properly for depending on libcurl

Hey Yousong,

Thanks for replying.
below is my cMakeList.txt I don't understand it much.
Also, I added MAKE_FLAGS+=VERBOSE=1 but I don't see anything different.
where should I add what?
below is CMakelist.txt from the example code I am editing(/examples/heart_rate_collector). and also added Makefile of the package.

cmake_minimum_required(VERSION 3.3)

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $ENV{TARGET_LDFLAGS} -L$ENV{BUILD_DIR} -Wl,--rpath-link,$ENV{STAGING_DIR}/lib")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $ENV{TARGET_LDFLAGS} -Wl,--rpath-link,/home/lyx/workspace/openwrt/openwrt_thingoo/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/lib")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/home/lyx/workspace/openwrt/pc-ble-driver-master-widora -Wl,--rpath-link,/home/lyx/workspace/openwrt/openwrt_widora-master/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/lib ")


# Use multithreaded Boost libraries
set(Boost_USE_MULTITHREADED ON)

# Use static boost libraries so the dynamic library 
# can run anywhere
set(Boost_USE_STATIC_LIBS ON)

# Find the necessary boost components on the system.
# Minimum version required is 1.54.0
find_package ( Boost 1.54.0 REQUIRED COMPONENTS thread system regex date_time chrono )

link_directories (
    ../../build
)

include_directories (
    ../../include/common/sdk_compat
    ../../include/common
    ../../include/common/internal/transport
)

if(MSVC)
    add_definitions(-DPC_BLE_DRIVER_STATIC)
endif()

# Build executable
add_executable(hrc_v2 main.c)
add_executable(hrc_v3 main.c)

target_compile_definitions(hrc_v2 PRIVATE -DNRF_SD_BLE_API=2)
target_compile_definitions(hrc_v3 PRIVATE -DNRF_SD_BLE_API=3)

target_include_directories(hrc_v2 PRIVATE ../../src/sd_api_v2/sdk/components/softdevice/s132/headers)
target_include_directories(hrc_v3 PRIVATE ../../src/sd_api_v3/sdk/components/softdevice/s132/headers)

# Specify libraries to link with
if(MSVC)
    target_link_libraries(hrc_v3 PRIVATE pc_ble_driver_static_sd_api_v3)
    target_link_libraries(hrc_v2 PRIVATE pc_ble_driver_static_sd_api_v2)
else()
    target_link_libraries(hrc_v2 PRIVATE pc_ble_driver_shared_sd_api_v2)
    target_link_libraries(hrc_v3 PRIVATE pc_ble_driver_shared_sd_api_v3)
endif()

target_link_libraries(hrc_v2 PRIVATE ${Boost_LIBRARIES})
target_link_libraries(hrc_v3 PRIVATE ${Boost_LIBRARIES})

Also the make file the package.

# 
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
#
# Copyright (C) 2008 Frank Cervenka
#
# This is free software, licensed under the GNU General Public License v2.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=pc-ble-driver-v5
PKG_VERSION:=1.0
PKG_RELEASE:=1
# modify this to equal to your openwrt boost version
PKG_BOOST_NAME:=boost_1_58_0

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)


include $(INCLUDE_DIR)/package.mk

define Package/pc-ble-driver-v5/Default
  TITLE:=NordicSemiconductor's pc-ble-driver-v5
#  DEPENDS:=+libpthread +libstdcpp +udev 
  DEPENDS:=+libpthread +libstdcpp +udev +boost +boost-atomic +boost-thread +boost-system +boost-regex +boost-date_time +boost-chrono +libcurl
#  URL:=https://github.com/NordicSemiconductor/pc-ble-driver 
endef

define Package/libpc-ble-driver-v5
  $(call Package/pc-ble-driver-v5/Default)
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE+= runtime library
endef

define Package/pc-ble-driver-v5-tools
  $(call Package/pc-ble-driver-v5/Default)
# SECTION:=utils
  CATEGORY:=thingoo
  DEPENDS+=+libpc-ble-driver-v5
  TITLE+= tools
endef

#TARGET_CFLAGS = -luci

MAKE_FLAGS+=VERBOSE=1

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
	$(CP) ./files/* $(PKG_BUILD_DIR)/
	rm -f $(PKG_BUILD_DIR)/CMakeCache.txt
	rm -fR $(PKG_BUILD_DIR)/CMakeFiles
	rm -f $(PKG_BUILD_DIR)/Makefile ]
	rm -f $(PKG_BUILD_DIR)/cmake_install.cmake
	rm -f $(PKG_BUILD_DIR)/progress.make
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_monitor/CMakeCache.txt
	rm -fR $(PKG_BUILD_DIR)/examples/heart_rate_monitor/CMakeFiles
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_monitor/Makefile ]
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_monitor/cmake_install.cmake
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_monitor/progress.make
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_collector/CMakeCache.txt
	rm -fR $(PKG_BUILD_DIR)/examples/heart_rate_collector/CMakeFiles
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_collector/Makefile ]
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_collector/cmake_install.cmake
	rm -f $(PKG_BUILD_DIR)/examples/heart_rate_collector/progress.make
endef

define Build/Configure
	IN_OPENWRT=1 \
	AR="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ar" \
	AS="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC) -c $(TARGET_CFLAGS)" \
	LD="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ld" \
	NM="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)nm" \
	CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
	GCC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
	CXX="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)g++" \
	RANLIB="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ranlib" \
	STRIP="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)strip" \
	OBJCOPY="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)objcopy" \
	OBJDUMP="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)objdump" \
	TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
	TARGET_CFLAGS="$(TARGET_CFLAGS)" \
	TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
	STAGING_DIR="$(STAGING_DIR)" \
	cmake $(PKG_BUILD_DIR)/CMakeLists.txt -DBOOST_LIBRARYDIR=$(BUILD_DIR)/$(PKG_BOOST_NAME)/ipkg-install/lib 

	AR="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ar" \
	AS="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC) -c $(TARGET_CFLAGS)" \
	LD="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ld" \
	NM="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)nm" \
	CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
	GCC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
	CXX="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)g++" \
	RANLIB="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ranlib" \
	STRIP="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)strip" \
	OBJCOPY="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)objcopy" \
	OBJDUMP="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)objdump" \
	TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
	TARGET_CFLAGS="$(TARGET_CFLAGS)" \
	TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
	STAGING_DIR="$(STAGING_DIR)" \
	BUILD_DIR="$(PKG_BUILD_DIR)" \
	cmake $(PKG_BUILD_DIR)/examples/heart_rate_monitor/CMakeLists.txt -DBOOST_LIBRARYDIR=$(BUILD_DIR)/$(PKG_BOOST_NAME)/ipkg-install/lib

	AR="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ar" \
	AS="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC) -c $(TARGET_CFLAGS)" \
	LD="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ld" \
	NM="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)nm" \
	CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
	GCC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
	CXX="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)g++" \
	RANLIB="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)ranlib" \
	STRIP="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)strip" \
	OBJCOPY="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)objcopy" \
	OBJDUMP="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)objdump" \
	TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
	TARGET_CFLAGS="$(TARGET_CFLAGS)" \
	TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
	STAGING_DIR="$(STAGING_DIR)" \
	BUILD_DIR="$(PKG_BUILD_DIR)" \
	cmake $(PKG_BUILD_DIR)/examples/heart_rate_collector/CMakeLists.txt -DBOOST_LIBRARYDIR=$(BUILD_DIR)/$(PKG_BOOST_NAME)/ipkg-install/lib
endef

define Build/InstallDev
	$(INSTALL_DIR) $(STAGING_DIR)/usr/include/libpc-ble-driver-v5
	$(CP) $(PKG_BUILD_DIR)/libpc-ble-driver-v5/* $(STAGING_DIR)/usr/include/libpc-ble-driver-v5/
	$(INSTALL_DIR) $(STAGING_DIR)/usr/lib
	$(CP) $(PKG_BUILD_DIR)/libpc_ble_driver_shared_sd_api_* $(STAGING_DIR)/usr/lib/
endef

define Build/UninstallDev
	rm -rf \
	$(STAGING_DIR)/usr/include/libpc-ble-driver-v5 \
	$(STAGING_DIR)/usr/lib/libpc_ble_driver_shared_sd_api_*
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR)
	$(MAKE) -C $(PKG_BUILD_DIR)/examples/heart_rate_monitor
	$(MAKE) -C $(PKG_BUILD_DIR)/examples/heart_rate_collector
endef

define Package/libpc-ble-driver-v5/install
	$(INSTALL_DIR) $(1)/usr/lib
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libpc_ble_driver_shared_sd_api_v2.so $(1)/usr/lib/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/libpc_ble_driver_shared_sd_api_v5.so $(1)/usr/lib/
endef

define Package/pc-ble-driver-v5-tools/install
	$(INSTALL_DIR) $(1)/usr/bin
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/examples/heart_rate_monitor/hrm_v2 $(1)/usr/bin
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/examples/heart_rate_monitor/hrm_v5 $(1)/usr/bin
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/examples/heart_rate_collector/hrc_v2 $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/examples/heart_rate_collector/hrc_v5 $(1)/usr/bin
endef


$(eval $(call BuildPackage,libpc-ble-driver-v5))
$(eval $(call BuildPackage,pc-ble-driver-v5-tools))

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR)
	$(MAKE) -C $(PKG_BUILD_DIR)/examples/heart_rate_monitor
	$(MAKE) -C $(PKG_BUILD_DIR)/examples/heart_rate_collector
endef

Add the VERBOSE=1 flag here to each $(MAKE) invocation.

Rebuild and it should reveal the link command. From there hopefully we will know for sure whether the library search path is correct and -lcurl is present.

As for the CMakeLists.txt, I do not see any mention of curl there. You will need to figure that out :wink:

Hey Yousong,

I did as about. I did not see -lcurl anywhere.

define Build/Compile
	$(MAKE) -C $(MAKE_FLAGS) $(PKG_BUILD_DIR)
	$(MAKE) -C $(MAKE_FLAGS)  $(PKG_BUILD_DIR)/examples/heart_rate_monitor
	$(MAKE) -C $(MAKE_FLAGS)  $(PKG_BUILD_DIR)/examples/heart_rate_collector
endef
compilation ends with error and some more details of command

make -C  AR="xxxx" ...

There should be something between -C and AR=. Have you touched something else between your first post and this one?

Yeah, I believe I edited the Makefile $(MAKE) wrongly.

I changed it to

    $(MAKE)  $(MAKE_FLAGS) -C $(PKG_BUILD_DIR)
    $(MAKE) $(MAKE_FLAGS) -C $(PKG_BUILD_DIR)/examples/heart_rate_monitor
    $(MAKE) $(MAKE_FLAGS) -C $(PKG_BUILD_DIR)/examples/heart_rate_collector

after all that now I get same undefined error but some details on command

Looks like it's not just libcurl, possibly libssl and libcrypto from openssl are also part of this. You will need to edit CMakeLists.txt files to let it know that the target program depends on these libraries.

Yes, I have selected OpenSSL inside libcurl config in menuconfig.

I have no idea of cMakelists.txt that's the problem. If I had so much of knowledge I would have done it by now :smiley:
I worked out to find a solution to my problem from yesterday but could not work out.
I have a timeline of Wednesday to finish implementing few https APIs. I have a workaround of calling python3 from C. I have noticed python3 is too slow on the hardware and openwrt. even after precompiling python modules.

I found the location of libcurl and openssl

find_package ( libcurl )
did no help

I added the following lines in the CMakelists.txt and that removed the undefined error for libcurl.
But still with openSSL though openSSL is also in the same path.
I also tried -lopenssl or find_package( openssl ) but that gave some strange errors related to BOOST.

getting undefined for some openSSL

Hey @yousong

I got it all compiling added -lcurl -lssl -lcrypto to CMakelists.txt


SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $ENV{TARGET_LDFLAGS} -L$ENV{BUILD_DIR} -Wl,--rpath-link,$ENV{STAGING_DIR}/lib -lcurl -lssl -lcrypto")
1 Like