[OpenWrt-Devel] Can't link to ubus / ubox from C++ package
Tomer Eliyahu
tomereliyahu1 at gmail.com
Wed Jul 22 07:34:23 EDT 2015
Hi,
Sorry if I am repeating this question (I posted it in the developers
forum and stackoverflow), but I am out of luck for 3 days now and come
to think it might be an openwrt bug, forgive me if i'm mistaken..
I am writing a GUI for openwrt which uses UBUS to get indications for
system status.
For some reason, I can't get it to compile with ubus / ubox - I keep
getting the same error:
[color=#FF0000]/local/store/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_uClibc-0.9.33.2_eabi/ilixi_mgui-source/src/UBusThread.cpp:11:
undefined reference to `uloop_init()'[/color]
It is the same for other ubus API. I'm quite new to CPP, but linking
to other C libraries works perfectly, for examlpe blobmsg_get_u32().
BTW - I used both CMAKE and Autotools (configure), both tools produced
the same error when trying to call ubus/ubox functions.
Any thoughts?
[b]UBusThread.h:[/b]
[code]
#ifndef SRC_UBUSTHREAD_H_
#define SRC_UBUSTHREAD_H_
#include <lib/Thread.h>
#include <libubox/ustream.h>
#include <libubus.h>
#include "StatusBar.h"
namespace MGUI
{
class UBusThread : public ilixi::Thread
{
public:
UBusThread(StatusBar* target);
virtual
~UBusThread();
virtual int
run();
private:
StatusBar* _bar;
ubus_context* _ubus;
};
} /* namespace MGUI */
#endif /* SRC_UBUSTHREAD_H_ */
[/code]
[b]UBusThread.cpp:[/b]
[code]
#include "UBusThread.h"
namespace MGUI
{
UBusThread::UBusThread(StatusBar* bar)
: Thread(),
_bar(bar)
{
char buf[10];
uloop_init();
}
UBusThread::~UBusThread()
{
}
} /* namespace MGUI */
[/code]
[b]mgui/CMakeLists.txt:[/b]
[code]
#
# mgui (marvell gui) project cmake
###################################
cmake_minimum_required(VERSION 2.6)
PROJECT(MGUI)
ADD_DEFINITIONS(-Os -ggdb -Wall -Werror -Wmissing-declarations
-DMARVELL_EXTENDED)
# define resource files target install
SET(MGUI_DATADIR ${CMAKE_INSTALL_PREFIX}/share/ilixi-1.0.0)
ADD_DEFINITIONS(-DDATADIR="${MGUI_DATADIR}")
SET_DIRECTORY_PROPERTIES(PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES
"Makefile;ipkg-install;ipkg-pxa1826;Makefile;CMakeCache.txt;CMakeFiles;cmake_install.cmake;install_manifest.txt;")
# find necessary libraries
INCLUDE(CheckLibraryExists)
find_library(json NAMES json-c json)
LIST(APPEND LIBS ubox ubus uci ${json} blobmsg_json)
find_library(librt NAMES rt librt)
LIST(APPEND LIBS ${librt})
# find ilixi-1.0.0
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(ILIXI REQUIRED ilixi>=1.0.0)
ADD_DEFINITIONS(${ILIXI_CFLAGS})
LIST(APPEND LIBS ${ILIXI_LIBRARIES})
CONFIGURE_FILE(config.h.in config.h @ONLY)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(data)
[/code]
[b]src/CMakeLists.txt[/b]
[code]
# define sources and linked libraries
SET(SOURCES
main.cpp
MGuiPlatform.h
BatteryIcon.cpp
BatteryIcon.h
BottomBar.cpp
BottomBar.h
BTIcon.cpp
BTIcon.h
CellularIcon.cpp
CellularIcon.h
GPSIcon.cpp
GPSIcon.h
MGuiApplication.cpp
MGuiApplication.h
SDCardIcon.cpp
SDCardIcon.h
SimIcon.cpp
SimIcon.h
SimpleIcon.cpp
SimpleIcon.h
StatusBar.cpp
StatusBar.h
UBusThread.cpp
UBusThread.h
WiFiIcon.cpp
WiFiIcon.h
)
# create and install executable
ADD_EXECUTABLE(mgui ${SOURCES})
TARGET_LINK_LIBRARIES(mgui ${LIBS})
INSTALL(TARGETS mgui RUNTIME DESTINATION bin)
[/code]
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list