Discussion:
[rrd-users] cross-compiling: cannot find -lrrd
(too old to reply)
Sergey Kopylov
2015-02-08 14:30:06 UTC
Permalink
Hello!
I am trying to cross-compile my test program for the OpenWRT
attitude-adjustment 12.09 (router D-Link DIR-320 hw.B1). But at the end of
compiling I have an error:
"/home/sergey/openwrt/attitude_adjustment/staging_dir/toolchain-mipsel_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld:
cannot find -lrrd"

What is the reason of this error? I tryied to find the library:
***@debian:/# find /home/sergey/openwrt/attitude_adjustment/ -name
librrd.so*
/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/root-ramips/usr/lib/librrd.so.2
/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/root-ramips/usr/lib/librrd.so.2.0.15
/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/rrdtool-1.2/lib/librrd.so.2
/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/rrdtool-1.2/lib/librrd.so
/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/rrdtool-1.2/lib/librrd.so.2.0.15

This library is installed. (For OpenWRT actual version of rrdtool -
1.2.30-3).

My test program: mbrrd.c
#include <string.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>

#include "rrd.h" // Положить файл rrd.h рядом с mbrrd.c

#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

int main (int argc,char** argv)
{
int i=rrd_update(argc,argv);
return 0;
}

I putted the rrd.h file together with mbrrd.c in a folder /src

My Makefile:
#======================================
# OpenWrt Makefile for mbrrd programm
#======================================

include $(TOPDIR)/rules.mk

PKG_NAME:=mbrrd
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

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

include $(INCLUDE_DIR)/package.mk


define Package/mbrrd
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+librrd
#+librrd
TITLE:=Gatawey-server Modbus RTU to RRD for Arduino
endef

define Package/mbrrd/description
Gatawey-server Modbus RTU to RRD for Arduino
endef

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef


define Build/Compile
$(TARGET_CC) $(TARGET_CFLAGS) -c -o $(PKG_BUILD_DIR)/mbrrd.o
$(PKG_BUILD_DIR)/mbrrd.c
$(TARGET_CC) $(TARGET_LDFLAGS) -lrrd -o $(PKG_BUILD_DIR)/mbrrd
$(PKG_BUILD_DIR)/mbrrd.o
endef

TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include/modbus
-I$(STAGING_DIR)/usr/lib -I$(STAGING_DIR)/usr/lib/rrdtool-1.2/lib/

define Package/mbrrd/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mbrrd $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,mbrrd))


Can you help me, please?



--
View this message in context: http://rrd-mailinglists.937164.n2.nabble.com/cross-compiling-cannot-find-lrrd-tp7582841.html
Sent from the RRDtool Users Mailinglist mailing list archive at Nabble.com.
Steve Shipway
2015-02-08 20:38:05 UTC
Permalink
Post by Sergey Kopylov
"/home/sergey/openwrt/attitude_adjustment/staging_dir/toolchain-
mipsel_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-
cannot find -lrrd"
I'm guessing you need to update your LD_LIBRARY_PATH to include the location
of the librrd.so.2 file. Possibly you've moved it from its compiled location,
or have chrooted? In any case, the loader can't find it. Set LD_LIBRARY_PATH
to include the correct path for it, or add the path to /etc/ld.so.conf or a
file in /etc/ld.so.d (these last 2 may be Linux-specific)

Steve

Steve Shipway
***@auckland.ac.nz
Sergey Kopylov
2015-02-09 20:17:02 UTC
Permalink
I tried to update my LD_LIBRARY_PATH:
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/root-ramips/usr/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/rrdtool-1.2/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/rrdtool-1.2.30/ipkg-install/usr/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/rrdtool-1.2.30/src/.libs

But it did not help me. May be there is 2 different LD_LIBRARY_PATH - one
for Debian, second - for openwrt? I am not familiar with compiling and
especially with cross-compilation.

I tried also put the folder 'lib' with these libraries to the folder 'src'
of my test program and include next row to my Makefile:
TARGET_LDFLAGS += -I./src/lib
But it did not help me also.

Anyway - thanks a lot for your answer!



--
View this message in context: http://rrd-mailinglists.937164.n2.nabble.com/cross-compiling-cannot-find-lrrd-tp7582841p7582843.html
Sent from the RRDtool Users Mailinglist mailing list archive at Nabble.com.
Dagobert Michelsen
2015-02-09 20:26:08 UTC
Permalink
Hi Sergey,
Post by Sergey Kopylov
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/root-ramips/usr/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/rrdtool-1.2/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/rrdtool-1.2.30/ipkg-install/usr/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sergey/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/rrdtool-1.2.30/src/.libs
But it did not help me. May be there is 2 different LD_LIBRARY_PATH - one
for Debian, second - for openwrt? I am not familiar with compiling and
especially with cross-compilation.
LD_LIBRARY_PATH will not help you when crosscompiling.
Post by Sergey Kopylov
I tried also put the folder 'lib' with these libraries to the folder 'src'
TARGET_LDFLAGS += -I./src/lib
-I is for includes, -L is for library pathes, try -L./src/lib


Best regards

— Dago
--
"You don't become great by trying to be great, you become great by wanting to do something,
and then doing it so hard that you become great in the process." - xkcd #896
Steve Shipway
2015-02-09 20:40:05 UTC
Permalink
Post by Dagobert Michelsen
LD_LIBRARY_PATH will not help you when crosscompiling.
Ah, yes, I should have read it more closely. I had thought that the problem
was in running the binary after compilation.
Post by Dagobert Michelsen
Post by Sergey Kopylov
I tried also put the folder 'lib' with these libraries to the folder 'src'
TARGET_LDFLAGS += -I./src/lib
-I is for includes, -L is for library pathes, try -L./src/lib
Yes, add the -L flag to the LDFLAGS with the location of the librrd files.
This should work, as you say. Cross-compilation is an awkward one, maybe try
to compile statically linked (rather than dynamically) as well? I think you
use something like "-Wl,-Bstatic" before the -l flag to achieve this.

Steve

Steve Shipway
***@auckland.ac.nz
Sergey Kopylov
2015-02-10 13:42:22 UTC
Permalink
Yes, using '-L' in TARGET_LDFLAGS - this is the right solution. I changed the
row in Makefile

from: TARGET_LDFLAGS += -I./src/lib -I$(STAGING_DIR)/usr/lib
-I$(STAGING_DIR)/usr/lib/rrdtool-1.2/lib

to: TARGET_LDFLAGS += -L./src/lib -L$(STAGING_DIR)/usr/lib
-L$(STAGING_DIR)/usr/lib/rrdtool-1.2/lib


and my test program was compiled without errors. I have instaled this
program on my router - and it work! Dago and Steve - Thank you very much!
Without you I could not solve this problem!



--
View this message in context: http://rrd-mailinglists.937164.n2.nabble.com/cross-compiling-cannot-find-lrrd-tp7582841p7582846.html
Sent from the RRDtool Users Mailinglist mailing list archive at Nabble.com.
Loading...