Cross compiling net-snmp for ARM - arm

Hi There
I am trying to cross compile the net-snmp agent (snmpd) for an ARM platform (my STB). I can successful compile the "--mini-agent" version, which isn't very useful (only knows about itself, not the system it runs on). I am a bit along the way (I guess), but I am stumbling over this error to do with libpcre, perhaps somebody can help me out. Here is what I do:
I am using the toolchain "arm-linux-gnueabihf" (I am not even sure, this is the right terminology).
I am downloading net-snmp and running configure like so:
./configure \
--host=arm-linux-gnueabihf \
--target=arm-linux-gnueabihf \
--build=i686 \
--disable-manuals \
--disable-ipv6 \
--with-cc=arm-linux-gnueabihf-gcc \
--with-ar=arm-linux-gnueabihf-ar \
--without-rpm \
--disable-applications \
--disable-embedded-perl \
--disable-deprecated \
--disable-shared \
--enable-static LDFLAGS="-L/home/crayfish/openvuplus_3.0/build/vusolo4k/tmp/sysroots/vusolo4k/usr/lib/libpcre" \
--with-sysroot=/home/crayfish/openvuplus_3.0/build/vusolo4k/tmp/sysroots/vusolo4k/
/home/crayfish/openvuplus_3.0 is where the source code from the STB sits, and there is also the libpcre:
file /home/crayfish/openvuplus_3.0/build/vusolo4k/tmp/sysroots/vusolo4k/usr/lib/libpcre.so.1.2.4
/home/crayfish/openvuplus_3.0/build/vusolo4k/tmp/sysroots/vusolo4k/usr/lib/libpcre.so.1.2.4: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=335b7191beb073ea9f6567442c6269855f4053bc, not stripped
Now, most of this is guess work or trial and error by me, but the configure script runs fine (as far as I can see), but it throws me this error at make:
libtool: link: arm-linux-gnueabihf-gcc -fno-strict-aliasing -g -O2 -Ulinux -Dlinux=linux -Wall -Wstrict-prototypes -Wwrite-strings -Wcast-qual -o snmpd snmpd.o -L/home/crayfish/openvuplus_3.0/build/vusolo4k/tmp/sysroots/vusolo4k/usr/lib/libpcre ./.libs/libnetsnmpagent.a ./.libs/libnetsnmpmibs.a /home/crayfish/code/agent/.libs/libnetsnmpagent.a /home/crayfish/code/snmplib/.libs/libnetsnmp.a -ldl ../snmplib/.libs/libnetsnmp.a -lm
./.libs/libnetsnmpmibs.a(proc.o): In function `proc_parse_config':
/home/crayfish/code/agent/mibgroup/ucd-snmp/proc.c:232: undefined reference to `pcre_compile'
./.libs/libnetsnmpmibs.a(swrun.o): In function `swrun_count_processes_by_regex':
/home/crayfish/code/agent/mibgroup/host/data_access/swrun.c:134: undefined reference to `pcre_exec'
collect2: error: ld returned 1 exit status
make[1]: *** [snmpd] Fehler 1
make[1]: Verzeichnis »/home/crayfish/code/agent« wird verlassen
make: *** [subdirs] Fehler 1
As you might be able to see, I am trying to let the system know, where the libpcre sits, but - for the life of me - I cannot figure out what syntax to use.
So, any and every help would be highly appreciated!!!
Thomas

Related

Using gmake on Mac with CLion (with an ArchLinux makefile)

I am trying to use a make file that my professor provided, but that make file is made to work in an Arch Linux VM, and not my Mac environment. To solve this, I've downloaded gmake and gcc via homebrew, and swapped them out as the make and compiler targets in my CLion toolchain. However, when I try to build, I am still getting the error "ld: unknown option: -rpath=$ORIGIN". This is the line that is failing (line 10) everytime:
$(CC) $(CFLAGS) $(LDFLAGS) -DDEBUG=$(DEBUG) -L. -Wl,-rpath='$$ORIGIN' -driverfile myfile.c -o $#
Here is my output when I hit build:
====================[ Build | all ]=============================================
/usr/local/Cellar/make/4.3/bin/gmake --jobs=9 all
/usr/local/Cellar/gcc/11.2.0_3/bin/gcc-11 -Wall -g -DDEBUG=1 -L. -Wl, -rpath='$ORIGIN' -driverfile myfile.c -o myfile
ld: unknown option: -rpath=$ORIGIN
collect2: error: ld returned 1 exit status
gmake: *** [Makefile:10: myfile] Error 1
I am allowed to modify the makefile for testing purposes on my local machine, so long as all the stuff still works with the original makefile on the Arch Linux VM, and I'm happy to do this if it's the only solution, but I'd much rather figure out why its not working as is. (Even if the answer is 'Bc its a Mac and Apple says so.')

