0

I'm trying to build libiconv as a static library for a Cortex M4 using the GNU ARM Toolchain and it seems the process is mostly successful.

I configure libiconv thus:

./configure --build=x86_64-linux-gnu --host=arm-none-eabi --prefix=/home/josaphat/Downloads/libiconv-1.14/build_dir CFLAGS="-nostdlib -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mfloat-abi=hard" --enable-static

Configure doesn't show any warnings or errors that I can discern other than "WARNING: using cross tools not prefixed with host triplet" (but it finds and uses the correct compiler just fine so I figure I can safely ignore this).

The errors come when compiling sigprogmask.c:

[... snip ...]

arm-none-eabi-gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I.. -I../lib  -I../intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1   -nostdlib -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mfloat-abi=hard -c sigprocmask.c
In file included from /usr/local/gcc-arm-none-eabi-4_8-2014q2/arm-none-eabi/include/signal.h:5:0,
                 from ./signal.h:52,
                 from sigprocmask.c:44:
./signal.h:490:1: error: expected identifier or '(' before 'const'
 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
 ^
./signal.h:490:1: error: expected ')' before '&' token
 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
 ^
./signal.h:490:1: error: expected ')' before '!=' token
 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
 ^
./signal.h:503:1: error: expected ')' before '*' token
 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
 ^
./signal.h:503:1: error: expected ')' before '=' token
 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
 ^
./signal.h:515:1: error: expected ')' before '*' token
 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
 ^
./signal.h:515:1: error: expected ')' before '|=' token
 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
 ^
./signal.h:528:1: error: expected ')' before '*' token
 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
 ^
./signal.h:528:1: error: expected ')' before '&=' token
 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
 ^
./signal.h:541:1: error: expected ')' before '*' token
 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
 ^
./signal.h:541:1: error: expected ')' before '=' token
 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
 ^
sigprocmask.c:87:14: error: expected identifier or '(' before 'const'
 sigismember (const sigset_t *set, int sig)
              ^
sigprocmask.c:87:1: error: expected ')' before '&' token
 sigismember (const sigset_t *set, int sig)
 ^
sigprocmask.c:87:1: error: expected ')' before '!=' token
 sigismember (const sigset_t *set, int sig)
 ^
sigprocmask.c:103:23: error: expected ')' before '*' token
 sigemptyset (sigset_t *set)
                       ^
sigprocmask.c:103:1: error: expected ')' before '=' token
 sigemptyset (sigset_t *set)
 ^
sigprocmask.c:110:21: error: expected ')' before '*' token
 sigaddset (sigset_t *set, int sig)
                     ^
sigprocmask.c:110:1: error: expected ')' before '|=' token
 sigaddset (sigset_t *set, int sig)
 ^
sigprocmask.c:130:21: error: expected ')' before '*' token
 sigdelset (sigset_t *set, int sig)
                     ^
sigprocmask.c:130:1: error: expected ')' before '&=' token
 sigdelset (sigset_t *set, int sig)
 ^
sigprocmask.c:151:22: error: expected ')' before '*' token
 sigfillset (sigset_t *set)
                      ^
sigprocmask.c:151:1: error: expected ')' before '=' token
 sigfillset (sigset_t *set)
 ^
make[2]: *** [sigprocmask.o] Error 1

[... etc....]

I'm at a loss here. I tried omitting the "nostdlib" flag but then the configure step fails because the compiler can't find _exit (I'm building for a target without an OS so that makes sense). So then, what am I missing? Does libiconv depend on something that -nostdlib removes? If so then how does that explain the fact that these are apparently syntax errors?

So I guess my question boils down to: Is it even possible to build libiconv for a system without an OS? And if so, how do I overcome this current obstacle?

josaphatv
  • 633
  • 4
  • 19
  • why your build option is using x86-64 while you want to compile to arm? i think it relates to macro definition. you need to config your compile option correctly. – Jason Hu Aug 27 '14 at 17:12
  • Because I'm building on an x86_64 Ubuntu computer for a Cortex M4. It definitely relates to the macro definition because that's the part that's failing. Could you be more specific about what "correctly" means? – josaphatv Aug 27 '14 at 18:07
  • is that what build means? maybe you should read the documentation, but in my comprehension, build option should be the target architecture. i am wondering if a documentation introduce you how to do it step by step. – Jason Hu Aug 27 '14 at 18:10
  • Yes. http://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html – josaphatv Aug 27 '14 at 18:16
  • That looks like signal handling code (which is very much OS-dependant) - is this file part of the _libiconv_ library itself, or the _iconv_ program that appears to also be part of the package? – Notlikethat Aug 29 '14 at 22:26
  • It's in the "srclib" directory of the source code package. I don't know enough about how the program works to know whether or not it's part of libiconv or iconv. I do know that all of those files are automatically generated (so I can't just go in and directly fix the source code to work for me). – josaphatv Sep 02 '14 at 16:45

1 Answers1

-1

I stumbled into the same problem. I did not find a clean way for configuration but managed to compile the library with

1) editing the scrlib/signals.h and changing the definitions before the errors 0->1 like:

/* Test whether a given signal is contained in a signal set.  */
# if 1
/* This function is defined as a macro on MacOS X.  */

Most likely commenting out these parts in signal.h will work as well.

2) commenting out the functions in scrlib/sigprocmask.c

These are needed for the command line tool, the library compiles OK without these.