Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting hidden symbol error while linking in static libraries but not in shared libraries
QtWS25 Last Chance

Getting hidden symbol error while linking in static libraries but not in shared libraries

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 15.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    up vote
    0
    down vote
    favorite
    I went through the Error while linking a static library of Qt libQtCore.a and What does exactly the warning mean about hidden symbol being referenced by DSO? but could not get a proper solution

    When I build static libraries of libQtGui and libQtCore CXXFLAGS -fvisibility=hidden is used for compiling each file of QtCore and QtGui. When I link this library in my final executable , then I get following

    hidden symbol `_ZNK7QLayout11minimumSizeEv' is referenced by DSO linking ld: final link failed: Bad value

    What is correct solution to remove the linking error hidden symbol `_ZNK7QLayout11minimumSizeEv' is referenced by DSO is referenced by DSO

    Also I have a query I make shared library with the same code base of QtCore and QtGui and also CXXFLAGS -fvisibility=hidden and when I link the shared libraries libQtCore.so and libQtGui.so in my final executable then it works fine and I do not get any linker error

    kshegunovK 1 Reply Last reply
    0
    • Q Qt Enthusiast

      up vote
      0
      down vote
      favorite
      I went through the Error while linking a static library of Qt libQtCore.a and What does exactly the warning mean about hidden symbol being referenced by DSO? but could not get a proper solution

      When I build static libraries of libQtGui and libQtCore CXXFLAGS -fvisibility=hidden is used for compiling each file of QtCore and QtGui. When I link this library in my final executable , then I get following

      hidden symbol `_ZNK7QLayout11minimumSizeEv' is referenced by DSO linking ld: final link failed: Bad value

      What is correct solution to remove the linking error hidden symbol `_ZNK7QLayout11minimumSizeEv' is referenced by DSO is referenced by DSO

      Also I have a query I make shared library with the same code base of QtCore and QtGui and also CXXFLAGS -fvisibility=hidden and when I link the shared libraries libQtCore.so and libQtGui.so in my final executable then it works fine and I do not get any linker error

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Qt-Enthusiast said in Getting hidden symbol error while linking in static libraries but not in shared libraries:

      What does exactly the warning mean about hidden symbol being referenced by DSO?

      It says it all: you're referencing a hidden symbol when linking a dynamic shared object (DSO), which isn't allowed.

      When I build static libraries of libQtGui and libQtCore CXXFLAGS -fvisibility=hidden is used for compiling each file of QtCore and QtGui.

      Visibility isn't applicable to static libraries (archives).

      What is correct solution to remove the linking error hidden symbol `_ZNK7QLayout11minimumSizeEv' is referenced by DSO is referenced by DSO

      Without knowing where this exactly comes from, there's no way to say. Provide the full link line that generates this error.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        The following code also reproduces the same issue

        File : my_lib.h

        1. /* Filename: lib_mylib.h */

        int fun();

        1. Filename : my_lib.c
        • Filename: lib_mylib.c */
          #include <stdio.h>
          int fun() {
          return 2;
          }

        File 3) my_lib_shared.h
        int foo();

        File4
        #include "my_lib.h"

        int foo(void) {
        return fun() + 4;
        }

        and following steps produces same error

        gcc -g -fvisibility=hidden -c my_lib.c -o lib_mylib.o
        ar rcs libMylib_static_hidden.a lib_mylib.o
        gcc -g -fvisibility=hidden -c -fPIC my_lib_shared.c -o my_lib_shared.o
        gcc -g -shared -o libMyShare.so my_lib_shared.o
        gcc -g driver.c -L . -lMylib_static_hidden -lMyShare

        kshegunovK 1 Reply Last reply
        0
        • Q Qt Enthusiast

          The following code also reproduces the same issue

          File : my_lib.h

          1. /* Filename: lib_mylib.h */

          int fun();

          1. Filename : my_lib.c
          • Filename: lib_mylib.c */
            #include <stdio.h>
            int fun() {
            return 2;
            }

          File 3) my_lib_shared.h
          int foo();

          File4
          #include "my_lib.h"

          int foo(void) {
          return fun() + 4;
          }

          and following steps produces same error

          gcc -g -fvisibility=hidden -c my_lib.c -o lib_mylib.o
          ar rcs libMylib_static_hidden.a lib_mylib.o
          gcc -g -fvisibility=hidden -c -fPIC my_lib_shared.c -o my_lib_shared.o
          gcc -g -shared -o libMyShare.so my_lib_shared.o
          gcc -g driver.c -L . -lMylib_static_hidden -lMyShare

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Qt-Enthusiast
          Make the symbol visible (which is equivalent to exporting it on Windows) and you won't have the error any more.

          Read and abide by the Qt Code of Conduct

          Q 1 Reply Last reply
          1
          • kshegunovK kshegunov

            @Qt-Enthusiast
            Make the symbol visible (which is equivalent to exporting it on Windows) and you won't have the error any more.

            Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by Qt Enthusiast
            #5

            my questions when I make static libraries as shared , then I do not get this linking error why ? Is there other flag which removes the visibilty. How to check the symbols are hidden in a shared library ?

            1 Reply Last reply
            0
            • kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              my questions when I make static libraries as shared , then I do not get this linking error why ?

              By default on Linux all (non-static) symbols will be exported (marked visible) from a shared object (dynamic library).

              Is there other flag which removes the visibilty.

              Not while compiling or linking, but you can set an attribute for individual symbols. For example (ELF ABI, Linux, GCC only):

              __attribute__((visibility ("hidden"))) void hiddenSymbol(int arg1, float arg2);
              

              How to check the symbols are hidden in a shared library ?

              Try this post.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by
                #7

                Not very clear

                I have do

                gcc -g -fvisibility=hidden -c my_lib.c -o lib_mylib.o
                gcc -g -shared -o libHiddemMyLib.so lib_mylib.o
                gcc -g -fvisibility=hidden -c -fPIC my_lib_shared.c -o my_lib_shared.o
                gcc -g -shared -o libMyShare.so my_lib_shared.o
                gcc -g driver.c -L . -lHiddemMyLib -lMyShare

                I do not get this library error why but for static librarries I get this hidden error ? not clear to me yet

                kshegunovK 1 Reply Last reply
                0
                • Q Qt Enthusiast

                  Not very clear

                  I have do

                  gcc -g -fvisibility=hidden -c my_lib.c -o lib_mylib.o
                  gcc -g -shared -o libHiddemMyLib.so lib_mylib.o
                  gcc -g -fvisibility=hidden -c -fPIC my_lib_shared.c -o my_lib_shared.o
                  gcc -g -shared -o libMyShare.so my_lib_shared.o
                  gcc -g driver.c -L . -lHiddemMyLib -lMyShare

                  I do not get this library error why but for static librarries I get this hidden error ? not clear to me yet

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @Qt-Enthusiast said in Getting hidden symbol error while linking in static libraries but not in shared libraries:

                  Not very clear

                  What's that?

                  I do not get this library error why but for static librarries I get this hidden error ?

                  The symbols in the so aren't hidden, so you don't get the error (see first comment of my previous post). The symbols in the archive are marked as hidden, because you've marked them as such, thus you get the errors.

                  As a word of advice, don't mix up flags for the compiler if you don't know what you're doing. Either go all in and mark everything -fvisibility=hidden or don't and leave the symbols with their default visibility.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by Qt Enthusiast
                    #9

                    with same files

                    The following code also reproduces the same issue

                    File : my_lib.h

                    /* Filename: lib_mylib.h */
                    int fun();

                    Filename : my_lib.c
                    Filename: lib_mylib.c */
                    #include <stdio.h>
                    int fun() {
                    return 2;
                    }
                    File 3) my_lib_shared.h
                    int foo();

                    File4
                    #include "my_lib.h"

                    int foo(void) {
                    return fun() + 4;
                    }

                    gcc -fvisibility=hidden -fPIC -c my_lib.c -o lib_mylib.o
                    gcc -fvisibility=hidden -shared -o libMyLibHidden.so lib_mylib.o
                    gcc -fPIC -c my_lib_shared.c -o my_lib_shared.o
                    gcc -shared -o libMyShared2.so my_lib_shared.o
                    gcc -L. -Wall -o test_hidden driver.c -lMyLibHidden -lMyShared2

                    when I do a

                    objdump -T libMyLibHidden.so

                    libMyLibHidden.so: file format elf64-x86-64

                    DYNAMIC SYMBOL TABLE:
                    0000000000000448 l d .init 0000000000000000 .init
                    0000000000000000 w D UND 0000000000000000 gmon_start
                    0000000000000000 w D UND 0000000000000000 _Jv_RegisterClasses
                    0000000000000658 g DF .fini 0000000000000000 Base _fini
                    0000000000000000 w D UND 0000000000000000 _ITM_deregisterTMCloneTable
                    0000000000000000 w D UND 0000000000000000 _ITM_registerTMCloneTable
                    0000000000000000 w DF UND 0000000000000126 GLIBC_2.2.5 __cxa_finalize
                    0000000000200938 g D ABS 0000000000000000 Base __bss_start
                    0000000000200948 g D ABS 0000000000000000 Base _end
                    0000000000200938 g D ABS 0000000000000000 Base _edata
                    0000000000000448 g DF .init 0000000000000000 Base _init

                    I do not get any reference of fun, fun1 and fun2 and I get error has
                    [3382] source script_hidden
                    /tmp/cciyfmzL.o: In function main': driver.c:(.text+0xe): undefined reference to fun'
                    collect2: error: ld returned 1 exit status

                    but When I do

                    gcc -fPIC -c my_lib.c -o lib_mylib.o
                    gcc -fvisibility=hidden -shared -o libMyLibHidden.so lib_mylib.o
                    gcc -fPIC -c my_lib_shared.c -o my_lib_shared.o
                    gcc -shared -o libMyShared2.so my_lib_shared.o
                    gcc -L. -Wall -o test_hidden driver.c -lMyLibHidden -lMyShared2

                    I get reference of fun, fun1 but the hidden visibility is supprresed
                    objdump -T libMyLibHidden.so

                    libMyLibHidden.so: file format elf64-x86-64

                    DYNAMIC SYMBOL TABLE:
                    00000000000004a8 l d .init 0000000000000000 .init
                    0000000000000650 g DF .text 000000000000000b Base fun
                    0000000000000000 w D UND 0000000000000000 gmon_start
                    0000000000000000 w D UND 0000000000000000 _Jv_RegisterClasses
                    00000000000006b8 g DF .fini 0000000000000000 Base _fini
                    0000000000000666 g DF .text 000000000000000b Base fun2
                    0000000000000000 w D UND 0000000000000000 _ITM_deregisterTMCloneTable
                    0000000000000000 w D UND 0000000000000000 _ITM_registerTMCloneTable
                    0000000000000000 w DF UND 0000000000000126 GLIBC_2.2.5 __cxa_finalize
                    0000000000200998 g D ABS 0000000000000000 Base __bss_start
                    00000000002009a8 g D ABS 0000000000000000 Base _end
                    0000000000200998 g D ABS 0000000000000000 Base _edata
                    000000000000065b g DF .text 000000000000000b Base fun1
                    00000000000004a8 g DF .init 0000000000000000 Base _init

                    Why ? My question is how to get hidden flag in final shared libraries

                    1 Reply Last reply
                    0
                    • kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #10

                      You andswered your question as to "why". Apparently gcc applies the hidden attribute on a per object file basis.

                      My question is how to get hidden flag in final shared libraries

                      By using -fvisibility=hidden for both compilation and linkage (i.e. everywhere).

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        Qt Enthusiast
                        wrote on last edited by
                        #11

                        I am still getting undefined reference
                        for

                        gcc -fPIC -fvisibility=hidden -c my_lib.c -o lib_mylib.o
                        gcc -fPIC -fvisibility=hidden -shared -o libMyLibHidden.so lib_mylib.o
                        gcc -fPIC -c my_lib_shared.c -o my_lib_shared.o
                        gcc -shared -o libMyShared2.so my_lib_shared.o
                        gcc -L. -Wall -o test_hidden driver.c -lMyLibHidden -lMyShared2

                        1 Reply Last reply
                        0
                        • kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by kshegunov
                          #12

                          I am still getting undefined reference

                          And as far as I can tell you should. You can't reference hidden symbols, that's why they're hidden in the first place.
                          I really don't know what you want to do exactly, I explained what I knew to the best of my abilities.

                          Read and abide by the Qt Code of Conduct

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved