Cannot `cmake` a Qt project from a subshell when using the Yocto toolchain - bash

I have a project whose configuration steps are as follows:
cmake /src
This is being built in an Ubuntu 20.04 docker container where the only contents are the Yocto toolchain for my image and last line of $HOME/.bashrc is source /opt/my-distro/2.5.3/environment-setup-aarch64-poky-linux
If I load up the docker container as follows...
(host) $ docker run --rm -it -v /home/me/my-source:/src mybuildenv:latest
(docker) $ mkdir /build
(docker) $ cd /build
(docker) $ cmake /src
-- The CXX compiler identification is GNU 7.3.0
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /build
If I load up the container and do the same cmake command in a subshell, I get
(host) $ docker run --rm -it -v /home/me/my-source:/src mybuildenv:latest
(docker) $ mkdir /build
(docker) $ cd /build
(docker) $ /bin/bash -c 'cmake /src'
-- The CXX compiler identification is GNU 7.3.0
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- Check for working CXX compiler: /opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at application/CMakeLists.txt:17 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/build/CMakeFiles/CMakeOutput.log".
I expect this to work since both the parent and subshells environments...
(docker) $ env
...
(docker) $ /bin/bash -c 'env'
...
... are functionally identical (ordering slightly different but all variables are the exact same).
I am unsure where the problems lies, if it's in bash, docker, cmake, or yocto. This is a problem since the Microsoft Azure pipeline I am running this build environment in is spawning a sub shell under docker exec and under this circumstance I cannot built my application.
EDIT
One other thing I looked at was the variables define in the CMake files using this snippet:
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
The diff:
< -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
< -- CMAKE_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar
< -- CMAKE_ASM_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
---
> -- CMAKE_AR=/usr/bin/ar
> -- CMAKE_AR=/usr/bin/ar
18c17
< -- CMAKE_CROSSCOMPILING=TRUE
---
> -- CMAKE_CROSSCOMPILING=FALSE
39c38
< -- CMAKE_CXX_ARCHIVE_APPEND_IPO="/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar" r <TARGET> <LINK_FLAGS> <OBJECTS>
---
> -- CMAKE_CXX_ARCHIVE_APPEND_IPO="/usr/bin/gcc-ar" r <TARGET> <LINK_FLAGS> <OBJECTS>
41c40
< -- CMAKE_CXX_ARCHIVE_CREATE_IPO="/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar" cr <TARGET> <LINK_FLAGS> <OBJECTS>
---
> -- CMAKE_CXX_ARCHIVE_CREATE_IPO="/usr/bin/gcc-ar" cr <TARGET> <LINK_FLAGS> <OBJECTS>
43c42
< -- CMAKE_CXX_ARCHIVE_FINISH_IPO="/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib" <TARGET>
---
> -- CMAKE_CXX_ARCHIVE_FINISH_IPO="/usr/bin/gcc-ranlib" <TARGET>
48,49c47,48
< -- CMAKE_CXX_COMPILER_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar
< -- CMAKE_CXX_COMPILER_AR=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar
---
> -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
> -- CMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar
315,316c314,315
< -- CMAKE_CXX_COMPILER_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib
< -- CMAKE_CXX_COMPILER_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib
---
> -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
> -- CMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib
333c332
< -- CMAKE_CXX_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
---
> -- CMAKE_CXX_FLAGS=-O2 -pipe -g -feliminate-unused-debug-types
366d364
< -- CMAKE_C_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
396,400d393
< -- CMAKE_FIND_ROOT_PATH=/opt/my-distro/2.5.3/sysroots/aarch64-poky-linux;/opt/b9-core-5/2.5.3/sysroots/x86_64-pokysdk-linux
< -- CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
< -- CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
< -- CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
< -- CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
419d411
< -- CMAKE_LDFLAGS_FLAGS= -O2 -pipe -g -feliminate-unused-debug-types
423,424c415,416
< -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
< -- CMAKE_LINKER=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld
---
> -- CMAKE_LINKER=/usr/bin/ld
> -- CMAKE_LINKER=/usr/bin/ld
444,446c436,438
< -- CMAKE_NM=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-nm
< -- CMAKE_OBJCOPY=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objcopy
< -- CMAKE_OBJDUMP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objdump
---
> -- CMAKE_NM=/usr/bin/nm
> -- CMAKE_OBJCOPY=/usr/bin/objcopy
> -- CMAKE_OBJDUMP=/usr/bin/objdump
454,455c446,447
< -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
< -- CMAKE_RANLIB=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib
---
> -- CMAKE_RANLIB=/usr/bin/ranlib
> -- CMAKE_RANLIB=/usr/bin/ranlib
511,512c503,504
< -- CMAKE_STRIP=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-strip
< -- CMAKE_SYSTEM=Linux
---
> -- CMAKE_STRIP=/usr/bin/strip
> -- CMAKE_SYSTEM=Linux-5.15.0-56-generic
519c511
< -- CMAKE_SYSTEM_PROCESSOR=aarch64
---
> -- CMAKE_SYSTEM_PROCESSOR=x86_64
522,523c514
< -- CMAKE_SYSTEM_VERSION=
< -- CMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
---
> -- CMAKE_SYSTEM_VERSION=5.15.0-56-generic
528d518
< -- COMPILER_BASENAME=aarch64-poky-linux-g++
531d520
< -- INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED=include("/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake")
533,534c522
< -- OE_QMAKE_PATH_EXTERNAL_HOST_BINS=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin
< -- PRESET_CMAKE_SYSTEM_NAME=TRUE
---
> -- PRESET_CMAKE_SYSTEM_NAME=FALSE
549d536
< -- _CMAKE_TOOLCHAIN_PREFIX=aarch64-poky-linux-
552d538
< -- _INCLUDED_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
564d549
< -- config=
575d559
< -- toolchain_config_files=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake.d/OEQt5Toolchain.cmake
So, as seen when I run /bin/bash -c "cmake /src" no toolchain related variables are populated, while when I run cmake /src there are. Is there any reason this would be the case when the bash environments are the same? Is there something I can do to make sure the variables carry over? I don't seem to have this problem with qmake.