Building GCC Cross-Compiler on cygwin for PowerPC

I have been trying to build a GCC C language cross-compiler for Powerpc-eabi architecture using Cygwin on Windows 7 32bit.
Following the instructions on http://wiki.osdev.org/GCC_Cross-Compiler when I execute the command
make all-gcc
after a while, the following error is generated.
...
g++ -c-g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual
-Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long
-Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H
-DGENERATOR_FILE -I. -Ibuild -I../../gcc-5.4.0/gcc
-I../../gcc-5.4.0/gcc/build -I../../gcc-5.4.0/gcc/../include
-I../../gcc-5.4.0/gcc/../libcpp/include
-o build/genpreds.o ../../gcc-5.4.0/gcc/genpreds.c
In file included from ../../gcc-5.4.0/gcc/rtl.h:26:0,
from ../../gcc-5.4.0/gcc/genpreds.c:27:
../../gcc-5.4.0/gcc/real.h:43:35: warning: division by zero [-Wdiv-by-zero]
#define SIGSZ (SIGNIFICAND_BITS / HOST_BITS_PER_LONG)
^
../../gcc-5.4.0/gcc/real.h:56:21: note: in expansion of macro ‘SIGSZ’
unsigned long sig[SIGSZ];
^
../../gcc-5.4.0/gcc/real.h:56:26: error: size of array ‘sig’ is not an integral constant-expression
unsigned long sig[SIGSZ];
^
make[1]: *** [Makefile:2429: build/genpreds.o] Error 1
make[1]: Leaving directory '/home/user/build-gcc/gcc'
make: *** [Makefile:4100: all-gcc] Error 2
The cause of error seems to be the missing definition of HOST_BITS_PER_LONG in file rtl.h.
The configure command is
../gcc-5.4.0/configure --target=powerpc-eabi --prefix=/home/user/opt/cross --disable-nls --enable-languages=c --without-headers
I have binutils-2.26.
Gcc version 5.4.0 is the latest edition available from the Cygwin Package List.
I have also tried using gcc-6.1.0 getting the same error, plus other errors.
I think the configure command was not executed correctly.
Do you have an idea on how to resolve the problem, please?
[1]: http://wiki.osdev.org/GCC_Cross-Compiler

"error: conflicting types for ‘sem_t’" when compiling eglibc-2.19 on Ubuntu

