View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015855CMakeCMakepublic2015-11-22 17:012016-05-02 08:30
ReporterRaphael Kubo da Costa 
Assigned ToBrad King 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSFreeBSDOS Version
Product VersionCMake 3.4 
Target VersionCMake 3.4.1Fixed in VersionCMake 3.4.1 
Summary0015855: "Disable shared library support when compiler links statically" forbids shared library builds with -nostdlib
DescriptionCommit 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 Reproducefoo.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.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0039901)
Brad King (manager)
2015-11-23 10:18

Thanks. We'll have to revert that commit and look for another solution to the problem it tried to address:

 Revert "Disable shared library support when compiler links statically"
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9682de56 [^]
(0039902)
Brad King (manager)
2015-11-23 10:19

I've queued this change for merge to the 'release' branch for inclusion in 3.4.1.
(0040966)
Robert Maynard (manager)
2016-05-02 08:30

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2015-11-22 17:01 Raphael Kubo da Costa New Issue
2015-11-23 09:47 Brad King Assigned To => Brad King
2015-11-23 09:47 Brad King Status new => assigned
2015-11-23 09:47 Brad King Target Version => CMake 3.4.1
2015-11-23 10:18 Brad King Note Added: 0039901
2015-11-23 10:19 Brad King Note Added: 0039902
2015-11-23 10:19 Brad King Status assigned => resolved
2015-11-23 10:19 Brad King Resolution open => fixed
2015-11-23 10:19 Brad King Fixed in Version => CMake 3.4.1
2016-05-02 08:30 Robert Maynard Note Added: 0040966
2016-05-02 08:30 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team