OpenWrt Forum Archive

Topic: Need a little help compiling a program

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,

I'm stuck on compiling a small program. Due to my bad knowledge of C I'm struggling half a week with the folling error:

-----------------------------------------------------------------------------------------------------------------------------
/home/hinschj/Openwrt/trunk/build_mipsel/smusbutil/smusbutil.c: In function `main':
/home/hinschj/Openwrt/trunk/build_mipsel/smusbutil/smusbutil.c:35: error: storage size of 'ftdic' isn't known
make[2]: *** [/home/hinschj/Openwrt/trunk/build_mipsel/smusbutil/.built] Error 1

-----------------------------------------------------------------------------------------------------------------------------

The program itself I like to get compiled for mips on kamikaze is called smusbutil which should give you the option to select frequency on a so called smartmouse from wb-electronics.

Code:

/*******************************************************************************
*
* smusbutil : A simple configuration utility for the WB Electronics
*             Smartmouse USB Phoenix Smartmouse interface.
*
* WB Electronics Homepage: http://www.wbe.dk
*
* History :
*   Version 1.0 - Initial release.
*
* Carsten Sprung <carsten@carsten-sprung.de>
* Many thanks to Martin <martin@wbe.dk> for providing the necessary infos.
*
*******************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <usb.h>
#include <ftdi.h>


static void print_usage(void)
{
  fprintf(stderr, "Usage: smusbutil clockrate mode\n\n");
  fprintf(stderr, "  <3580 | 3680 | 6000>     Set smartcard clock in kHz\n");
  fprintf(stderr, "  <phoenix | smartmouse>   Set operation mode\n");
  fprintf(stderr, "\n");
  fprintf(stderr, "  Note: When you get a -5 error, make sure the kernel ftdi_sio driver is unloaded.\n  You will need root privileges!\n\n");
}


int main(int argc, char *argv[])
{
  struct ftdi_context ftdic;
  int f,i,e;
  char buf[1];
  buf[0] = 0;
  e = 0;
  char frq, opmode;

  if (argc != 3)
  {
    print_usage();
    exit(-1);
  }

  switch(atoi(argv[1]))  {
    case 3580:                     //3,58 = 10 = 2
      frq = 2;
      break;
    case 3680:                     //3,68 = 11 = 3
      frq = 3;
      break;
    case 6000:                     //6,00 = 01 = 1
      frq = 1;
      break;
    default:
       print_usage();
       exit(-1);
  }

  buf[0] |= frq<<4;

  if(strcmp(argv[2], "smartmouse") == 0)  {
    buf[0] |= 1<<6;
    e = 1;
  }

  if(strcmp(argv[2], "phoenix") == 0)  {
    e = 1;
  }

  if(!e)  {
    print_usage();
    exit(-1);
  }

  ftdi_init(&ftdic);

  f = ftdi_usb_open(&ftdic, 0x104f, 0x0002);
  if(f < 0 && f != -5) {
    fprintf(stderr, "can't find any Smartmouse USB (VID:0x104f/PID:0x0002): %d\n",f);
    exit(-1);
  }
  printf("Smartmouse USB found: %d\n",f);

  printf("enabling bitbang mode\n");
  ftdi_enable_bitbang(&ftdic, 0xFF);

  f = ftdi_write_data(&ftdic, buf, 1);
  if(f < 0) exit(-1);


  f = ftdi_write_data(&ftdic, buf, 1);
  if(f < 0) exit(-1);

  buf[0] |= 0x80; //RI

  f = ftdi_write_data(&ftdic, buf, 1);
  if(f < 0) exit(-1);

  printf("disabling bitbang mode\n");
  ftdi_disable_bitbang(&ftdic);

  ftdi_usb_close(&ftdic);
  ftdi_deinit(&ftdic);
}
---------------------------------------------------------------------------------------------------------------------------

I already replaced the include statements for usb.h and ftdi.h with full qualified pathnames and also replaced the ftdi_sio.h and ftdi_sio.c in the build_mipsel subdir with the one provied with this program.

Maybe one of you all with much better knowledge can help me / give a hint what to do with this error...?

Thanks in advance

Joachim

PS: The Makefile seems to work...I copied and modified it from the io-package...

it errors right off trying to declare <struct ftdi_context ftdic;>
how are you compiling it? i'm guessing it either can't find the header file (.h) containing the ftdi_context structure, or it needs a library.

Hi,

I realized that there is also a libftdi, but it's quite more to be compiled and comes with a standard Makefile...so, I don't know if or how to get the lib compiled right now. But as you said, that seems to be the missing part. First I thought it was searching for some functions or the declarations where bad inside the ftdi_sio, but then I found the libftdi-0.9xxx

So I will give it a try to get it a Makefile for OpenWrt, but I assume I would like to ask for some more help...

Thanks so far!

Best regards

Joachim

Yes, the libftdi package is missing for OpenWrt. I've patches for libftdi and smusbutils. smusbutils still doesn't compile. See log below.

adds libftdi package:

Index: feeds/packages/libs/libftdi/Makefile
===================================================================
--- feeds/packages/libs/libftdi/Makefile        (revision 0)
+++ feeds/packages/libs/libftdi/Makefile        (revision 0)
@@ -0,0 +1,69 @@
+#
+# Copyright (C) 2006 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# $Id$
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=libftdi
+PKG_VERSION:=0.9
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=http://www.intra2net.com/de/produkte/opensource/ftdi/TGZ/
+PKG_MD5SUM:=6b1bf276ba8d623332083477f91deefd
+PKG_CAT:=zcat
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/libftdi
+  SECTION:=libs
+  CATEGORY:=Libraries
+  DEPENDS:=+libusb
+  TITLE:=Library to control and program the FTDI USB controller
+  URL:=http://www.intra2net.com/de/produkte/opensource/ftdi/
+endef
+
+# uses GNU configure
+
+define Build/Compile
+       $(MAKE) -C $(PKG_BUILD_DIR) \
+               $(TARGET_CONFIGURE_OPTS) \
+               OFLAGS="$(TARGET_CFLAGS)" \
+               DESTDIR="$(PKG_INSTALL_DIR)" \
+               install
+endef
+
+define Build/InstallDev
+       mkdir -p $(STAGING_DIR)/usr/include/
+       $(CP) $(PKG_INSTALL_DIR)/usr/include/ftdi.h $(STAGING_DIR)/usr/include/
+       mkdir -p $(STAGING_DIR)/usr/lib/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libftdi.{a,so*} $(STAGING_DIR)/usr/lib/
+       mkdir -p $(STAGING_DIR)/usr/bin/
+       $(CP) $(PKG_INSTALL_DIR)/usr/bin/libftdi-config $(STAGING_DIR)/usr/bin/
+       mkdir -p $(STAGING_DIR)/usr/lib/pkgconfig
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libftdi.pc \
+               $(STAGING_DIR)/usr/lib/pkgconfig
+endef
+
+define Build/UninstallDev
+       rm -rf \
+               $(STAGING_DIR)/usr/include/ftdi.h \
+               $(STAGING_DIR)/usr/lib/libftdi.{a,so*} \
+               $(STAGING_DIR)/usr/bin/libftdi-config \
+               $(STAGING_DIR)/usr/lib/pkgconfig/libftdi.pc
+endef
+
+define Package/libftdi/install
+       $(INSTALL_DIR) $(1)/usr/lib/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libftdi.so.* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,libftdi))
+

adds smusbutil package:

Index: feeds/packages/utils/smusbutil/src/smusbutil.c
===================================================================
--- feeds/packages/utils/smusbutil/src/smusbutil.c      (revision 0)
+++ feeds/packages/utils/smusbutil/src/smusbutil.c      (revision 0)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+*
+* smusbutil : A simple configuration utility for the WB Electronics
+*             Smartmouse USB Phoenix Smartmouse interface.
+*
+* WB Electronics Homepage: http://www.wbe.dk
+*
+* History :
+*   Version 1.0 - Initial release.
+*
+* Carsten Sprung <carsten@carsten-sprung.de>
+* Many thanks to Martin <martin@wbe.dk> for providing the necessary infos.
+*
+*******************************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <usb.h>
+#include <ftdi.h>
+
+
+static void print_usage(void)
+{
+  fprintf(stderr, "Usage: smusbutil clockrate mode\n\n");
+  fprintf(stderr, "  <3580 | 3680 | 6000>     Set smartcard clock in kHz\n");
+  fprintf(stderr, "  <phoenix | smartmouse>   Set operation mode\n");
+  fprintf(stderr, "\n");
+  fprintf(stderr, "  Note: When you get a -5 error, make sure the kernel ftdi_sio
+driver is unloaded.\n  You will need root privileges!\n\n");
+}
+
+
+int main(int argc, char *argv[])
+{
+  struct ftdi_context ftdic;
+  int f,i,e;
+  char buf[1];
+  buf[0] = 0;
+  e = 0;
+  char frq, opmode;
+
+  if (argc != 3)
+  {
+    print_usage();
+    exit(-1);
+  }
+
+  switch(atoi(argv[1]))  {
+    case 3580:                     //3,58 = 10 = 2
+      frq = 2;
+      break;
+    case 3680:                     //3,68 = 11 = 3
+      frq = 3;
+      break;
+    case 6000:                     //6,00 = 01 = 1
+      frq = 1;
+      break;
+    default:
+       print_usage();
+       exit(-1);
+  }
+
+  buf[0] |= frq<<4;
+
+  if(strcmp(argv[2], "smartmouse") == 0)  {
+    buf[0] |= 1<<6;
+    e = 1;
+  }
+
+  if(strcmp(argv[2], "phoenix") == 0)  {
+    e = 1;
+  }
+
+  if(!e)  {
+    print_usage();
+    exit(-1);
+  }
+
+  ftdi_init(&ftdic);
+
+  f = ftdi_usb_open(&ftdic, 0x104f, 0x0002);
+  if(f < 0 && f != -5) {
+    fprintf(stderr, "can't find any Smartmouse USB (VID:0x104f/PID:0x0002): %d\n",f);
+    exit(-1);
+  }
+  printf("Smartmouse USB found: %d\n",f);
+
+  printf("enabling bitbang mode\n");
+  ftdi_enable_bitbang(&ftdic, 0xFF);
+
+  f = ftdi_write_data(&ftdic, buf, 1);
+  if(f < 0) exit(-1);
+
+
+  f = ftdi_write_data(&ftdic, buf, 1);
+  if(f < 0) exit(-1);
+
+  buf[0] |= 0x80; //RI
+
+  f = ftdi_write_data(&ftdic, buf, 1);
+  if(f < 0) exit(-1);
+
+  printf("disabling bitbang mode\n");
+  ftdi_disable_bitbang(&ftdic);
+
+  ftdi_usb_close(&ftdic);
+  ftdi_deinit(&ftdic);
+}
+
Index: feeds/packages/utils/smusbutil/Makefile
===================================================================
--- feeds/packages/utils/smusbutil/Makefile     (revision 0)
+++ feeds/packages/utils/smusbutil/Makefile     (revision 0)
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2007 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# $Id: $
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=smusbutil
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/smusbutil
+  SECTION:=utils
+  CATEGORY:=Utilities
+  DEPENDS:=libftdi
+  TITLE:=smusbutil
+  DESCRIPTION:=\
+       A simple configuration utility for the WB Electronics \\\
+       Smartmouse USB Phoenix Smartmouse interface.
+  URL:=http://www.wbe.dk/
+endef
+
+define Build/Prepare
+       mkdir -p $(PKG_BUILD_DIR)
+       $(CP) ./src/* $(PKG_BUILD_DIR)/
+endef
+
+define Build/Compile
+       $(TARGET_CC) $(TARGET_CFLAGS) -Os $(PKG_BUILD_DIR)/smusbutil.c \
+               -o $(PKG_BUILD_DIR)/$(PKG_NAME) -I$(STAGING_DIR)/usr/include/
+endef
+
+define Package/smusbutil/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       # $(INSTALL_BIN) $(PKG_BUILD_DIR)/io $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,smusbutil))

make package/smusbutil-{clean,compile} V=99

ubuntu@OpenWrt-DevEnv:~/atheros-2.6$ make package/smusbutil-{clean,compile} V=99
make -C package smusbutil-clean
make[1]: Entering directory `/home/ubuntu/atheros-2.6/package'
make -C smusbutil clean
make[2]: Entering directory `/home/ubuntu/atheros-2.6/feeds/packages/utils/smusbutil'
rm -f /home/ubuntu/atheros-2.6/bin/packages/smusbutil_*
make[2]: Leaving directory `/home/ubuntu/atheros-2.6/feeds/packages/utils/smusbutil'
make[1]: Leaving directory `/home/ubuntu/atheros-2.6/package'
make -C package smusbutil-compile
make[1]: Entering directory `/home/ubuntu/atheros-2.6/package'
make -C smusbutil compile
find: /home/ubuntu/atheros-2.6/build_mips/smusbutil: No such file or directory
make[2]: Entering directory `/home/ubuntu/atheros-2.6/feeds/packages/utils/smusbutil'
mkdir -p /home/ubuntu/atheros-2.6/build_mips/smusbutil
cp -fpR ./src/* /home/ubuntu/atheros-2.6/build_mips/smusbutil/
touch /home/ubuntu/atheros-2.6/build_mips/smusbutil/.prepared
(cd /home/ubuntu/atheros-2.6/build_mips/smusbutil/./; if [ -x ./configure ]; then AR=mips-linux-uclibc-ar AS="mips-linux-uclibc-gcc -c -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time" LD=mips-linux-uclibc-ld NM=mips-linux-uclibc-nm CC="mips-linux-uclibc-gcc" GCC="mips-linux-uclibc-gcc" CXX=mips-linux-uclibc-g++ RANLIB=mips-linux-uclibc-ranlib STRIP=mips-linux-uclibc-strip OBJCOPY=mips-linux-uclibc-objcopy OBJDUMP=mips-linux-uclibc-objdump CFLAGS="-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -I/home/ubuntu/atheros-2.6/staging_dir_mips/usr/include -I/home/ubuntu/atheros-2.6/staging_dir_mips/include" CXXFLAGS="-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -I/home/ubuntu/atheros-2.6/staging_dir_mips/usr/include -I/home/ubuntu/atheros-2.6/staging_dir_mips/include" CPPFLAGS="-I/home/ubuntu/atheros-2.6/staging_dir_mips/usr/include -I/home/ubuntu/atheros-2.6/staging_dir_mips/include -I/home/ubuntu/atheros-2.6/staging_dir_mips/usr/include -I/home/ubuntu/atheros-2.6/staging_dir_mips/include" LDFLAGS="-L/home/ubuntu/atheros-2.6/staging_dir_mips/usr/lib -L/home/ubuntu/atheros-2.6/staging_dir_mips/lib" PKG_CONFIG_PATH="/home/ubuntu/atheros-2.6/staging_dir_mips/usr/lib/pkgconfig" PKG_CONFIG_LIBDIR="/home/ubuntu/atheros-2.6/staging_dir_mips/usr/lib/pkgconfig"  ./configure --target=mips-linux --host=mips-linux --build=i486-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls ; fi; )
touch /home/ubuntu/atheros-2.6/build_mips/smusbutil/.configured
mips-linux-uclibc-gcc -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -Os /home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c -o /home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil -I/home/ubuntu/atheros-2.6/staging_dir_mips/usr/include/
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c: In function 'print_usage':
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:29: error: missing terminating " character
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: 'driver' undeclared (first use in this function)
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: (Each undeclared identifier is reported only once
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: for each function it appears in.)
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: expected ')' before 'is'
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: stray '\' in program
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: stray '\' in program
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: stray '\' in program
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:30: error: missing terminating " character
/home/ubuntu/atheros-2.6/build_mips/smusbutil/smusbutil.c:31: error: expected ';' before '}' token
make[2]: *** [/home/ubuntu/atheros-2.6/build_mips/smusbutil/.built] Error 1
make[2]: Leaving directory `/home/ubuntu/atheros-2.6/feeds/packages/utils/smusbutil'
make[1]: *** [smusbutil-compile] Error 2
make[1]: Leaving directory `/home/ubuntu/atheros-2.6/package'
make: *** [package/smusbutil-compile] Error 2
ubuntu@OpenWrt-DevEnv:~/atheros-2.6$

(Last edited by forum2006 on 23 Apr 2007, 00:04)

Hi forum2006,

thanks for providing the scripts. I tried out to compile them also and get strange errors from the Makefile: stating that there is a "separator missing" at
--------------------------------
define Package/libftdi/install
--------------------------------

line 63...(?) I triple checked everything but can't find a problem with that statement. But I believe we get closer to a working smusbutil (hopefully...).

Regards

Joachim

Update: I found the problem! Just copied and pasted the Makefile for libftdi from here, so I needed to replace the spaces with tabs...

But it's still not completely compiling, now it complains about this:

....
/usr/lib/libusb.so  -Wl,-soname -Wl,libftdi.so.0 -o .libs/libftdi.so.0.9.0
/usr/lib/libusb.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[4]: *** [libftdi.la] Error 1
....

Any ideas where to look at?

Regards

Joachim

(Last edited by jhinsch on 25 Apr 2007, 18:03)

The discussion might have continued from here.