I try to use riscv64-unknown-elf-g++ which is rv64imac architecture to compile C code with rust static lib.
The simple example is https://github.com/zzhengzhuo/base_bin .
When I use riscv64-unknown-elf-gcc, it works well. But when I use riscv64-unknown-elf-g++, it reports errors like this:
riscv64-unknown-elf-g++ -Ibase_lib -v -o build/base_bin main.c base_lib/target/riscv64imac-unknown-none-elf/release/libbase_lib.a
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-g++
COLLECT_LTO_WRAPPER=/opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /home/zhengzhuo/riscv-gnu-toolchain/riscv-gcc/configure --target=riscv64-unknown-elf --prefix=/opt/riscv --disable-shared --disable-threads --enable-languages=c,c++ --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=.././riscv-gcc --enable-multilib --with-abi=lp64 --with-arch=rv64imac --with-tune=rocket 'CFLAGS_FOR_TARGET=-Os -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medlow'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 11.1.0 (GCC)
COLLECT_GCC_OPTIONS='-I' 'base_lib' '-v' '-o' 'build/base_bin' '-mtune=rocket' '-march=rv64imac' '-mabi=lp64' '-march=rv64imac' '-dumpdir' 'build/base_bin-'
/opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/cc1plus -quiet -v -I base_lib main.c -quiet -dumpdir build/base_bin- -dumpbase main.c -dumpbase-ext .c -mtune=rocket -march=rv64imac -mabi=lp64 -march=rv64imac -version -o /tmp/ccpwBEao.s
GNU C++17 (GCC) version 11.1.0 (riscv64-unknown-elf)
compiled by GNU C version 9.4.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/riscv/riscv64-unknown-elf/usr/local/include"
ignoring duplicate directory "/opt/riscv/riscv64-unknown-elf/include"
#include "..." search starts here:
#include <...> search starts here:
base_lib
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/include/c++/11.1.0
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/include/c++/11.1.0/riscv64-unknown-elf
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/include/c++/11.1.0/backward
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/include
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/include-fixed
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/include
End of search list.
GNU C++17 (GCC) version 11.1.0 (riscv64-unknown-elf)
compiled by GNU C version 9.4.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 70c8dfad8a0cf9a76df8ead2812f5775
COLLECT_GCC_OPTIONS='-I' 'base_lib' '-v' '-o' 'build/base_bin' '-mtune=rocket' '-march=rv64imac' '-mabi=lp64' '-march=rv64imac' '-dumpdir' 'build/base_bin-'
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/bin/as -v -I base_lib --traditional-format -march=rv64imac -march=rv64imac -mabi=lp64 -o /tmp/cc4pRmao.o /tmp/ccpwBEao.s
GNU assembler version 2.37 (riscv64-unknown-elf) using BFD version (GNU Binutils) 2.37
COMPILER_PATH=/opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/:/opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/:/opt/riscv/libexec/gcc/riscv64-unknown-elf/:/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/:/opt/riscv/lib/gcc/riscv64-unknown-elf/:/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/bin/
LIBRARY_PATH=/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/:/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/lib/:/opt/riscv/riscv64-unknown-elf/lib/
COLLECT_GCC_OPTIONS='-I' 'base_lib' '-v' '-o' 'build/base_bin' '-mtune=rocket' '-march=rv64imac' '-mabi=lp64' '-march=rv64imac' '-dumpdir' 'build/base_bin.'
/opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/collect2 -plugin /opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/liblto_plugin.so -plugin-opt=/opt/riscv/libexec/gcc/riscv64-unknown-elf/11.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccQyuKYm.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgloss -plugin-opt=-pass-through=-lgcc --sysroot=/opt/riscv/riscv64-unknown-elf -melf64lriscv -o build/base_bin /opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/lib/crt0.o /opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/crtbegin.o -L/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0 -L/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/lib -L/opt/riscv/riscv64-unknown-elf/lib /tmp/cc4pRmao.o base_lib/target/riscv64imac-unknown-none-elf/release/libbase_lib.a -lstdc++ -lm -lgcc --start-group -lc -lgloss --end-group -lgcc /opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/crtend.o
/opt/riscv/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/bin/ld: /tmp/cc4pRmao.o: in function `.L0 ':
main.c:(.text+0xa): undefined reference to `echo(unsigned int)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:5: build/base_bin] Error 1
Thanks for any help.
Adding extern "C" in the header file will work, more details see What is the effect of extern "C" in C++? .
related to https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1021.
Thanks for everyone helped me.
Related
I installed cross-compilation tools on my Ubuntu system using:
sudo apt-get install gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi
And then i made simple .c file which compiles ok, but when gcc runs assembler stage, it is for unknown reason invokes 'as' command, instead of appropriate 'arm-linux-gnueabi-as' command and as result compilation fails with following errors:
arm-linux-gnueabi-gcc -v test.c
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/6/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armel-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armel-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armel-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 6.3.0 20170406 (Ubuntu/Linaro 6.3.0-12ubuntu2)
COLLECT_GCC_OPTIONS='-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/6/cc1 -quiet -v -imultiarch arm-linux-gnueabi test.c -quiet -dumpbase test.c -march=armv5t -mfloat-abi=soft -mtls-dialect=gnu -auxbase test -version -fstack-protector-strong -Wformat -Wformat-security -o /tmp/cccUVSll.s
GNU C11 (Ubuntu/Linaro 6.3.0-12ubuntu2) version 6.3.0 20170406 (arm-linux-gnueabi)
compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/lib/gcc-cross/arm-linux-gnueabi/6/../../../../arm-linux-gnueabi/include"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-cross/arm-linux-gnueabi/6/include
/usr/lib/gcc-cross/arm-linux-gnueabi/6/include-fixed
/usr/include
End of search list.
GNU C11 (Ubuntu/Linaro 6.3.0-12ubuntu2) version 6.3.0 20170406 (arm-linux-gnueabi)
compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 50226affb1339dba25cfdfb2ad79e687
COLLECT_GCC_OPTIONS='-v' '-march=armv5t' '-mfloat-abi=soft' '-mtls-dialect=gnu'
as -v -march=armv5t -mfloat-abi=soft -meabi=5 -o /tmp/cczGBXSH.o /tmp/cccUVSll.s
GNU assembler version 2.28 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.28
Assembler messages:
Fatal error: invalid -march= option: `armv5t'
As you can see, it fails, because it invoking wrong command - as, which knows only about x86_64-linux-gnu target, and does not recognizing armv5t architecture option.
How to force gcc toolchain to use correct cross-platform assembler/linker to produce binary, instead of 'as' 'ld' etc?
Is there something in my environment, that causing such behavior?
P.S. On my college's machine, installing same toolchain works without problem, however he has Ubuntu 16.04, while mine are 17.04..
And GCC executing following command for assembler:
/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/bin/as
-v -march=armv5t -mfloat-abi=soft -meabi=5 -o /tmp/ccXru9b3.o /tmp/ccUwNPuq.s
As you can see, it takes right assembler and all is ok.. but not on my system..
I'm trying to compile the following program with gcc 4.8.2 on Ubuntu 14.04.1
with the package libsqlite3-dev installed:
#include <sqlite3.h>
int main(int argc, char *argv[])
{
struct sqlite3 *s3;
char *filename = ":memory:";
sqlite3_open(filename, &s3);
return 0;
}
When running gcc -L/usr/lib/x86_64-linux-gnu -lsqlite3 program.c I get
the error:
/tmp/ccjvJqkW.o: In function `main':
program.c:(.text+0x26): undefined reference to `sqlite3_open'
collect2: error: ld returned 1 exit status
It looks to me like I have the correct library installed:
autobound#Calcium:~$ locate libsqlite3.so
/usr/lib/i386-linux-gnu/libsqlite3.so.0
/usr/lib/i386-linux-gnu/libsqlite3.so.0.8.6
/usr/lib/x86_64-linux-gnu/libsqlite3.so
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
autobound#Calcium:~$ readelf -a /usr/lib/x86_64-linux-gnu/libsqlite3.so | grep sqlite3_open
71: 00000000000947b0 5 FUNC GLOBAL DEFAULT 11 sqlite3_open_v2
157: 00000000000947a0 12 FUNC GLOBAL DEFAULT 11 sqlite3_open
194: 00000000000947c0 181 FUNC GLOBAL DEFAULT 11 sqlite3_open16
Running clang with the same arguments (clang -L/usr/lib/x86_64-linux-gnu -lsqlite3 program.c)
builds the executable just fine. In fact, the -L argument isn't even
needed for clang to build it.
The verbose output of gcc is:
autobound#Calcium:~/src/c/sqlitetest (master)$ gcc --verbose -L/usr/lib/x86_64-linux-gnu -lsqlite3 program.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
COLLECT_GCC_OPTIONS='-v' '-L/usr/lib/x86_64-linux-gnu' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.8/cc1 -quiet -v -imultiarch x86_64-linux-gnu program.c -quiet -dumpbase program.c -mtune=generic -march=x86-64 -auxbase program -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccIBEqw6.s
GNU C (Ubuntu 4.8.2-19ubuntu1) version 4.8.2 (x86_64-linux-gnu)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C (Ubuntu 4.8.2-19ubuntu1) version 4.8.2 (x86_64-linux-gnu)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dc75e0628c9356affcec059d0c81cc01
COLLECT_GCC_OPTIONS='-v' '-L/usr/lib/x86_64-linux-gnu' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/cca2r2gq.o /tmp/ccIBEqw6.s
GNU assembler version 2.24 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-L/usr/lib/x86_64-linux-gnu' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -lsqlite3 /tmp/cca2r2gq.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
/tmp/cca2r2gq.o: In function `main':
program.c:(.text+0x26): undefined reference to `sqlite3_open'
collect2: error: ld returned 1 exit status
Try to change order of parameters
gcc program.c -L/usr/lib/x86_64-linux-gnu -lsqlite3
I'm trying to compile a library on Ubuntu 14.04 with packages gcc-arm-linux-gnueabi and g++-arm-linux-gnueabi installed.
The compile fails on the first source file it encounters:
/usr/bin/arm-linux-gnueabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -I. -DCRYPTOPP_DISABLE_ASM
-mcpu=cortex-m3 -mthumb --sysroot=/usr/arm-linux-gnueabi -c 3way.cpp
In file included from cryptlib.h:83:0,
from seckey.h:8,
from 3way.h:7,
from 3way.cpp:5:
stdcpp.h:14:18: fatal error: memory: No such file or directory
compilation terminated.
Here's what the include line looks like in cryptlib.h:
#ifndef CRYPTOPP_CRYPTLIB_H
#define CRYPTOPP_CRYPTLIB_H
#include "config.h"
#include "stdcpp.h"
...
Obviously, stdcpp.h exists:
$ pwd
/home/jwalton/cryptopp-embedded
$ ls 3way.h cryptlib.h stdcpp.h
3way.h cryptlib.h stdcpp.h
Adding -v shows:
...
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/include"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include
...
End of search list.
I've cross compiled the library on other platforms (like Android, iOS and Windows Phone), so I have a good idea of what needs to be done. This is my first time with arm-linux-gnueabi, however.
Why is arm-linux-gnueabi skipping the header in the present working directory? How can I resolve the issue?
Full output from arm-linux-gnueabi-g++ -v:
/usr/bin/arm-linux-gnueabi-g++ -v -DNDEBUG -g2 -Os -pipe -fPIC -I. -DCRYPTOPP_DISABLE_ASM
-mcpu=cortex-m3 -mthumb --sysroot=/usr/arm-linux-gnueabi -c 3way.cpp
Using built-in specs.
COLLECT_GCC=/usr/bin/arm-linux-gnueabi-g++
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-12ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++
--prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.7.3
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-gnu-unique-object
--disable-libmudflap --disable-libitm --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog
--enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --enable-multilib
--disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueab --program-prefix=arm-linux-gnueabi-
--includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1)
COLLECT_GCC_OPTIONS='-v' '-D' 'NDEBUG' '-g2' '-Os' '-pipe' '-fPIC' '-I' '.' '-D' 'CRYPTOPP_DISABLE_ASM'
'-mcpu=cortex-m3' '-mthumb' '-c' '-shared-libgcc' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/cc1plus -quiet -v -I . -imultilib sf -imultiarch
arm-linux-gnueabi
-isysroot /usr/arm-linux-gnueabi -D_GNU_SOURCE -D NDEBUG -D CRYPTOPP_DISABLE_ASM
3way.cpp -quiet
-dumpbase 3way.cpp -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -mtls-dialect=gnu -auxbase 3way
-g2 -Os -version -fPIC -fstack-protector -o - |
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/as -v -I . -mcpu=cortex-m3
-mfloat-abi=soft -meabi=5 -o 3way.o
GNU assembler version 2.24 (arm-linux-gnueabi) using BFD version (GNU Binutils for Ubuntu) 2.24
GNU C++ (Ubuntu/Linaro 4.7.3-12ubuntu1) version 4.7.3 (arm-linux-gnueabi)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabi/sf"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/arm-linux-gnueabi/include/c++/4.7.3/backward"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/arm-linux-gnueabi/usr/include"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/include-fixed
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.7.3-12ubuntu1) version 4.7.3 (arm-linux-gnueabi)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dd2bb0d8e9ec09589fb3eaca028d0191
In file included from cryptlib.h:83:0,
from seckey.h:8,
from 3way.h:7,
from 3way.cpp:5:
stdcpp.h:14:18: fatal error: memory: No such file or directory
compilation terminated.
make: *** [3way.o] Error 1
stdcpp.h:14:18: fatal error: memory: No such file or directory
Arg... The missing header is memory, and not stdcpp.h. (Damn C++ header names...).
And the un-found <memory> appears to be a bug in Ubuntu's g++arm-linux-gnueabi: g++-arm-linux-gnueabi cannot compile a C++ program with --sysroot.
I am trying to use several programs for watershed generation, genericaly called TOPAZ, from
ftp://solar1.msa-oxford.ars.usda.gov/pub/outgoing/TOPAZ/TOPAZ312/Ascii/
the source code is available, so everybody can try
The code is not mine, and i thank publicly here to the authors for their work.
Machine for development is debian 6.0.8, kernel 2.6.32-5-amd64
The source code of all programs conforms strictly to FORTRAN 90 standards, acording to the documentation.
installed gfortran, and when compiling i get
root#geo:/usr/src/topaz.src/tmp# gfortran -v DEDNM.F90
Driving: gfortran -v DEDNM.F90 -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/f951 DEDNM.F90 -cpp /tmp/ccLDYiVO.f90 -quiet -v DEDNM.F90 -quiet -dumpbase DEDNM.F90 -mtune=generic -auxbase DEDNM -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-linux-gnu/4.4.5/finclude -o /tmp/ccy4DOzn.s
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/finclude
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include-fixed
/usr/include
End of search list.
GNU Fortran (Debian 4.4.5-8) version 4.4.5 (x86_64-linux-gnu)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3.
GGC heuristics: --param ggc-min-expand=55 --param ggc-min-heapsize=47475
DEDNM.F90:12415.1:
\x1A
1
Error: Invalid character in name at (1)
i get a similar error on compiling the other programs,
the source is ANSI Standard Fortran90, acording to documentation
i don't know much of fortran, but i would like to use a linux machine rather than going back to windows, and so need to compile the programs instead of using precompliled ones for win95
many thanks
André
I have 3 different machines with the following configurations:
OpenSuSe 12.1, linux kernel 3.1.10, gcc 4.6.2
Debian 6, linux kernel 2.6.32, gcc 4.4.5
CentOS 5.6, linux kernel 2.6.18, gcc 4.1.2
All their architectures are x86_64. Note that CentOS' software versions are older than Debian's, but versions of OpenSuSe software are newer than Debian's versions.
And I have the following example code:
#include <cstdio>
#include <cstdlib>
unsigned int cols=5;
unsigned int rows=6;
int main()
{
//allocating...
double **mat=new double*[rows];
double *col=new double[rows];
for(unsigned int i=0;i<rows;++i)
{
mat[i]=new double[cols];
}
//filling with something...
for(unsigned int i=0;i<rows;++i)
{
for(unsigned int j=0;j<cols;++j)
{
mat[i][j]=i+j;
}
}
//testing...
unsigned long long sum,add;
for(unsigned int i=0;i<cols;++i)
{
sum=0;
for(unsigned int j=0;j<rows;++j)
{
col[j]=mat[j][i];
add=*((unsigned long long*) (&(col[j])));
sum+=add;
}
printf("%llu\n",sum);
}
return 0;
}
If I compile this code without any options:
g++ code.cpp
it runs in the same way on all machines.
But if I compile it with -O2, it behaves in the same way on the 1st and the 3rd machines, but on the 2nd machine (Debian) the -O2 optimization breaks it.
This is the output of this code on the 1st machine with -O2:
4619567317775286272
9238008735643729920
9250393634618998784
9259400833873739776
9266719183268216832
And this is on the 2nd machine with -O2:
0
4619567317775286272
9238008735643729920
9250393634618998784
9259400833873739776
The output of the second machine looks like the 1st' output, shifted down by one line.
If I replace (&(col[j])) with (&(mat[j][i])), the code begins to work normaly.
Here is the compiler's output on the 2nd machine with -v and -O2 options:
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
COLLECT_GCC_OPTIONS='-v' '-O2' '-shared-libgcc' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/cc1plus -quiet -v -D_GNU_SOURCE dmtest.cpp -quiet -dumpbase dmtest.cpp -mtune=generic -auxbase dmtest -O2 -version -o /tmp/cc6v7CNY.s
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.4
/usr/include/c++/4.4/x86_64-linux-gnu
/usr/include/c++/4.4/backward
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include-fixed
/usr/include
End of search list.
GNU C++ (Debian 4.4.5-8) version 4.4.5 (x86_64-linux-gnu)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5a2e15051eaa06a84cf6320b754ba993
COLLECT_GCC_OPTIONS='-v' '-O2' '-shared-libgcc' '-mtune=generic'
as -V -Qy -o /tmp/ccL37GHG.o /tmp/cc6v7CNY.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.20.1-system.20100303
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-O2' '-shared-libgcc' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/collect2 --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../.. /tmp/ccL37GHG.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crtn.o
What's the reason of such behavior? Is my code incorrect or it's a bug in gcc 4.4.5?
This is type punning and it is therefore undefined behavior. I'm surprised you're not getting warnings about it.
It normally works the way you expect, of course, but it is still undefined behavior.
To get around the undefined behavior part you can cast to a char * and read each byte in succession. Does this fix the behavior you are seeing?
According to this blog entry, GCC 4.4 enforces strict aliasing rules for -O2. The type-punning access therefore results in undefined behaviour. Unfortunately, in order to get warnings for breaking strict aliasing rules, you have to compile with -Wstrict-aliasing.
Maybe the newer versions of GCC have reverted to the old behaviour and leave the decision whether to enable strict aliasing to the user.