How to hide the exporting of some symbols in CMake while linking a C++ shared library for AIX platform

1.2k Views Asked by At

I am building a shared library on AIX using XLC compiler which depends on a static library. The issue am facing is the shared library built is exporting some of the symbols of the static libary which should be hidden. I noticed that, in the linker command if I directly specify the library instead of using -L <path_to_lib> -l then the symbols are exported as expected, But if I link like ../../some_path/libxyz.a then it exports many symbols when most of them should be hidden.

With the below command the libabc.so exports some of the symbols of libxyz.a which should be hidden

/usr/bin/xlC_r -q64 -qthreaded -qhalt=s -O -DNDEBUG -Wl,-brtl -G -Wl,-bnoipath -o abc.so <path>/abc.cpp.o <path-to-lib>/libxyz.a

With the below command the symbols stay hidden as expected

/usr/bin/xlC_r -q64 -qthreaded -qhalt=s -O -DNDEBUG -Wl,-brtl -G -Wl,-bnoipath -o abc.so <path>/abc.cpp.o -L<path-to-lib> -lxyz

I have two questions here

  1. What is the difference when we link the file directly as "/libxyz.a" vs when we link as "-L -l"

  2. My CMakeLists.txt looks like the following.

    add_library(abc SHARED src/abc.cpp)

    target_link_options(abc )

    target_link_libraries( abc PRIVATE xyz::xyz)

Here abc is the file shared library that am building and xyz::xyz is cmake target for libxyz.a which is a dependency.

With these Cmake rules the linker command expands to

 /usr/bin/xlC_r -q64 -qthreaded -qhalt=s -O -DNDEBUG -Wl,-brtl -G -Wl,-bnoipath -o abc.so <path>/abc.cpp.o <path-to-lib>/libxyz.a

How to Achieve this kind of linking using Cmake

/usr/bin/xlC_r -q64 -qthreaded -qhalt=s -O -DNDEBUG -Wl,-brtl -G -Wl,-bnoipath -o abc.so <path>/abc.cpp.o -L<path-to-lib> -lxyz
0

There are 0 best solutions below