I was trying to build eglibc-2.19 on Ubuntu 14.04 LTS which I downloaded through
apt-get source libc6
I followed the INSTALL instructions but got this error when it ran into nptl
gcc sem_init.c -c -std=gnu99 -fgnu89-inline -fno-stack-protector -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -g -Wstrict-prototypes -U_FORTIFY_SOURCE -I../include -I/home/gpanda/wksp/glibc/tmp2/glibc-build/nptl -I/home/gpanda/wksp/glibc/tmp2/glibc-build -I../sysdeps/unix/sysv/linux/x86_64/64/nptl -I../sysdeps/unix/sysv/linux/x86_64/64 -I../nptl/sysdeps/unix/sysv/linux/x86_64 -I../nptl/sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/wordsize-64 -I../nptl/sysdeps/unix/sysv/linux -I../nptl/sysdeps/pthread -I../libpthread/sysdeps/pthread -I../sysdeps/pthread -I../ports/sysdeps/unix/sysv/linux -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu -I../sysdeps/unix/inet -I../nptl/sysdeps/unix/sysv -I../ports/sysdeps/unix/sysv -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../nptl/sysdeps/unix -I../ports/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix -I../libpthread/sysdeps/posix -I../nptl/sysdeps/x86_64/64 -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../nptl/sysdeps/x86_64 -I../sysdeps/x86_64 -I../sysdeps/x86 -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64/wordsize-64 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I../libpthread/include -I../libpthread -I../nptl -I../ports -I.. -I../libio -I. -I../libpthread/include -D_LIBC_REENTRANT -include ../include/libc-symbols.h -DNOT_IN_libc=1 -DIS_IN_libpthread=1 -DIN_LIB=libpthread -o /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o -MD -MP -MF /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o.dt -MT /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o
In file included from sem_init.c:20:0:
../libpthread/include/semaphore.h:28:0: warning: "SEM_FAILED" redefined [enabled by default]
#define SEM_FAILED ((void *) 0)
^
In file included from ../libpthread/include/semaphore.h:26:0,
from sem_init.c:20:
../nptl/sysdeps/unix/sysv/linux/x86/bits/semaphore.h:33:0: note: this is the location of the previous definition
#define SEM_FAILED ((sem_t *) 0)
^
In file included from sem_init.c:20:0:
../libpthread/include/semaphore.h:30:28: error: conflicting types for ‘sem_t’
typedef struct __semaphore sem_t;
^
In file included from ../libpthread/include/semaphore.h:26:0,
from sem_init.c:20:
../nptl/sysdeps/unix/sysv/linux/x86/bits/semaphore.h:40:3: note: previous declaration of ‘sem_t’ was here
} sem_t;
^
make[2]: *** [/home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o] Error 1
make[2]: Leaving directory `/home/gpanda/wksp/glibc/tmp2/eglibc-2.19/nptl'
make[1]: *** [nptl/subdir_lib] Error 2
make[1]: Leaving directory `/home/gpanda/wksp/glibc/tmp2/eglibc-2.19'
make: *** [all] Error 2
Is this some kind of conflict between libpthread and nptl? How to fix this problem?
Thanks in advance.
Consider LinuxThreads has been superseded by NPTL, so I just removed the add-on libpthread from the eglibc directory, and re-did the configure and make, then everything seems to be ok now.
see LinuxThreads,NPTL
BTW, since I didn't use the standard /usr path as the "--prefix=" option for configure, so I need copy libstdc++.so.6 and libgcc_s.so.1 to my current build path to get "make check" pass.
see glibc Known_testsuite_failures
I got the same error because I ran a plain ./configure --prefix=/opt, so I ran apt-get source -b eglibc instead and I noted the configure flags it used:
(exec 3>&1; exit `( ( ( cd build-tree/i386-libc && CC="i686-linux-gnu-gcc-4.8" CXX="i686-linux-gnu-g++-4.8" AUTOCONF=false MAKEINFO=: /home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/configure --host=i686-linux-gnu --build=$configure_build --prefix=/usr --without-cvs --enable-add-ons=libidn,"nptl " --enable-profile --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --with-pkgversion="Ubuntu EGLIBC 2.19-0ubuntu6.9" --with-bugurl="https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs" --with-headers=/home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/debian/include --enable-kernel=2.6.24 --with-selinux --enable-multi-arch ) 2>&1 3>&-; echo $? >&4) | tee -a build-tree/log-build-i686-linux-gnu-libc >&3) 4>&1`)
The command is rather involved, more complex than usual for apt-get source, since glibc insists on being built from a separate directory. The actual configure flags are:
--host=i686-linux-gnu --build=$configure_build --prefix=/usr --without-cvs --enable-add-ons=libidn,"nptl " --enable-profile --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --with-pkgversion="Ubuntu EGLIBC 2.19-0ubuntu6.9" --with-bugurl="https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs" --with-headers=/home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/debian/include --enable-kernel=2.6.24 --with-selinux --enable-multi-arch
It works with those arguments of course, since that's what Ubuntu maintainers used to compile the package with.
I don't really know which of those flags prevents the error, but if you use that command, or the exact arguments provided by apt-get source -b eglibc on your Ubuntu system, it should work well enough.

Cross compiling OpenSSL - openssl binary cannot be executed