The reason /bin/bash -c "cmake /src" is not equivalent to cmake /src is because cmake was an alias for cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake and aliases are not inherited by subshells.
The solution is to use /bin/bash -c "cmake -DCMAKE_TOOLCHAIN_FILE=/opt/my-distro/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'"

Related

cmake dry-run for cmake_link_script

I'm building aws_demos from amazon-freertos repository, and would like to get all the build commands including the link commands in this project. I'm building the project with 'Gnu Makefiles' generator and in order to do so I'm running the following command :
make -C build -Bn aws_demos VERBOSE=1
or even :
cmake --build build --target aws_demos --verbose -- -Bn
but both produce the same output which is missing the full link command, I only get the following in the console :
/usr/bin/cmake -E cmake_link_script CMakeFiles/aws_demos.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-objcopy -O ihex /home/sagi/amazon-freertos/build/aws_demos.elf /home/sagi/amazon-freertos/build/aws_demos.hex
/usr/bin/arm-none-eabi-size /home/sagi/amazon-freertos/build/aws_demos.elf
but when running only the following command :
(cd build && /usr/bin/cmake -E cmake_link_script CMakeFiles/aws_demos.dir/link.txt --verbose=1)
I get the whole link command :
/usr/bin/arm-none-eabi-gcc -g -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=nosys.specs -Wl,-Map=output.map,--gc-sections,-zmuldefs -lm CMakeFiles/aws_demos.dir/vendors/st/boards/stm32l475_discovery/aws_demos/application_code/st_code/cmsis_os.c.obj CMakeFiles/aws_demos.dir/vendors/st/boards/stm32l475_discovery/aws_demos/application_code/st_code/entropy_hardware_poll.c.obj .....
truncated because it is too long.
deleting build/aws_demos.elf file and building again without the -Bn parameters to make output the whole link command, i.e. :
make -C build VERBOSE=1
[ 86%] Linking C executable aws_demos.elf
/usr/bin/cmake -E cmake_link_script CMakeFiles/aws_demos.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=nosys.specs -Wl,-Map=output.map,--gc-sections,-zmuldefs -lm CMakeFiles/aws_demos.dir/vendors/st/boards/stm32l475_discovery/aws_demos/application_code/st_code/cmsis_os.c.obj
...
which means that in make dry-run mode the verbose parameter is being ignored in cmake_link_script
any idea how to get make/cmake to print this command as well ?

Cross compiling with arm-linux-gnueabihf

I am quite new to cross compiling. After downloading the arm-linux-gnueabihf tool from arm. I tried to use the binary called arm-linux-gnueabihf-g++ and arm-linux-gnueabihf-gcc to compile my code. My command looks something like:
~/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -Isrc -I/usr/include -std=c++11 -Wall -Wno-unknown-pragmas -O0 -g3 -D__DEBUG_BUILD__ -DDEVELOPMENT -MMD -c -o "Debug/src/BatteryStatus.o" "src/BatteryStatus.cpp"
I immediately run into this issue:
~/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/stdlib.h:133:35: error: missing binary operator before token "("
#if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
It's weird that the issue happens in the tool chain, I would expect some incompatibilities in the libraries I am using. The environment entails CentOS 7.2, c++ 11 and I am compiling for an ARM 32-bit target on a x86_64 host machine. Building a simple hello world program went fine, it compiled and ran successfully on the target machine.
You are pointing to your native header files directory, /usr/include, in your build command. This is very likely the cause of your problem. Try this command instead:
~/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -Isrc -std=c++11 -Wall -Wno-unknown-pragmas -O0 -g3 -D__DEBUG_BUILD__ -DDEVELOPMENT -MMD -c -o "Debug/src/BatteryStatus.o" "src/BatteryStatus.cpp
The default directories used by the toolchain can be displayed using:
echo | /opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -v -x c -E -
Using built-in specs.
COLLECT_GCC=/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
Target: arm-linux-gnueabihf
Configured with: /tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/src/gcc/configure --target=arm-linux-gnueabihf --prefix= --with-sysroot=/arm-linux-gnueabihf/libc --with-build-sysroot=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/install//arm-linux-gnueabihf/libc --with-bugurl=https://bugs.linaro.org/ --enable-gnu-indirect-function --enable-shared --disable-libssp --disable-libmudflap --enable-checking=release --enable-languages=c,c++,fortran --with-gmp=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpfr=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpc=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-isl=/tmp/dgboter/bbs/rhev-vm8--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-arch=armv7-a --with-fpu=neon --with-float=hard --with-arch=armv7-a --with-pkgversion='GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)'
Thread model: posix
gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))
COLLECT_GCC_OPTIONS='-v' '-E' '-mfloat-abi=hard' '-mfpu=neon' '-mtls-dialect=gnu' '-marm' '-march=armv7-a+simd'
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../libexec/gcc/arm-linux-gnueabihf/8.3.0/cc1 -E -quiet -v -iprefix /opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/ -isysroot /opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc - -mfloat-abi=hard -mfpu=neon -mtls-dialect=gnu -marm -march=armv7-a+simd
ignoring duplicate directory "/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.3.0/include"
ignoring nonexistent directory "/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/local/include"
ignoring duplicate directory "/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.3.0/include-fixed"
ignoring duplicate directory "/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/include
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/include-fixed
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/include
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"
COMPILER_PATH=/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../libexec/gcc/arm-linux-gnueabihf/8.3.0/:/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../libexec/gcc/:/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/:/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/:/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/lib/:/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/lib/:/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-E' '-mfloat-abi=hard' '-mfpu=neon' '-mtls-dialect=gnu' '-marm' '-march=armv7-a+simd'
That is, on my system, the correct, default directories for the header files would be:
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/include
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/include-fixed
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/include
/opt/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/include
and not /usr/include.

