我正在尝试使用 cmake 和 mingw 交叉编译器从 debian 创建 *.deb 文件。使用 .CMake 时,CMake 的编译器测试失败dpkg-buildpackage
。
正常构建没问题:
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
-DCMAKE_VERBOSE_MAKEFILE=ON
-DCMAKE_BUILD_TYPE=None
-DCMAKE_INSTALL_SYSCONFDIR=/etc
-DCMAKE_INSTALL_LOCALSTATEDIR=/var
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /etc/alternatives/i686-w64-mingw32-gcc
-- Check for working C compiler: /etc/alternatives/i686-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /etc/alternatives/i686-w64-mingw32-g++
-- Check for working CXX compiler: /etc/alternatives/i686-w64-mingw32-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
但是,当我使用它构建它时,dpkg-buildpackage
它无法配置:
dpkg-buildpackage -uc -us
dpkg-buildpackage: info: source package foo
dpkg-buildpackage: info: source version 1.0
dpkg-buildpackage: info: source distribution stretch
dpkg-buildpackage: info: source changed by $USER
dpkg-buildpackage: info: host architecture amd64
dpkg-source --before-build hw
fakeroot debian/rules clean
dh clean --buildsystem=cmake --parallel
dh_testdir -O--buildsystem=cmake -O--parallel
dh_auto_clean -O--buildsystem=cmake -O--parallel
dh_clean -O--buildsystem=cmake -O--parallel
dpkg-source -b hw
dpkg-source: info: using source format '3.0 (native)'
dpkg-source: info: building sim-honeywell-ease-control in sim-honeywell-ease-control_1.0.tar.xz
dpkg-source: info: building sim-honeywell-ease-control in sim-honeywell-ease-control_1.0.dsc
debian/rules build
make: 'build' is up to date.
fakeroot debian/rules binary
dh binary --buildsystem=cmake --parallel
dh_testdir -O--buildsystem=cmake -O--parallel
dh_update_autotools_config -O--buildsystem=cmake -O--parallel
dh_auto_configure -O--buildsystem=cmake -O--parallel
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LOCALSTATEDIR=/var
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /etc/alternatives/i686-w64-mingw32-gcc
-- Check for working C compiler: /etc/alternatives/i686-w64-mingw32-gcc -- broken
CMake Error at /usr/share/cmake-3.7/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "/etc/alternatives/i686-w64-mingw32-gcc" is not able to
compile a simple test program.
完整日志中有趣的部分是链接期间的失败:
/etc/alternatives/i686-w64-mingw32-gcc -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-z,relro -Wl,--whole-archive CMakeFiles/cmTC_fc912.dir/objects.a -Wl,--no-whole-archive -o cmTC_fc912.exe -Wl,--out-implib,libcmTC_fc912.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/cmTC_fc912.dir/linklibs.rsp
/usr/bin/i686-w64-mingw32-ld: unrecognized option '-z'
mingw 链接器无法识别该-z
选项。当我diff
CMakeCache.txt 时,我可以看到 dpkg-buildpakcage 默认添加一些链接器标志:
< CMAKE_EXE_LINKER_FLAGS:STRING=-Wl,-z,relro
---
> CMAKE_EXE_LINKER_FLAGS:STRING=
我怎样才能防止dpkg-buildpackage
这样做?
仅供参考:我的debian/rules
文件如下所示:
#!/usr/bin/make -f
%:
dh $@ --buildsystem=cmake --parallel
答案1
您需要禁用relro
强化配置;改变你debian/rules
的
#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=-relro
%:
dh $@ --buildsystem=cmake --parallel
看联机dpkg-buildflags
帮助页了解详情。
(顺便说一句,如果您使用的是兼容级别 10 或更高版本,则不需要,--parallel
因为默认情况下已启用它。在许多情况下,您--buildsystem=cmake
也可以删除它,因为dh
系统会自动检测它。)