View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015556CMakeCMakepublic2015-05-06 06:112016-02-01 09:10
ReporterKjell Irgens 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformFedoraOSLinuxOS Version4.0
Product VersionCMake 3.2.1 
Target VersionCMake 3.3Fixed in VersionCMake 3.3 
Summary0015556: CMAKE_<lang>_VISIBILITY_PRESET not used when compiling static libraries
DescriptionWhen compiling a STATIC library the -fvisibility=hidden compiler flag is not set to gcc when compiling.

Why is this a problem? I am linking the resulting static library into another SHARED library, and I want the symbols defined in the link library to be hidden, which is why I used CMAKE_CPP_VISIBILITY_PRESET in the first place.

https://gcc.gnu.org/wiki/Visibility [^]
"In your build system (Makefile etc), you will probably wish to add the -fvisibility=hidden and -fvisibility-inlines-hidden options to the command line arguments of every GCC invocation"

The workaround is to add -fvisibility=HIDDEN as to COMPILE_FLAGS.
Steps To Reproduceset (CMAKE_C_VISIBILITY_PRESET hidden)

add_library (mplug STATIC test.c)

make VERBOSE=1
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0038719)
Robert Maynard (manager)
2015-05-06 08:44

As far as I am aware the visibility flags have no effect on static libraries since there is no real 'linking' step.
(0038720)
Kjell Irgens (reporter)
2015-05-06 10:04

Too bad, as -fvisibility definitely have an effect on building object files
(command line arguments of *every* GCC invocation)

I just found out that it also does not seem to have any effect when building a MODULE, although I have not testet this properly.
(0038723)
Brad King (manager)
2015-05-06 14:02

For reference, the code that decides whether to add flags based on the target type is here:

 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmLocalGenerator.cxx;hb=v3.2.2#l2369 [^]

As of CMake 3.2.2 it adds them for SHARED and MODULE libraries and executables with ENABLE_EXPORTS set.
(0038750)
Kjell Irgens (reporter)
2015-05-15 04:45

You are right, it works for MODULE. The original problem remains though.
(0038799)
Brad King (manager)
2015-05-26 09:25

I added a policy to enable this for all target types in a compatible way:

 Honor visibility properties for all target types
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=700f1c3b [^]
(0040402)
Robert Maynard (manager)
2016-02-01 09:10

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

 Issue History
Date Modified Username Field Change
2015-05-06 06:11 Kjell Irgens New Issue
2015-05-06 08:44 Robert Maynard Note Added: 0038719
2015-05-06 10:04 Kjell Irgens Note Added: 0038720
2015-05-06 14:02 Brad King Note Added: 0038723
2015-05-15 04:45 Kjell Irgens Note Added: 0038750
2015-05-26 09:25 Brad King Note Added: 0038799
2015-05-26 09:25 Brad King Assigned To => Brad King
2015-05-26 09:25 Brad King Status new => resolved
2015-05-26 09:25 Brad King Resolution open => fixed
2015-05-26 09:25 Brad King Fixed in Version => CMake 3.3
2015-05-26 09:25 Brad King Target Version => CMake 3.3
2016-02-01 09:10 Robert Maynard Note Added: 0040402
2016-02-01 09:10 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team