Cmake and make, error compiling scribus

I'm finding always an error while trying to compile Scribus 1.5 svn. I tried with both Qt4 and Qt5 but the error doesn't seems to rely on them.
This is the cmake output:
cmake -DCMAKE_INSTALL_PREFIX:PATH=/home/fabio/scribusinstall .. -DUSE_QT5=1 -DQT_PREFIX="/opt/qt5/bin"
-- Shared Library Flags:
-- Scribus 1.5.0.svn will be built to install into /home/fabio/scribusinstall
-- Machine: x86_64-linux-gnu, void pointer size: 8
-- Found target X86
-- Found target X86_64
-- Building for target x86_64-linux-gnu
-- Using standard ApplicationDataDir. You can change it with -DAPPLICATION_DATA_DIR
-- ----- USE QT 5-----
-- ----- USE QT Widgets-----
-- ----- USE Qt5Gui -----
-- ----- USE QT 5 XML -----
-- ----- USE Qt5WebKit -----
-- ----- USE Qt5WebKitWidgets -----
-- ----- USE Qt5Network -----
-- ----- USE Qt5OpenGL -----
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so
ZLIB Library Found OK
-- Found PNG: /usr/lib/x86_64-linux-gnu/libpng.so
Using PNG Library: /usr/lib/x86_64-linux-gnu/libpng.so
PNG Library Found OK
OSG found OK
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so
-- Found JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so
JPEG Library Found OK
-- Found TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so
TIFF Library Found OK
-- Found PythonLibs: /usr/lib/libpython2.7.so (found suitable version "2.7.3", required is "2")
Python Library Found OK
-- Found Freetype: /usr/lib/x86_64-linux-gnu/libfreetype.so (found version "2.4.8")
-- FreeType2 Library Found OK
-- Looking for FT_Get_First_Char in /usr/lib/x86_64-linux-gnu/libfreetype.so
-- Looking for FT_Get_First_Char in /usr/lib/x86_64-linux-gnu/libfreetype.so - found
-- Looking for FT_Get_Next_Char in /usr/lib/x86_64-linux-gnu/libfreetype.so
-- Looking for FT_Get_Next_Char in /usr/lib/x86_64-linux-gnu/libfreetype.so - found
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26")
-- checking for one of the modules 'libcairo>=1.2.0;cairo>=1.2.0'
CAIRO Library Found OK
-- Found Cups: /usr/lib/x86_64-linux-gnu/libcups.so (found version "1.5.3")
CUPS Library Found OK
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.7.8")
LIBXML2 Library Found OK
LCMS ReleaseLibrary: /usr/lib/x86_64-linux-gnu/liblcms.so
LCMS Debug Library: LCMS_LIBRARY_DEBUG-NOTFOUND
LCMS Library: /usr/lib/x86_64-linux-gnu/liblcms.so
LCMS 2 ReleaseLibrary: LCMS2_LIBRARY_RELEASE-NOTFOUND
LCMS 2 Debug Library: LCMS2_LIBRARY_DEBUG-NOTFOUND
LCMS 2 Library: LCMS2_LIBRARY_RELEASE-NOTFOUND
LCMS ReleaseLibrary: /usr/lib/x86_64-linux-gnu/liblcms.so
LCMS Debug Library: LCMS_LIBRARY_DEBUG-NOTFOUND
LCMS Library: /usr/lib/x86_64-linux-gnu/liblcms.so
LittleCMS Library Found OK
-- checking for one of the modules 'fontconfig'
FontConfig Found OK
-- Could NOT find HUNSPELL (missing: HUNSPELL_LIBRARIES HUNSPELL_INCLUDE_DIR)
Hunspell or its developer libraries NOT found - Disabling support for spell checking
PoDoFo found OK
-- Boost version: 1.46.1
Boost Library Found OK
Building without GraphicksMagick (use -DWANT_GRAPHICSMAGICK=1 to enable)
-- checking for one of the modules 'libpoppler>=0.19.0;poppler>=0.19.0'
-- Found poppler
-- Found poppler libs: /usr/lib/x86_64-linux-gnu/libpoppler.so
-- Found poppler includes: /usr/include/poppler
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for include file endian.h
-- Looking for include file endian.h - found
-- Looking for include file fcntl.h
-- Looking for include file fcntl.h - found
RPATH: lib/scribus/plugins/;
-- Qt5::CoreQt5::WidgetsQt5::GuiQt5::XmlQt5::WebKitQt5::WebKitWidgetsQt5::NetworkQt5::OpenGL/usr/lib/x86_64-linux-gnu/libxml2.so/usr/lib/x86_64-linux-gnu/libz.so
-- Building with Scripter 1
-- Source header files will be installed
-- /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/resources/translations/po
-- The following GUI languages will be installed:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir
then I do:
cd ..
make
Scanning dependencies of target scribus_pgf_lib
[ 0%] Building CXX object scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/Decoder.cpp.o
<command-line>:0:1: error: macro names must be identifiers
/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf/Decoder.cpp:583:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
make[2]: *** [scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/Decoder.cpp.o] Errore 1
make[1]: *** [scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/all] Errore 2
make: *** [all] Errore 2
It doesn't seem to be a dependency problem because I installed them with the apt-get build-dep command in Ubuntu Precise (Linux Mint 13). What can be the problem and how can I solve it?
Thank you very much in advance!
Edited to add make VERBOSE=1
fabio#fabio-EasyNote-TS11HR ~/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir $ make VERBOSE=1/usr/bin/cmake -H/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810 -B/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/CMakeFiles /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: ingresso nella directory "/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir"
make -f scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/build.make scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/depend
make[2]: ingresso nella directory "/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir"
cd /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810 /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus/third_party/pgf /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/DependInfo.cmake --color=
make[2]: uscita dalla directory "/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir"
make -f scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/build.make scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/build
make[2]: ingresso nella directory "/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir"
/usr/bin/cmake -E cmake_progress_report /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/CMakeFiles
[ 0%] Building CXX object scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/Decoder.cpp.o
cd /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus/third_party/pgf && /usr/bin/c++ -DNDEBUG -DQT_CORE_LIB -DQT_WIDGETS_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_XML_LIB -DQT_CORE_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_WEBKITWIDGETS_LIB -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_PRINTSUPPORT_LIB -DQT_LOCATION_LIB -DQT_SENSORS_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_OPENGL_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DUSE_QT5 -DHAVE_DLFCN_H -DHAVE_UNISTD_H -DHAVE_CONFIG_H -O2 -Wall -fPIC -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus/third_party/pgf -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf -I/opt/qt5/include -I/opt/qt5/include/QtCore -I/opt/qt5/mkspecs/default -I/opt/qt5/include/QtWidgets -I/opt/qt5/include/QtGui -I/opt/qt5/include/QtXml -I/opt/qt5/include/QtWebKit -I/opt/qt5/include/QtOpenGL -I/opt/qt5/include/QtNetwork -I/usr/include/qt5 -I/usr/include/qt5/QtWebKitWidgets -I/usr/include/qt5/QtQuick -I/usr/include/qt5/QtQml -I/usr/include/qt5/QtPrintSupport -I/usr/include/qt5/QtLocation -I/usr/include/qt5/QtSensors -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus -I/usr/include/libxml2 -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810 -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus -DSHAREDIR=\"/home/fabio/scribusinstall/share/scribus/\" -DDOCDIR=\"/home/fabio/scribusinstall/share/doc/scribus/\" -DICONDIR=\"/home/fabio/scribusinstall/share/scribus/icons/\" -DSAMPLESDIR=\"/home/fabio/scribusinstall/share/scribus/samples/\" -DSCRIPTSDIR=\"/home/fabio/scribusinstall/share/scribus/scripts/\" -DTEMPLATEDIR=\"/home/fabio/scribusinstall/share/scribus/templates/\" -DDESKTOPDIR=\"/home/fabio/scribusinstall/share/applications/\" -DLIBDIR=\"/home/fabio/scribusinstall/lib/scribus/\" -DPLUGINDIR=\"/home/fabio/scribusinstall/lib/scribus/plugins/\" -D -D -DCOMPILE_SCRIBUS_MAIN_APP -o CMakeFiles/scribus_pgf_lib.dir/Decoder.cpp.o -c /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf/Decoder.cpp
<command-line>:0:1: error: macro names must be identifiers
/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf/Decoder.cpp:583:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
make[2]: *** [scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/Decoder.cpp.o] Errore 1
make[2]: uscita dalla directory "/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir"
make[1]: *** [scribus/third_party/pgf/CMakeFiles/scribus_pgf_lib.dir/all] Errore 2
make[1]: uscita dalla directory "/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir"
make: *** [all] Errore 2
Following there are the only two "-D" definitions found in the Makefile:
# Special rule for the target install/local
install/local: preinstall
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/strip
install/strip: preinstall
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
You can start from the error you get:
<command-line>:0:1: error: macro names must be identifiers
The <command-line>:0:1 shows that the error does not come from the .cpp file but from the options passed to the compiler. Since you generated a Makefile and called it with make, it means that the generated Makefile is erratic.
Now, error: macro names must be identifiers probably means that the Makefile tried to create a macro that does not correspond to a proper preprocessing identifier with the option -D. For example, if you type:
g++ foobar.cpp -D1
You will get the exact same error since 1 is not a valid identifier (valid identifiers only contain letters, digits and underscores; the first character can not be a digit). I can't deduce more with just what you have, but what you can do is search your Makefile for an invalid -D option an try to find which part of the CMakeLists.txt could have generated this option.
The macro definition with -D is often defined from a cmake file with the following command add_definitions. For example, I could have passed my error-prone -D1 option by adding this line to the cmake:
add_definitions(-D1)
Hope you will manage to track down the cause of your error.
EDIT: The error is in this giant line:
cd /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus/third_party/pgf && /usr/bin/c++ -DNDEBUG -DQT_CORE_LIB -DQT_WIDGETS_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_XML_LIB -DQT_CORE_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_WEBKITWIDGETS_LIB -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_PRINTSUPPORT_LIB -DQT_LOCATION_LIB -DQT_SENSORS_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_OPENGL_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DUSE_QT5 -DHAVE_DLFCN_H -DHAVE_UNISTD_H -DHAVE_CONFIG_H -O2 -Wall -fPIC -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus/third_party/pgf -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf -I/opt/qt5/include -I/opt/qt5/include/QtCore -I/opt/qt5/mkspecs/default -I/opt/qt5/include/QtWidgets -I/opt/qt5/include/QtGui -I/opt/qt5/include/QtXml -I/opt/qt5/include/QtWebKit -I/opt/qt5/include/QtOpenGL -I/opt/qt5/include/QtNetwork -I/usr/include/qt5 -I/usr/include/qt5/QtWebKitWidgets -I/usr/include/qt5/QtQuick -I/usr/include/qt5/QtQml -I/usr/include/qt5/QtPrintSupport -I/usr/include/qt5/QtLocation -I/usr/include/qt5/QtSensors -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/builddir/scribus -I/usr/include/libxml2 -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810 -I/home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus -DSHAREDIR=\"/home/fabio/scribusinstall/share/scribus/\" -DDOCDIR=\"/home/fabio/scribusinstall/share/doc/scribus/\" -DICONDIR=\"/home/fabio/scribusinstall/share/scribus/icons/\" -DSAMPLESDIR=\"/home/fabio/scribusinstall/share/scribus/samples/\" -DSCRIPTSDIR=\"/home/fabio/scribusinstall/share/scribus/scripts/\" -DTEMPLATEDIR=\"/home/fabio/scribusinstall/share/scribus/templates/\" -DDESKTOPDIR=\"/home/fabio/scribusinstall/share/applications/\" -DLIBDIR=\"/home/fabio/scribusinstall/lib/scribus/\" -DPLUGINDIR=\"/home/fabio/scribusinstall/lib/scribus/plugins/\" -D -D -DCOMPILE_SCRIBUS_MAIN_APP -o CMakeFiles/scribus_pgf_lib.dir/Decoder.cpp.o -c /home/fabio/ScribusSVN/scribus-trunk-1.5.0svn201304091810/scribus/third_party/pgf/Decoder.cpp
In the middle of the line, there are the options -D -D that trigger your actual error. Now, the problem will be to find what generated this command line and how to correct this :)

