什么是CMake等价于“gcc -fvisibility = hidden”当控制共享库的导出符号? [英] What is the CMake equivalent to "gcc -fvisibility=hidden" when controlling the exported symbol of a shared library?

查看:5088
本文介绍了什么是CMake等价于“gcc -fvisibility = hidden”当控制共享库的导出符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c ++中开发了跨平台软件。我知道,Linux .so默认导出所有符号,通过gcc -fvisibility = hidden我可以将所有导出的符号设置为隐藏,然后设置 __ attribute __(visibility(default))为我想导出的类和函数,所以我可以控制要导出的内容。

I developed cross platform software in c++. As I know, Linux .so exported all the symbols by default, well through "gcc -fvisibility=hidden" I can set all the exported symbols as hidden, then set __attribute__(visibility("default")) for the class and function I want to export, so I can control what I want to export.

我的问题是,使用CMake,我如何做gcc -fvisibility = hidden控件?

My question is, using CMake, how can I do the work as "gcc -fvisibility=hidden" control?

推荐答案

您可以向Cmake编译器添加一个标志:

You can add a flag to the Cmake compiler like that:

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")

要确保这仅在Linux下完成,您可以使用此代码:

To make sure that this only done under Linux you can use this code:

IF(UNIX)
    IF(CMAKE_COMPILER_IS_GNUCC)
         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
    ENDIF(CMAKE_COMPILER_IS_GNUCC)
ENDIF(UNIX)

这篇关于什么是CMake等价于“gcc -fvisibility = hidden”当控制共享库的导出符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