I'm trying to cross compile OpenSSL for PowerPC with the FIPS module. My build host's architecture is not PowerPC. I was able to cross compile the FIPS module just fine. However, when I run make on openssl, during the linking phase, it tries to execute certain binaries to run tests. The issue is that those binaries are produced for the target architecture and, as a result, I get the error "cannot execute binary file". Is there a way to produce executables of these tests on the host architecture rather than the target architecture? Should I be handling this process differently? Here are the following commands I used to build openssl. I replaced certain directories with DIR_HIDDEN.
export FIPS_DIRECTORY="$PWD/../../openssl-fips/tgt/linux-ppc603e/"
export cross="DIR_HIDDEN/powerpc-linux-gnu-"
make clean || exit 1
make dclean || exit 1
./Configure --prefix=$PWD/../tgt/linux-ppc603e linux-ppc fips --with-fipsdir=${FIPS_DIRECTORY}
make depend || exit 1
make CC="$FIPS_DIRECTORY/bin/fipsld" RANLIB="${cross}ranlib" AR="${cross}ar r" LD="$FIPS_DIRECTORY/bin/fipsld" FIPSLD_CC="${cross}gcc" HOSTCC="/usr/bin/gcc" || exit 1
make install || exit 1
I get the following error during the make command:
shlib_target=; if [ -n "" ]; then \
shlib_target="linux-shared"; \
elif [ -n "libcrypto" ]; then \
FIPSLD_CC="/DIR_HIDDEN/openssl/openssl-1.0.1i/../../openssl-fips/tgt/linux-ppc603e//bin/fipsld"; CC=/DIR_HIDDEN/openssl/openssl-1.0.1i/../../openssl-fips/tgt/linux-ppc603e//bin/fipsld; export CC FIPSLD_CC; \
fi; \
LIBRARIES="-L.. -lssl -L.. -lcrypto" ; \
make -f ../Makefile.shared -e \
APPNAME=openssl OBJECTS="openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o" \
LIBDEPS=" $LIBRARIES -ldl" \
link_app.${shlib_target}
make[2]: Entering directory `/DIR_HIDDEN/openssl/openssl-1.0.1i/apps'
( :; LIBDEPS="${LIBDEPS:--L.. -lssl -L.. -lcrypto -ldl}"; LDCMD="${LDCMD:-/DIR_HIDDEN/openssl/openssl-1.0.1i/../../openssl-fips/tgt/linux-ppc603e//bin/fipsld}"; LDFLAGS="${LDFLAGS:--DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DB_ENDIAN -DTERMIO -O3 -Wall -DOPENSSL_BN_ASM_MONT -I/DIR_HIDDEN/openssl/openssl-1.0.1i/../../openssl-fips/tgt/linux-ppc603e//include -DSHA1_ASM -DSHA256_ASM -DAES_ASM}"; LIBPATH=`for x in $LIBDEPS; do echo $x; done | sed -e 's/^ *-L//;t' -e d | uniq`; LIBPATH=`echo $LIBPATH | sed -e 's/ /:/g'`; LD_LIBRARY_PATH=$LIBPATH:$LD_LIBRARY_PATH ${LDCMD} ${LDFLAGS} -o ${APPNAME:=openssl} openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o ${LIBDEPS} )
/DIR_HIDDEN/openssl/openssl-1.0.1i/../../openssl-fips/tgt/linux-ppc603e//bin/fipsld: line 185: ./openssl: cannot execute binary file
make[2]: *** [link_app.] Error 126
When invoking the make command again and again, I get the same error but for all the applications located in the /test directory of the openssl tarball. Examples include bntest, ectest, and ecdhtest.
I received a similar error when I was cross compiling the FIPS module, but I was able to resolve that by including the host compiler in the HOSTCC variable. A similar trick did not work for the openssl compilation.
Any guidance would be appreciated. Thanks!
I was able to modify the make command to get the process to complete. I was missing the FIPS_SIG environment variable, which points to the incore script. The make command is now:
make FIPS_SIG=$PWD/`find ../../openssl-fips/ -iname incore` CC="$FIPS_DIRECTORY/bin/fipsld" RANLIB="${cross}ranlib" AR="${cross}ar r" LD="$FIPS_DIRECTORY/bin/fipsld" FIPSLD_CC="${cross}gcc"
I still see prints to console that indicate that openssl cannot be executed, but these are warnings and don't halt the makefile. Not really sure why or how this fixed the problem, but I'll take it.

undefined reference to sync_fetch_and_add_4

Whenever I try to use __sync_fetch_and_add with -m32 on a 64 bit machine, I get the following error, while it compiles fine with normal 64 bit. I am using gcc compiler 4.1.2. What can be the problem here and what is the solution?
replication.cpp:(.text+0xb3b): undefined reference to `__sync_fetch_and_add_4'
replication.cpp:(.text+0xb82): undefined reference to `__sync_fetch_and_add_4'
replication.cpp:(.text+0xcc2): undefined reference to `__sync_fetch_and_add_4'
/tmp/cc7u9FLV.o: In function `potential_barrier_leader(unsigned int, pthread_barrier_t*)':
replication.cpp:(.text+0xd3f): undefined reference to `__sync_fetch_and_add_4'
replication.cpp:(.text+0xd54): undefined reference to `__sync_fetch_and_add_4'
/tmp/cc7u9FLV.o:replication.cpp:(.text+0xdb0): more undefined references to `__sync_fetch_and_add_4' follow
collect2: ld returned 1 exit status
make: *** [all] Error 1
Using -march=i486 flag did the trick for me.
Try using a more recent GCC compiler (e.g. GCC 4.6). I tried to compile with gcc -S -O3 -m32 -fverbose-asm sync-3.c the test file gcc/testsuite/gcc.c-torture/compile/sync-3.c and it works. My gcc (on Debian/Sid/AMD64) is the system gcc 4.6.2 compiler.
hahah! there are 5+ "standard atomic libs" (+kernel support) that's hardly atom
ic if you ask me. but ignore it, is all a timely distraction.
so your building, ie glibc and get that error (i did)
glibc-2.11.x expects gcc-4.4.x to define it internally, and you have gcc sans bu
ilt-in atomic, likely you didnt specify arch that gcc accepts (due to lacky dire
ctions). were glibc likes 786, gcc wants 386 and figures 786 maybe. use "nativ
e" should do it. opt(march) and opt(mtune) ARE NON OPTIONAL gcc builds wrong w/
o them (likely)
you won't find a header or libfoo that defines it (per say)
for linux-gnu you might use (a simple for moi build)
cd gcc-4.4.foo
./configure --with-glibc-version=2.11 --enable-threads=posix \
--disable-cloog --disable-ppl --disable-libssp --enable-__cxa_atexit \
--disable-rpath --disable-nls --disable-bootstrp --disable-multilib \
--with-system-libunwind
IMPORTANT: if you build gcc w/o mtune march right, gcc wont define sync_fetch_and_add
(p.s. glibc sync_fetch_and_add_4 is just macro for sync_fetch_and_add which, aga
in, glibc expects is defined)
also if you replace gcc-3.foo with gcc-4.4.foo and are compiling you may need:
[ -n "$newgnu" ] && CFLAGS="$CFLAGS -march=native -mtune=native "
[ -n "$newgnu" ] && \
CFLAGS="$CFLAGS -std=gnu89 " && CPPFLAGS="$CPPFLAGS -std=gnu89 "
i newly need this (newgnu) to build binutils-ver/: -Wstrict-aliasing=0
cd glibc-2.foo/
./configure --with-headers=/usr/src/linux/usr/include \
--enable-kernel=2.2.foo \
--disable-profile --disable-sanity-checks --with-tls \
--disable-rpath --disable-nls
thanks guy in holland for posting --std that might be an issue for gcc upgraders !
no thanks to comittees continually changing and also creating "standards" that make depends problems in gcc :( use .h or .c appropriately for foo "builtin" to add features you want in your code like everyone else !!
have fun :)
With old GCC versions (4.5 for example) you might encounter the problem of __sync_fetch_and_add() being undeclared when using the g++ driver instead of gcc for linking a shared library.
Background: __sync_fetch_and_add is defined within static libgcc and missing from shared library libgcc_s.
So simply adding -lgcc might solve the problem. But there is a more elegant solution.
See here for full information and workaround(s):
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46563

Resources