How to build a cross-compiler for i386-apple-darwin target from x86_64-apple-darwin host?

Problem overview
I am trying to learn how to build a cross-compiler, specifically a version of GNU gcc 4.7.2 on a 64-bit Intel OS X host that targets i386-apple-darwin (32-bit Intel). However, I keep getting stuck on the same error:
...
checking for i386-apple-darwin-gcc... /Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/xgcc -B/Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/bin/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/lib/ -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/include -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/sys-include
checking for suffix of object files... configure: error: in `/Users/alexpreynolds/Developer/third-party/build-gcc/i386-apple-darwin/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[1]: *** [configure-target-libgcc] Error 1
make: *** [all] Error 2
Build process
I first build a version of GNU binutils which targets i386-apple-darwin, which is accessible to the GNU gcc build folder:
$ cd third-party
$ wget http://ftp.gnu.org/gnu/binutils/binutils-2.23.2.tar.bz2
$ tar xjvf binutils-2.23.2.tar.bz2
$ mkdir i386-apple-darwin
$ mkdir build-binutils && cd build-binutils
$ ../binutils-2.23.2/configure --target=i386-apple-darwin --prefix="/Users/alexpreynolds/Developer/third-party/i386-apple-gcc"
$ make all && make install
...
Then I try to build a targeted version of gcc as follows:
$ cd ..
$ pwd
/Users/alexpreynolds/Developer/third-party
$ wget http://ftp.gnu.org/pub/gnu/gcc/gcc-4.7.2/gcc-4.7.2.tar.bz2
$ tar xvjf gcc-4.7.2.tar.bz2
$ cd gcc-4.7.2
$ ./contrib/download_prerequisites
... /* this grabs GMP, MPC and MPFR dependencies */
$ cd ..
$ mkdir build-gcc && cd build-gcc
$ ../gcc-4.7.2/configure --target=i386-apple-darwin --prefix="/Users/alexpreynolds/Developer/Bedops/bedops/third-party/i386-apple-gcc"
$ make
...
After about 30 minutes of compiling stuff, it gets stuck with the error message shown above.
Error details
To track down the source of the error, here is a snippet of build-gcc/i386-apple-darwin/libgcc/config.log:
configure:3344: /Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/xgcc -B/Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/bin/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/lib/ -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/include -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/sys-include -V >&5
xgcc: error: unrecognized command line option '-V'
xgcc: fatal error: no input files
compilation terminated.
configure:3355: $? = 1
configure:3344: /Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/xgcc -B/Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/bin/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/lib/ -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/include -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/sys-include -qversion >&5
xgcc: error: unrecognized command line option '-qversion'
xgcc: fatal error: no input files
compilation terminated.
configure:3355: $? = 1
configure:3371: /Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/xgcc -B/Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/bin/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/lib/ -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/include -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/sys-include -o conftest -g -O2 conftest.c >&5
Assembler messages:
Fatal error: invalid listing option `r'
configure:3374: $? = 1
configure:3562: checking for suffix of object files
configure:3584: /Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/xgcc -B/Users/alexpreynolds/Developer/third-party/build-gcc/./gcc/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/bin/ -B/Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/lib/ -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/include -isystem /Users/alexpreynolds/Developer/third-party/i386-apple-gcc/i386-apple-darwin/sys-include -c -g -O2 conftest.c >&5
Assembler messages:
Fatal error: invalid listing option `r'
configure:3588: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgcc/"
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:3602: error: in `/Users/alexpreynolds/Developer/third-party/build-gcc/i386-apple-darwin/libgcc':
configure:3605: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
The compiler I'm bootstrapping from
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.7.2/lto-wrapper
Target: x86_64-apple-darwin12
Configured with: ../gcc-4.7.2/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check --with-pkgversion='MacPorts gcc47 4.7.2_2+universal'
Thread model: posix
gcc version 4.7.2 (MacPorts gcc47 4.7.2_2+universal)
Question
Is there a step I missed in setting up the build environment of coreutils or gcc such that this error results?
What else can I troubleshoot in trying to resolve this error? My Google searches on this error message are not bearing much fruit.
Changes
I changed the build script as follows:
#!/bin/bash -x
WORK_DIR=$PWD
INSTALL_DIR=$WORK_DIR/gcc-4.7.2-darwin
MIN_OSX_VERSION=10.5
if [ -d "$INSTALL_DIR" ]; then
echo "Directory $INSTALL_DIR already exists";
exit 1
fi
BINUTILS=binutils-2.23.2
TARBALL_BINUTILS=$BINUTILS.tar.bz2
URL_BINUTILS=http://ftp.gnu.org/gnu/binutils/$TARBALL_BINUTILS
SOURCE_BINUTILS_DIR=$WORK_DIR/$BINUTILS
BUILD_BINUTILS_DIR=$WORK_DIR/build-$BINUTILS
GCC=gcc-4.7.2
TARBALL_GCC=$GCC.tar.bz2
URL_GCC=http://ftp.gnu.org/pub/gnu/gcc/$GCC/$TARBALL_GCC
SOURCE_GCC_DIR=$WORK_DIR/$GCC
BUILD_GCC_DIR=$WORK_DIR/build-$GCC
curl -O $URL_BINUTILS
mkdir -p $SOURCE_BINUTILS_DIR
tar -xjvf $TARBALL_BINUTILS
rm $TARBALL_BINUTILS
mkdir -p $BUILD_BINUTILS_DIR
cd $BUILD_BINUTILS_DIR
$SOURCE_BINUTILS_DIR/configure --prefix=$INSTALL_DIR
make -j $(sysctl -n hw.availcpu) all CFLAGS='-Wno-error' && make install
find $INSTALL_DIR -name '*strip*' -delete
cd $WORK_DIR
curl -O $URL_GCC
mkdir -p $SOURCE_GCC_DIR
tar -xvjf $TARBALL_GCC
rm $TARBALL_GCC
cd $SOURCE_GCC_DIR
sed -i '' -e 's/wget/curl -O/g' $SOURCE_GCC_DIR/contrib/download_prerequisites
$SOURCE_GCC_DIR/contrib/download_prerequisites
cd $WORK_DIR
mkdir -p $BUILD_GCC_DIR
cd $BUILD_GCC_DIR
$SOURCE_GCC_DIR/configure --prefix=$INSTALL_DIR --enable-languages=c,c++
make -j $(sysctl -n hw.availcpu) CFLAGS="-mmacosx-version-min=$MIN_OSX_VERSION" && make install
find $INSTALL_DIR -name '*.a' -print0 | xargs -0 -n1 ranlib
rm -Rf $BUILD_GCC_DIR
rm -Rf $BUILD_BINUTILS_DIR
rm -Rf $SOURCE_GCC_DIR
rm -Rf $SOURCE_BINUTILS_DIR
The ranlib step was necessary due to numerous errors during the process of building a library.
To build an i386 binary, I had to do the following with my Makefile:
ARCH = i386
...
GCCDIR = ${PARTY3}/gcc-4.7.2-darwin
GCCBINDIR = ${GCCDIR}/bin
GCCLIBDIR = ${GCCDIR}/lib
GCCINCDIR = ${GCCDIR}/include
...
LIBCPP = libgcc_eh.a
LIBCXX = libstdc++.a
...
INCLUDES = -I${GCCINCDIR} ...
...
CC = ${GCCBINDIR}/gcc
CXX = ${GCCBINDIR}/g++
...
GCCCPPLIBPATH = ${GCCLIBDIR}/gcc/x86_64-apple-darwin12.3.0/4.7.2/${ARCH}/${LIBCPP}
GCCCXXLIBPATH = ${GCCLIBDIR}/${ARCH}/${LIBCXX}
...
FLAGS = ${SFLAGS} ${NONSTATICFLAGS} ${OBJS} -L${GCCLIBDIR} ...
...
run: dependencies
mkdir -p ${BIN} && ${CXX} -o ${BIN}/${PROG}_${ARCH} ${FLAGS} -static-libgcc -mmacosx-version-min=${MIN_OSX_VERSION} -arch ${ARCH} ... ${GCCCPPLIBPATH} ${GCCCXXLIBPATH} ${SOURCE1}
Summary of Makefile changes:
I had to add the -static-libgcc flag and leave out -static-libstdc++, which had no effect (except to cause the build to fail, until I ran ranlib on the static libraries, which fixed the build failure but had no effect on -static-libstdc++).
I added ${GCCCPPLIBPATH} and ${GCCCXXLIBPATH} to the run target, which each point to the static C anc C++ libraries libgcc_eh.a and libstdc++.a, respectively.
This allowed me to compile a working i386 (32-bit) binary, but the same GCC installation failed to build a working x86_64 (64-bit) binary.
After thinking about this a little, it occurs to me that by far the easiest solution would be to compile GCC for x86_64, and then to just pass -m32 when you wish to build for i386. Is that not sufficient for your needs for some reason? Building in this manner is dramatically simpler, and doesn't require any of the madness described below. Doing the following sequence of events results in a working compiler that will spit out i386 binaries when requested:
WORK_DIR=$PWD
INSTALL_DIR=$WORK_DIR/install
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.23.2.tar.bz2
tar xjvf binutils-2.23.2.tar.bz2
mkdir build-binutils && cd build-binutils
../binutils-2.23.2/configure --prefix=$INSTALL_DIR
make -j $(sysctl -n hw.availcpu) all CFLAGS='-Wno-error' && make install
find $INSTALL_DIR -name '*strip*' -delete
cd $WORK_DIR
curl -O http://ftp.gnu.org/pub/gnu/gcc/gcc-4.7.2/gcc-4.7.2.tar.bz2
tar xvjf gcc-4.7.2.tar.bz2
cd gcc-4.7.2
sed -i '' -e 's/wget/curl -O/g' ./contrib/download_prerequisites
./contrib/download_prerequisites
cd ..
mkdir build-gcc && cd build-gcc
../gcc-4.7.2/configure --prefix=$INSTALL_DIR --enable-languages=c,c++
make -j $(sysctl -n hw.availcpu) && make install
Once this completes you can see it in action like so:
mrowe#falcon:~/tmp$ cat > test.cpp
#include <iostream>
int main(int argc, char **argv) {
std::cerr << "Built with GCC 4.7" << std::endl;
return 0;
}
^D
mrowe#falcon:~/tmp$ ./install/bin/g++ -o test test.cpp
mrowe#falcon:~/tmp$ file test
test: Mach-O 64-bit executable x86_64
mrowe#falcon:~/tmp$ ./install/bin/g++ -m32 -static-libgcc -static-libstdc++ -o test test.cpp
mrowe#falcon:~/tmp$ file test
test: Mach-O executable i386
mrowe#falcon:~/tmp$ otool -L ./test
./test:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1192.0.0)
mrowe#falcon:~/tmp$ ./test
Built with GCC 4.7
mrowe#falcon:~/tmp$
If you see warnings like:
ignoring file …/4.7.2/i386/libgcc.a, file was built for archive which is not the architecture being linked (i386)
You can fix them by running ranlib on the static libraries:
find $INSTALL_DIR -name '*.a' -print0 | xargs -0 -n1 ranlib
Below is my attempt at helping you along the path you were attempting to follow. I don't think it's the ideal approach and it is fraught with problems.
The error you reported seeing is due to your GCC build trying to use the GNU assembler from binutils when the generated assembly is intended to be assembled with the GNU assembler from Apple's cctools. The dialect of assembly that is supported differs between the two as Apple's assembler diverged from the upstream GNU assembler many years ago.
All of the instructions I was able to find for building cctools were out of date so I experimented until I got something working. I did something close to the following:
curl -O http://opensource.apple.com/tarballs/cctools/cctools-829.tar.gz
tar xvzf cctools-829.tar.gz
cd cctools-829
You'll then need to patch two files in order to build without a dependency on LLVM:
diff -ru cctools-829/libstuff/lto.c cctools-829.modified/libstuff/lto.c
--- cctools-829/libstuff/lto.c 1969-12-31 16:00:00.000000000 -0800
+++ cctools-829.modified/libstuff/lto.c 2013-04-05 03:18:34.000000000 -0700
## -376,4 +376,18 ##
lto_dispose(mod);
}
+#else
+
+#include <stdlib.h>
+
+__private_extern__
+int
+is_llvm_bitcode(
+ struct ofile *ofile,
+ char *addr,
+ size_t size)
+{
+ return 0;
+}
+
#endif /* LTO_SUPPORT */
diff -ru cctools-829/misc/libtool.c cctools-829.modified/misc/libtool.c
--- cctools-829/misc/libtool.c 1969-12-31 16:00:00.000000000 -0800
+++ cctools-829.modified/misc/libtool.c 2013-04-05 03:20:21.000000000 -0700
## -1369,8 +1369,11 ##
}
}
}
- else if(ofiles[i].arch_type == OFILE_Mach_O ||
- ofiles[i].arch_type == OFILE_LLVM_BITCODE){
+ else if(ofiles[i].arch_type == OFILE_Mach_O
+#ifdef LTO_SUPPORT
+ || ofiles[i].arch_type == OFILE_LLVM_BITCODE
+#endif
+ ){
if(cmd_flags.ranlib == TRUE){
error("for architecture: %s file: %s is not an "
"archive (no processing done on this file)",
And then build:
make install USE_DEPENDENCY_FILE=NO BUILD_DYLIBS=NO LTO= TRIE= DSTROOT=../build-cctools
And install the necessary parts of by hand:
cd ..
cp build-cctools/usr/bin/as i386-apple-gcc/bin/i386-apple-darwin-as
cp build-cctools/usr/bin/as i386-apple-gcc/i386-apple-darwin/bin/as
cp build-cctools/usr/bin/lipo i386-apple-gcc/bin/i386-apple-darwin-lipo
cp build-cctools/usr/bin/lipo i386-apple-gcc/i386-apple-darwin/bin/lipo
cp build-cctools/usr/bin/strip i386-apple-gcc/bin/i386-apple-darwin-strip
cp build-cctools/usr/bin/strip i386-apple-gcc/i386-apple-darwin/bin/strip
If we then attempt to build GCC once more we'll discover that the build process is upset because our freshly-built assembler is unable to target x86_64. Since that doesn't seem relevant to what you're trying to achieve you can add the --disable-multilib argument to GCC's configure script to prevent it from trying that.
At this point I ran in to errors while attempting to build libgcc. These errors are because a suitable linker cannot be found, so I guess that now you'd need to download and build ld64 too.
And it's at this point that I've run out of time to make it any further. Good luck!

Rebuild only if the source was modified by a previous command

I have a python script which extracts information from a C++ source file and writes it to a header file. Whenever this generated header changes (which happens rarely), I want to re-compile it (via the GCC precompiled header feature).
Obviously, the command invoking the script depends on the source file, and the recompiling command depends on the header file generated by the script.
add_custom_command(OUTPUT "file.pch.h" COMMAND <script> DEPENDS "file.cpp")
add_custom_command(OUTPUT "file.pch.h.gch" COMMAND <compile> DEPENDS "file.pch.h")
But now file.pch.h.gch depends on file.cpp and is recompiled whenever it changes. How can I avoid this?
Have your script write the header to a temporary file, and only copy it over the existing file.pch.h if it’s changed. Then the (fast) script runs every time file.cpp changes, but the precompiled header only gets reprecompiled if it’s changed.
If you don’t want to modify the script, you can use a separate move-if-change script, running a command along these lines:
myscript < file.cpp > file.pch.h.tmp && move-if-change file.pch.h.tmp file.pch.h
There might be a nicer way to do this with Cmake, but this is the old-fashioned way to solve this problem with Make.
Here’s a working example with CMake.
The main program, foo.c:
#include "foo.pch.h"
#ifndef FOO_PCH
#include <stdio.h>
#endif
int main() {
printf("Hello, world\n");
return 0;
}
The program to generate the precompiled header, make-pch:
#!/bin/bash
(echo '#define FOO_PCH 1'
awk '/^#endif/ { p = 0 }
p { print $0 }
/^#ifndef FOO_PCH/ { p = 1 }') < foo.c > foo.pch.h.tmp
if ! cmp -s foo.pch.h{.tmp,}; then
echo 'Header changed, updating'
mv foo.pch.h{.tmp,}
else
echo 'Header not changed'
rm -f foo.pch.h.tmp
fi
And CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
add_executable(foo foo.c foo.pch.h.gch)
add_custom_command(OUTPUT "foo.pch.h" COMMAND ./make-pch DEPENDS "foo.c")
add_custom_command(OUTPUT "foo.pch.h.gch"
COMMAND echo calling gcc
COMMAND gcc foo.pch.h
DEPENDS "foo.pch.h")
Let’s build it:
$ cmake .
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is Clang 4.1.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/andrew/sx/14662471
$ make
[ 33%] Generating foo.pch.h
Header changed, updating
[ 66%] Generating foo.pch.h.gch
calling gcc
Scanning dependencies of target foo
[100%] Building C object CMakeFiles/foo.dir/foo.c.o
Linking C executable foo
[100%] Built target foo
$ ./foo
Hello, world
$ # it’s up-to-date, so calling make again does nothing
$ make
[100%] Built target foo
$ Let’s change the C file
$ sed -i -e 's/Hello, world/Hello there, world/' foo.c
$ make
[ 33%] Generating foo.pch.h
Header not changed
Scanning dependencies of target foo
[ 33%] Generating foo.pch.h
Header not changed
[ 66%] Building C object CMakeFiles/foo.dir/foo.c.o
Linking C executable foo
[100%] Built target foo
$ # note that the precompiled header was *not* recompiled
$ ./foo
Hello there, world
$ # now let’s add a header file
$ sed -i -e $'s/stdio.h>/stdio.h>\\\n#include <stdlib.h>/' foo.c
$ make
[ 33%] Generating foo.pch.h
Header changed, updating
[ 66%] Generating foo.pch.h.gch
calling gcc
Scanning dependencies of target foo
[100%] Building C object CMakeFiles/foo.dir/foo.c.o
Linking C executable foo
[100%] Built target foo
$ # the precompiled header file *was* recompiled

Resources