download the sources and build expdef.exe
i686-w64-mingw32-g++-win32 -static -m32 -Wall -O2 -o expdef.exe expdef.cpp
generate the .def and the libsomething.dll.a implib
wine ./expdef.exe -p -o something.dll >something.def
i686-w64-mingw32-dlltool --no-leading-underscore -d something.def -D something.dll -l libsomething.dll.a
if something.dll use stdcall
convention the sources need to prefix the prototype declarations with [[gnu::stdcal]]
[[gnu::stdcall]] void *SomeFunctionInSomething(void);
build and link the executable
i686-w64-mingw32-g++-win32 -Wall -O2 -I./include -o someprogram.exe someprogram.cpp -L. -lsomething
That’s it.
git clone https://github.com/crosstool-ng/crosstool-ng.git
cd crosstool-ng
./bootstrap
./configure --prefix=$HOME/install/crosstool-ng
make install
echo 'export PATH="${PATH}:$HOME/install/crosstool-ng/bin"' >>~/install/crosstool-ng/crosstool-ng.env
. ./install/crosstool-ng/crosstool-ng.env
mkdir -p ~/workdir
cd ~/workdir
ct-ng list-samples
ct-ng i686-ubuntu16.04-linux-gnu
ct-ng menuconfig
nice -19 ct-ng build.4
ls ~/x-tools/i686-xg-linux-gnu/
In a old post I wrote where to get and how to use a gcc cross toolchain to compile from a pc host to a raspberry target.
Here how to use distcc
on target raspberry (and distccd
on pc host) to build faster over a distributed network (a cross toolchain installed on network nodes is a prerequisite).
Assuming the pc have ip address 192.168.1.210
and pi 192.168.1.2
, on the host:
pc host $ cd $HOME/toolchains/raspberry-pi
pc host $ export PATH=$PWD/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/libexec/gcc/arm-linux-gnueabihf/4.8.3:$PATH
pc host $ export PATH=$PWD/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/bin:$PATH
pc host $ distccd --daemon --jobs 8 --allow 192.168.1.2 --verbose --log-stderr --no-detach
Using --no-detach
the process will sleep listening for connections and eventually log on stdout, on pi:
pi target $ export DISTCC_HOSTS="192.168.1.210"
pi target $ CC="distcc gcc" CXX="distcc g++" cmake -DCMAKE_BUILD_TYPE=release
pi target $ make -j4
DISTCC_HOSTS
support more machines (see distcc documentation for more options) Here I’m using --jobs 8
on distccd side and only -j4
on distcc side. The drawbacks are that not all packages support CC
and CXX
variables from env correctly, as not every package support a parallel build.
An alternative to pass CC CXX
is to use the environment PATH
variable (export PATH=/usr/lib/ccache:/usr/lib/distcc:$PATH
) to specify a directory which should contain symlinks (eg: gcc -> ../../bin/ccache
or clang++-4.0 -> ../../distcc
), the name of the symlink should match the invoked compiler and point to the real executables of ccache and distcc.
One feature not so known about gcc are specs
files
gcc -dumpspecs >spec
output the built-in specs file
If we need to add some option, compile/link flag to be used always or on some condition we can add it to the dumped spec file, example:
*link:
-rpath /opt/someroot/lib
add always the rpath to the link options, we can try the spec file with the command line:
gcc -specs=spec test.c
readelf -d a.out |grep RPATH
on startup gcc/g++ look for a spec file on the filesystem, we can guess the full path with strace
and grep
:
strace -fF -o /tmp/g++.log g++ test.cpp
grep specs /tmp/g++.log
if we build our toolchain we can add a configure option --with-specs=
, the argument is a spec code, it isn’t shown on -dumpspecs
but will be used, example:
--with-specs="%{shared:-Wl,-rpath -Wl,$(DESTDIR)/lib}%{!shared:-Wl,-rpath -Wl,$(DESTDIR)/lib}"
Debianizzando ts – task spooler che già utilizza di suo dei cflags molto rigidi
-pedantic -ansi -Wall -D_XOPEN_SOURCE=500 -D__STRICT_ANSI__
mi sono accorto che Debian ne usa ancora di più verbosi e le informazion che generano possono essere interessanti
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security