[cmake-developers] [CMake 0015855]: "Disable shared library support when compiler links statically" forbids shared library builds with -nostdlib
Mantis Bug Tracker
mantis at public.kitware.com
Sun Nov 22 17:01:36 EST 2015
The following issue has been SUBMITTED.
======================================================================
https://cmake.org/Bug/view.php?id=15855
======================================================================
Reported By: Raphael Kubo da Costa
Assigned To:
======================================================================
Project: CMake
Issue ID: 15855
Category: CMake
Reproducibility: always
Severity: major
Priority: normal
Status: new
======================================================================
Date Submitted: 2015-11-22 17:01 EST
Last Modified: 2015-11-22 17:01 EST
======================================================================
Summary: "Disable shared library support when compiler links
statically" forbids shared library builds with -nostdlib
Description:
Commit 8b4873a1b025d7f47c90f3cafc93ca152b9e4652 ("Disable shared library support
when compiler links statically") introduced a check in
Modules/CMakeDetermineCompilerId.cmake that ends up running file(1) on the
compiler itself and assumes it cannot generate shared libraries if file(1) says
the compiler was statically linked.
This breaks builds if one passes "-nostdlib" in C{XX}FLAGS and there's an
ADD_LIBRARY(... SHARED ...) target:
CMake Warning (dev) at CMakeLists.txt:3 (add_library):
ADD_LIBRARY called with SHARED option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
This happens because if -nostdlib is passed, as running the binary produced by
CMakeC{XX}CompilerId.c{pp}.in in will be statically linked (and crash on
startup, even though it is not relevant here).
On FreeBSD, this breaks the build of ports (packages) such as libcxxrt, which,
being a very low-level library that provides features to a compiler, needs to be
built with -nostdlib. This is not limited to FreeBSD, however, as the same
file(1) returns a false-positive on Linux as well.
Steps to Reproduce:
foo.c:
int foo(void) { return 42; }
CMakeLists.txt:
project(foo)
cmake_minimum_required(VERSION 3.4)
add_library(foo SHARED foo.c)
It will produce libfoo.a, not libfoo.so.
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2015-11-22 17:01 Raphael Kubo da CostaNew Issue
======================================================================
More information about the cmake-developers
mailing list