Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020 
<== Date ==> <== Thread ==>

Subject: Re: Cross compiling
From: "Johnson, Andrew N. via Tech-talk" <tech-talk@aps.anl.gov>
To: "tech-talk@aps.anl.gov" <tech-talk@aps.anl.gov>
Date: Thu, 29 Aug 2019 19:23:58 +0000
Hi Florian,

On 8/29/19 1:33 PM, Florian Feldbauer via Tech-talk wrote:
My configure/os/CONFIG_SITE.linux-x86-64.linux-arm looks like this

GNU_TARGET = arm-angstrom-linux-gnueabi
GNU_BIN = /opt/cross-compiler/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi
COMMANDLINE_LIBRARY = READLINE_NCURSES
USR_CFLAGS += -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/iseg/cross-compiler/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi
USR_CXXFLAGS += -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/iseg/cross-compiler/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi

Looking at the compiler commands executed by make below, only the USR_CFLAGS are used when compiling c files, but the CXXFLAGS are ignored.
USR_CFLAGS is used when compiling .c files to .o
USR_CXXFLAGS is used when compling .cpp/.cxx/.cc flags to .o
USR_LDFLAGS is used when linking .o files together into executables or libraries.

It's the latter (link) stage that is failing in your build. Your first command is a compilation of a C file, which succeeds:
/opt/iseg/cross-compiler/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-gcc -D_GNU_SOURCE -D_DEFAULT_SOURCE         -march=armv7-a -mthumb -mfpu=neon  -mfloat-abi=hard --sysroot=/opt/iseg/cross-compiler/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi -DUNIX  -Dlinux     -O3 -g   -Wall     -march=armv7-a -mthumb -mfpu=neon  -mfloat-abi=hard --sysroot=/opt/iseg/cross-compiler/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi -fPIC -I. -I../O.Common -I. -I../../src/osi/compiler/gcc -I../../src/osi/compiler/default -I. -I../../src/osi/os/Linux -I../../src/osi/os/posix -I../../src/osi/os/default -I.. -I../../src/as -I../../src/bucketLib -I../../src/calc -I../../src/cvtFast -I../../src/cppStd -I../../src/cxxTemplates -I../../src/dbmf -I../../src/ellLib -I../../src/env -I../../src/error -I../../src/fdmgr -I../../src/flex -I../../src/freeList -I../../src/gpHash -I../../src/iocsh -I../../src/log -I../../src/macLib -I../../src/misc -I../../src/osi -I../../src/pool -I../../src/ring -I../../src/taskwd -I../../src/timer -I../../src/yacc -I../../src/yacc -I../../src/yajl -I/opt/epics/base/include/compiler/gcc -I/opt/epics/base/include/os/Linux -I/opt/epics/base/include -I/opt/epics/base/include/compiler/gcc -I/opt/epics/base/include/os/Linux -I/opt/epics/base/include         -c ../../src/yajl/yajl_parser.c

The next command is actually using g++ to link object files into a library (libCom.so.3.17.5), it isn't actually compiling anything, so it doesn't get given your $(USR_CXXFLAGS):
/opt/iseg/cross-compiler/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-g++ -o libCom.so.3.17.5 -shared -fPIC -L/opt/epics/base/lib/linux-arm -Wl,-rpath,/opt/epics/base/lib/linux-arm -rdynamic          asLib.o asTrapWrite.o bucketLib.o postfix.o calcPerform.o cvtFast.o resourceLib.o epicsSingletonMutex.o dbmf.o ellLib.o ellSort.o envSubr.o envData.o errlog.o errSymLib.o errSymTbl.o fdmgr.o fdManager.o freeListLib.o gpHashLib.o iocsh.o initHooks.o registry.o libComRegister.o iocLog.o logClient.o macCore.o macEnv.o macUtil.o alarmString.o aToIPAddr.o adjustment.o cantProceed.o epicsConvert.o epicsExit.o epicsStdlib.o epicsString.o truncateFile.o ipAddrToAsciiAsynchronous.o epicsUnitTest.o epicsThread.o epicsMutex.o epicsEvent.o epicsTime.o epicsMessageQueue.o epicsMath.o epicsAtomicOSD.o epicsGeneralTime.o osiClockTime.o osdSock.o osdSockAddrReuse.o osiSock.o systemCallIntMech.o epicsSocketConvertErrnoToString.o osdAssert.o osdFindSymbol.o osdInterrupt.o osdPoolStatus.o osdSignal.o osdEnv.o epicsReadline.o epicsTempFile.o epicsStdio.o osdStdio.o osdThread.o osdThreadExtra.o osdThreadHooks.o osdMutex.o osdSpin.o osdEvent.o osdTime.o osdMonotonic.o osdProcess.o osdNetIntf.o osdMessageQueue.o devLibVME.o devLibVMEOSD.o epicsStackTrace.o osdBackTrace.o osdFindAddr.o poolJob.o threadPool.o epicsRingPointer.o epicsRingBytes.o taskwd.o epicsTimer.o timer.o timerQueue.o timerQueueActive.o timerQueueActiveMgr.o timerQueuePassive.o yajl.o yajl_alloc.o yajl_buf.o yajl_encode.o yajl_gen.o yajl_lex.o yajl_parser.o       -lpthread   -lreadline -lncurses -lm -lrt -ldl -lgcc
The last command breaks because the --sysroot option is missing and the compiler doesn't find it's libraries.

Did I do something wrong? What is the correct way to define default C compiler and C++ compiler flags when cross-compiling?
You didn't set a variable to provide the linker flags needed for your build. Following your other settings that would be USR_LDFLAGS, but I would recommend that you actually set these variables instead:

ARCH_DEP_CFLAGS = <your USR_CFLAGS value above>

The ARCH_DEP_CXXFLAGS variable defaults to $(ARCH_DEP_CFLAGS) so you don't need to set this at all.

ARCH_DEP_LDFLAGS = <flags to pass to g++ when using it as a linker>

I'm suggesting you use the ARCH_DEP_ flags instead of the USR_ ones because some application Makefiles may override the USR_ variables instead of just appending to them, which would cause your builds to fail.

Hope this helps,

- Andrew

-- 
Complexity comes for free, Simplicity you have to work for.

Replies:
Re: Cross compiling Florian Feldbauer via Tech-talk
References:
Cross compiling Florian Feldbauer via Tech-talk

Navigate by Date:
Prev: Cross compiling Florian Feldbauer via Tech-talk
Next: Re: Cross compiling Florian Feldbauer via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020 
Navigate by Thread:
Prev: Cross compiling Florian Feldbauer via Tech-talk
Next: Re: Cross compiling Florian Feldbauer via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020 
ANJ, 29 Aug 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·