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. [SOLVED] Problem compiling/using external library (assimp)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Problem compiling/using external library (assimp)

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 5 Posters 17.3k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    dianyu
    wrote on 22 Jan 2016, 14:34 last edited by dianyu 2 Feb 2016, 11:09
    #1

    Hello all,

    I have a qt project of a 3d renderer that I develop on mac (os x 10.11.2) with qt creator 3.5.1 (based on qt 5.5.1 clang 6.1 64 bits). I need to include assimp library to load 3d models. So, I've download assimp library and, following their instruction, I've used cmake to generate an xcode project file that I've compiled to generate the libassimpd.a and libassimp.a. Then, I have copied this .a files and the include folder to my project and I've modified the .pro file to use the library:

    CONFIG(debug, debug|release){
        LIBS += ../Assimp-3.1.1/libassimpd.a
        PRE_TARGETDEPS += "../Assimp-3.1.1/libassimpd.a"
    }CONFIG(release, debug|release){
        LIBS += ../Assimp-3.1.1/libassimp.a
        PRE_TARGETDEPS += "../Assimp-3.1.1/libassimp.a"
    }
    

    Then I compile my project and I get a Undefined symbols for architecture x86_64 error in compilation. What could be the problem??? Maybe I need to compile assimp with qt to be able to use it? If not I don't know where could be the problem...

    Thanks a lot!!!

    Imanol.

    p.d.: The log of the error starts like the following:

    Undefined symbols for architecture x86_64:
      "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::at(unsigned long) const", referenced from:
          Assimp::DXF::LineReader::operator++() in libassimpd.a(DXFLoader.o)
      "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
          Assimp::LWOImporter::AdjustTexturePath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libassimpd.a(LWOLoader.o)
          Assimp::ColladaLoader::CreateAnimation(aiScene*, Assimp::ColladaParser const&, Assimp::Collada::Animation const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libassimpd.a(ColladaLoader.o)
          boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(ColladaLoader.o)
          boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(XFileImporter.o)
          boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(SplitByBoneCountProcess.o)
          boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(BVHLoader.o)
          boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(XFileParser.o)
          ...
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    K R 2 Replies Last reply 22 Jan 2016, 14:39
    0
    • D dianyu
      22 Jan 2016, 14:34

      Hello all,

      I have a qt project of a 3d renderer that I develop on mac (os x 10.11.2) with qt creator 3.5.1 (based on qt 5.5.1 clang 6.1 64 bits). I need to include assimp library to load 3d models. So, I've download assimp library and, following their instruction, I've used cmake to generate an xcode project file that I've compiled to generate the libassimpd.a and libassimp.a. Then, I have copied this .a files and the include folder to my project and I've modified the .pro file to use the library:

      CONFIG(debug, debug|release){
          LIBS += ../Assimp-3.1.1/libassimpd.a
          PRE_TARGETDEPS += "../Assimp-3.1.1/libassimpd.a"
      }CONFIG(release, debug|release){
          LIBS += ../Assimp-3.1.1/libassimp.a
          PRE_TARGETDEPS += "../Assimp-3.1.1/libassimp.a"
      }
      

      Then I compile my project and I get a Undefined symbols for architecture x86_64 error in compilation. What could be the problem??? Maybe I need to compile assimp with qt to be able to use it? If not I don't know where could be the problem...

      Thanks a lot!!!

      Imanol.

      p.d.: The log of the error starts like the following:

      Undefined symbols for architecture x86_64:
        "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::at(unsigned long) const", referenced from:
            Assimp::DXF::LineReader::operator++() in libassimpd.a(DXFLoader.o)
        "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
            Assimp::LWOImporter::AdjustTexturePath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libassimpd.a(LWOLoader.o)
            Assimp::ColladaLoader::CreateAnimation(aiScene*, Assimp::ColladaParser const&, Assimp::Collada::Animation const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libassimpd.a(ColladaLoader.o)
            boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(ColladaLoader.o)
            boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(XFileImporter.o)
            boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(SplitByBoneCountProcess.o)
            boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(BVHLoader.o)
            boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(XFileParser.o)
            ...
      ld: symbol(s) not found for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      
      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 22 Jan 2016, 14:39 last edited by
      #2

      @dianyu
      Hello,
      This may sound trivial, but are Qt, assimp and your application using the same architecture?

      Kind regards.

      Read and abide by the Qt Code of Conduct

      D 1 Reply Last reply 25 Jan 2016, 10:29
      0
      • D dianyu
        22 Jan 2016, 14:34

        Hello all,

        I have a qt project of a 3d renderer that I develop on mac (os x 10.11.2) with qt creator 3.5.1 (based on qt 5.5.1 clang 6.1 64 bits). I need to include assimp library to load 3d models. So, I've download assimp library and, following their instruction, I've used cmake to generate an xcode project file that I've compiled to generate the libassimpd.a and libassimp.a. Then, I have copied this .a files and the include folder to my project and I've modified the .pro file to use the library:

        CONFIG(debug, debug|release){
            LIBS += ../Assimp-3.1.1/libassimpd.a
            PRE_TARGETDEPS += "../Assimp-3.1.1/libassimpd.a"
        }CONFIG(release, debug|release){
            LIBS += ../Assimp-3.1.1/libassimp.a
            PRE_TARGETDEPS += "../Assimp-3.1.1/libassimp.a"
        }
        

        Then I compile my project and I get a Undefined symbols for architecture x86_64 error in compilation. What could be the problem??? Maybe I need to compile assimp with qt to be able to use it? If not I don't know where could be the problem...

        Thanks a lot!!!

        Imanol.

        p.d.: The log of the error starts like the following:

        Undefined symbols for architecture x86_64:
          "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::at(unsigned long) const", referenced from:
              Assimp::DXF::LineReader::operator++() in libassimpd.a(DXFLoader.o)
          "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
              Assimp::LWOImporter::AdjustTexturePath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libassimpd.a(LWOLoader.o)
              Assimp::ColladaLoader::CreateAnimation(aiScene*, Assimp::ColladaParser const&, Assimp::Collada::Animation const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libassimpd.a(ColladaLoader.o)
              boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(ColladaLoader.o)
              boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(XFileImporter.o)
              boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(SplitByBoneCountProcess.o)
              boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(BVHLoader.o)
              boost::format::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in libassimpd.a(XFileParser.o)
              ...
        ld: symbol(s) not found for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        
        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 22 Jan 2016, 14:45 last edited by raven-worx
        #3

        @dianyu
        a quick search pointed out that on newer MAC OS systems clang linkes against the libc++ lib.
        Try adding -stdlib=libstdc++ to the clang flags of the C lib and try again.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        D 1 Reply Last reply 25 Jan 2016, 10:33
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Jan 2016, 23:00 last edited by
          #4

          Hi,

          To add to my fellow, depending on what you need the Qt3D module has an ASSIMP backend.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply 25 Jan 2016, 10:31
          0
          • K kshegunov
            22 Jan 2016, 14:39

            @dianyu
            Hello,
            This may sound trivial, but are Qt, assimp and your application using the same architecture?

            Kind regards.

            D Offline
            D Offline
            dianyu
            wrote on 25 Jan 2016, 10:29 last edited by
            #5

            @kshegunov
            Qt and my application are using the same architecture: x86_64.

            I've build assimp in xCode and looking in the build settings, on the architectures section the configuration of valid architectures is: "i386 x86_64". So, I understand that both are valid and the library could be used in x86_64. Isn't it?

            K 1 Reply Last reply 25 Jan 2016, 12:12
            0
            • S SGaist
              22 Jan 2016, 23:00

              Hi,

              To add to my fellow, depending on what you need the Qt3D module has an ASSIMP backend.

              D Offline
              D Offline
              dianyu
              wrote on 25 Jan 2016, 10:31 last edited by
              #6

              @SGaist Of your comment, I understand that I could use Qt3D module to load the models and after that transform them to my code... Currently, I don't use Qt3dD module and I prefere to use assimp library directly... But anyway, it could be a solution if I can't make it work. Thanks.

              1 Reply Last reply
              0
              • R raven-worx
                22 Jan 2016, 14:45

                @dianyu
                a quick search pointed out that on newer MAC OS systems clang linkes against the libc++ lib.
                Try adding -stdlib=libstdc++ to the clang flags of the C lib and try again.

                D Offline
                D Offline
                dianyu
                wrote on 25 Jan 2016, 10:33 last edited by
                #7

                @raven-worx I don't understand you... add this flag where? to the cmake or xcode when I build assimp or in qt creator? Thaaanks!

                R 1 Reply Last reply 25 Jan 2016, 10:55
                0
                • D dianyu
                  25 Jan 2016, 10:33

                  @raven-worx I don't understand you... add this flag where? to the cmake or xcode when I build assimp or in qt creator? Thaaanks!

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 25 Jan 2016, 10:55 last edited by
                  #8

                  @dianyu
                  depends. Which one is causing the problem. Try adding it to linker flags of the assimp lib first. If unsuccessful also to your project.
                  I dont know the assimp lib. Maybe it already depends on this specific stdlib. I would give assimp with the given linker flag a chance first.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  D 1 Reply Last reply 25 Jan 2016, 11:07
                  0
                  • R raven-worx
                    25 Jan 2016, 10:55

                    @dianyu
                    depends. Which one is causing the problem. Try adding it to linker flags of the assimp lib first. If unsuccessful also to your project.
                    I dont know the assimp lib. Maybe it already depends on this specific stdlib. I would give assimp with the given linker flag a chance first.

                    D Offline
                    D Offline
                    dianyu
                    wrote on 25 Jan 2016, 11:07 last edited by
                    #9

                    @raven-worx Ok. I've changed linker flags in xcode ("other linker flags") for the assimp, and nothing has changed. It compiles well, but qtcreator give me the same errors... To change it in qtcreator, how can i do it? I don't found linker flags configuration option. Thanks!

                    R 1 Reply Last reply 25 Jan 2016, 11:55
                    0
                    • D dianyu
                      25 Jan 2016, 11:07

                      @raven-worx Ok. I've changed linker flags in xcode ("other linker flags") for the assimp, and nothing has changed. It compiles well, but qtcreator give me the same errors... To change it in qtcreator, how can i do it? I don't found linker flags configuration option. Thanks!

                      R Offline
                      R Offline
                      raven-worx
                      Moderators
                      wrote on 25 Jan 2016, 11:55 last edited by
                      #10

                      @dianyu
                      add the flags to the QMAKE_LFLAGS variable in your pro file
                      and don't forget to rerun qmake

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      D 1 Reply Last reply 25 Jan 2016, 12:17
                      0
                      • D dianyu
                        25 Jan 2016, 10:29

                        @kshegunov
                        Qt and my application are using the same architecture: x86_64.

                        I've build assimp in xCode and looking in the build settings, on the architectures section the configuration of valid architectures is: "i386 x86_64". So, I understand that both are valid and the library could be used in x86_64. Isn't it?

                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 25 Jan 2016, 12:12 last edited by
                        #11

                        @dianyu
                        Yes it should. Are you linking all the assimp's dependencies? Your linker seems to have trouble finding some functions from the boost library ... Maybe try and compile assimp as a shared object, and then try to link it into your project?

                        Kind regards,

                        Read and abide by the Qt Code of Conduct

                        D 1 Reply Last reply 25 Jan 2016, 12:21
                        0
                        • R raven-worx
                          25 Jan 2016, 11:55

                          @dianyu
                          add the flags to the QMAKE_LFLAGS variable in your pro file
                          and don't forget to rerun qmake

                          D Offline
                          D Offline
                          dianyu
                          wrote on 25 Jan 2016, 12:17 last edited by
                          #12

                          @raven-worx Same errors... :S

                          1 Reply Last reply
                          0
                          • K kshegunov
                            25 Jan 2016, 12:12

                            @dianyu
                            Yes it should. Are you linking all the assimp's dependencies? Your linker seems to have trouble finding some functions from the boost library ... Maybe try and compile assimp as a shared object, and then try to link it into your project?

                            Kind regards,

                            D Offline
                            D Offline
                            dianyu
                            wrote on 25 Jan 2016, 12:21 last edited by
                            #13

                            @kshegunov

                            Yes it should. Are you linking all the assimp's dependencies?

                            Mmm, I don't think so... I thought that as I have compiled it as static library, all the dependencies should be included inside the .a file.

                            Your linker seems to have trouble finding some functions from the boost library ...

                            I've seen this also... But it is strange. In cmake I have activated the flag to make boost workaround because i think that I don't have boost installed (At least i have no conscience of it...)

                            Maybe try and compile assimp as a shared object, and then try to link it into your project?

                            How can I specify this in xcode or cmake?

                            Kind regards,

                            Thank you a lot!

                            K 1 Reply Last reply 25 Jan 2016, 12:44
                            0
                            • D dianyu
                              25 Jan 2016, 12:21

                              @kshegunov

                              Yes it should. Are you linking all the assimp's dependencies?

                              Mmm, I don't think so... I thought that as I have compiled it as static library, all the dependencies should be included inside the .a file.

                              Your linker seems to have trouble finding some functions from the boost library ...

                              I've seen this also... But it is strange. In cmake I have activated the flag to make boost workaround because i think that I don't have boost installed (At least i have no conscience of it...)

                              Maybe try and compile assimp as a shared object, and then try to link it into your project?

                              How can I specify this in xcode or cmake?

                              Kind regards,

                              Thank you a lot!

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 25 Jan 2016, 12:44 last edited by kshegunov
                              #14

                              @dianyu said:

                              Mmm, I don't think so... I thought that as I have compiled it as static library, all the dependencies should be included inside the .a file.

                              Not at all, this is a common misconception. I don't really have the strength to explain it in detail, but you should link against static libraries' dependencies. Otherwise the linker will not be able to resolve the symbols. Do install boost, and link it as well. I think it is best to compile assimp as a .so, but in any case you'll still need to link against the dependencies to compile the shared object.

                              How can I specify this in xcode or cmake?

                              I have worked with neither of those, and only have a basic understanding of the cmake build cycle, so unfortunately I couldn't be of help for that. Maybe someone else will suggest the proper way.

                              Kind regards.

                              Read and abide by the Qt Code of Conduct

                              D 1 Reply Last reply 25 Jan 2016, 14:30
                              0
                              • K kshegunov
                                25 Jan 2016, 12:44

                                @dianyu said:

                                Mmm, I don't think so... I thought that as I have compiled it as static library, all the dependencies should be included inside the .a file.

                                Not at all, this is a common misconception. I don't really have the strength to explain it in detail, but you should link against static libraries' dependencies. Otherwise the linker will not be able to resolve the symbols. Do install boost, and link it as well. I think it is best to compile assimp as a .so, but in any case you'll still need to link against the dependencies to compile the shared object.

                                How can I specify this in xcode or cmake?

                                I have worked with neither of those, and only have a basic understanding of the cmake build cycle, so unfortunately I couldn't be of help for that. Maybe someone else will suggest the proper way.

                                Kind regards.

                                D Offline
                                D Offline
                                dianyu
                                wrote on 25 Jan 2016, 14:30 last edited by
                                #15

                                @kshegunov said:

                                Not at all, this is a common misconception. I don't really have the strength to explain it in detail, but you should link against static libraries' dependencies. Otherwise the linker will not be able to resolve the symbols. Do install boost, and link it as well. I think it is best to compile assimp as a .so, but in any case you'll still need to link against the dependencies to compile the shared object.

                                How can I specify this in xcode or cmake?

                                I have worked with neither of those, and only have a basic understanding of the cmake build cycle, so unfortunately I couldn't be of help for that. Maybe someone else will suggest the proper way.

                                Kind regards.

                                I missunderstood you. Shared objects (dynamic libraries) in mac are .dylib. I've built them. But I can't link againts them... Linker say "library not found". I link with this code:

                                    LIBS += -l../Assimp-3.1.1/libassimpd.3.1.1.dylib
                                

                                Anyway, I've compiled the assimp library creating a new library in my project using the .pri of assimp code inside qt3dmodule and it compiles and linkes... I needed to do some tricks in the code and link against libz.dylib. Now I should check if it works... But, I still want to make work the assimp library compiled with xcode... I linked it agains libz using (LIBS += -lz) and it didn't work... It is strage, maybe it is not working the boost workaround in the cmake?

                                Thanks

                                K 1 Reply Last reply 25 Jan 2016, 14:57
                                0
                                • D dianyu
                                  25 Jan 2016, 14:30

                                  @kshegunov said:

                                  Not at all, this is a common misconception. I don't really have the strength to explain it in detail, but you should link against static libraries' dependencies. Otherwise the linker will not be able to resolve the symbols. Do install boost, and link it as well. I think it is best to compile assimp as a .so, but in any case you'll still need to link against the dependencies to compile the shared object.

                                  How can I specify this in xcode or cmake?

                                  I have worked with neither of those, and only have a basic understanding of the cmake build cycle, so unfortunately I couldn't be of help for that. Maybe someone else will suggest the proper way.

                                  Kind regards.

                                  I missunderstood you. Shared objects (dynamic libraries) in mac are .dylib. I've built them. But I can't link againts them... Linker say "library not found". I link with this code:

                                      LIBS += -l../Assimp-3.1.1/libassimpd.3.1.1.dylib
                                  

                                  Anyway, I've compiled the assimp library creating a new library in my project using the .pri of assimp code inside qt3dmodule and it compiles and linkes... I needed to do some tricks in the code and link against libz.dylib. Now I should check if it works... But, I still want to make work the assimp library compiled with xcode... I linked it agains libz using (LIBS += -lz) and it didn't work... It is strage, maybe it is not working the boost workaround in the cmake?

                                  Thanks

                                  K Offline
                                  K Offline
                                  kshegunov
                                  Moderators
                                  wrote on 25 Jan 2016, 14:57 last edited by
                                  #16

                                  @dianyu
                                  Hello,

                                  I missunderstood you. Shared objects (dynamic libraries) in mac are .dylib

                                  It doesn't really matter how you call them, they behave and are built similarly. On windows they are called dll's, but the principle is the same (with some very minor platform specific tweaks). I will first explain what a static library is and hopefully it will shed some light on the issue.
                                  A static library (.a, from archive) is only a collection of translation units (.o - object files) put into one file. To create such a thing you don't really need a linker step on *nix/Linux systems, because symbol resolution is done at runtime (there are special .lib files on windows though). Now when you have a call to a function in your code an undefined symbol is created that should be resolved by the linker. When you "link" your static library the archive is appended to your application code as it would have been if you compiled the code in your application, but in no way are symbols resolved beforehand. So, if the static library references a dynamic library (e.g. libc) you have to link against it in your application, so when the loader runs it will load the libc image, and then resolve the undefined symbols (referenced in the static library OR the application). This all means, that if you have multiple dependencies in your static library they have to be met in your application (either by linking, I use this term a bit frivolously here, other static libraries or linking the dynamic libraries the static one depends on). There can be no automatic linkage performed on a static library, as it's just a collection of translation units, a static library has no notion of address space or binary compatibility, because it's just some binary code that's simply included into the final executable/shared object, and not a separate self-sustained unit. I hope this helps in understanding why you need to meet the static library's dependencies on your own.

                                  But I can't link againts them... Linker say "library not found". I link with this code:

                                  What about this?

                                  LIBS += -L../Assimp-3.1.1/ -lassimpd
                                  

                                  You should resolve the linker errors to make it work. Furthermore, qmake knows what platform you're running and knows what prefixes/suffixes are used for dynamic libraries. It also has the idea of separation between link path and library name, so maybe use the qmake link switches accordingly ...? Additionally you should check if at that location there is indeed such file present.

                                  LIBS += -lz
                                  

                                  Looks correct, but make sure you have installed that library and qmake can find it at the configured default link path.

                                  Kind regards.

                                  Read and abide by the Qt Code of Conduct

                                  D 1 Reply Last reply 25 Jan 2016, 15:23
                                  0
                                  • K kshegunov
                                    25 Jan 2016, 14:57

                                    @dianyu
                                    Hello,

                                    I missunderstood you. Shared objects (dynamic libraries) in mac are .dylib

                                    It doesn't really matter how you call them, they behave and are built similarly. On windows they are called dll's, but the principle is the same (with some very minor platform specific tweaks). I will first explain what a static library is and hopefully it will shed some light on the issue.
                                    A static library (.a, from archive) is only a collection of translation units (.o - object files) put into one file. To create such a thing you don't really need a linker step on *nix/Linux systems, because symbol resolution is done at runtime (there are special .lib files on windows though). Now when you have a call to a function in your code an undefined symbol is created that should be resolved by the linker. When you "link" your static library the archive is appended to your application code as it would have been if you compiled the code in your application, but in no way are symbols resolved beforehand. So, if the static library references a dynamic library (e.g. libc) you have to link against it in your application, so when the loader runs it will load the libc image, and then resolve the undefined symbols (referenced in the static library OR the application). This all means, that if you have multiple dependencies in your static library they have to be met in your application (either by linking, I use this term a bit frivolously here, other static libraries or linking the dynamic libraries the static one depends on). There can be no automatic linkage performed on a static library, as it's just a collection of translation units, a static library has no notion of address space or binary compatibility, because it's just some binary code that's simply included into the final executable/shared object, and not a separate self-sustained unit. I hope this helps in understanding why you need to meet the static library's dependencies on your own.

                                    But I can't link againts them... Linker say "library not found". I link with this code:

                                    What about this?

                                    LIBS += -L../Assimp-3.1.1/ -lassimpd
                                    

                                    You should resolve the linker errors to make it work. Furthermore, qmake knows what platform you're running and knows what prefixes/suffixes are used for dynamic libraries. It also has the idea of separation between link path and library name, so maybe use the qmake link switches accordingly ...? Additionally you should check if at that location there is indeed such file present.

                                    LIBS += -lz
                                    

                                    Looks correct, but make sure you have installed that library and qmake can find it at the configured default link path.

                                    Kind regards.

                                    D Offline
                                    D Offline
                                    dianyu
                                    wrote on 25 Jan 2016, 15:23 last edited by
                                    #17

                                    @kshegunov said:

                                    @dianyu
                                    Hello,

                                    I missunderstood you. Shared objects (dynamic libraries) in mac are .dylib

                                    It doesn't really matter how you call them, they behave and are built similarly. On windows they are called dll's, but the principle is the same (with some very minor platform specific tweaks). I will first explain what a static library is and hopefully it will shed some light on the issue.
                                    A static library (.a, from archive) is only a collection of translation units (.o - object files) put into one file. To create such a thing you don't really need a linker step on *nix/Linux systems, because symbol resolution is done at runtime (there are special .lib files on windows though). Now when you have a call to a function in your code an undefined symbol is created that should be resolved by the linker. When you "link" your static library the archive is appended to your application code as it would have been if you compiled the code in your application, but in no way are symbols resolved beforehand. So, if the static library references a dynamic library (e.g. libc) you have to link against it in your application, so when the loader runs it will load the libc image, and then resolve the undefined symbols (referenced in the static library OR the application). This all means, that if you have multiple dependencies in your static library they have to be met in your application (either by linking, I use this term a bit frivolously here, other static libraries or linking the dynamic libraries the static one depends on). There can be no automatic linkage performed on a static library, as it's just a collection of translation units, a static library has no notion of address space or binary compatibility, because it's just some binary code that's simply included into the final executable/shared object, and not a separate self-sustained unit. I hope this helps in understanding why you need to meet the static library's dependencies on your own.

                                    Thank you! I have a mess in my head! :)

                                    But I can't link againts them... Linker say "library not found". I link with this code:

                                    What about this?

                                    LIBS += -L../Assimp-3.1.1/ -lassimpd
                                    

                                    Completely right.

                                    You should resolve the linker errors to make it work. Furthermore, qmake knows what platform you're running and knows what prefixes/suffixes are used for dynamic libraries. It also has the idea of separation between link path and library name, so maybe use the qmake link switches accordingly ...? Additionally you should check if at that location there is indeed such file present.

                                    LIBS += -lz
                                    

                                    Looks correct, but make sure you have installed that library and qmake can find it at the configured default link path.

                                    It is because it is installed in the /usr/lib folder.

                                    I've used the dynamic library (without boost) and it works. It compiles and links without errors. Then, my doubts are why it works for the dynamic library and not for the static one? The dependencies should be at least the same, isn't it? Another question, is there any way to check the dependencies of library?

                                    Thanks a lot!

                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      kshegunov
                                      Moderators
                                      wrote on 25 Jan 2016, 15:37 last edited by kshegunov
                                      #18

                                      @dianyu
                                      Hello,

                                      It is because it is installed in the /usr/lib folder.

                                      This should be in your default link-path as far as I can tell, so in all probability LIBS += -lz should be just enough.

                                      I've used the dynamic library (without boost) and it works. It compiles and links without errors. Then, my doubts are why it works for the dynamic library and not for the static one? The dependencies should be at least the same, isn't it?

                                      The shared object is supposed to be shared, so it has a header that tells ld, the linker that is, what other binaries to load and possibly (through rpath field in the ELF, or the LD_LIBRARY_PATH environment variable) where to find those dependencies. A static library, as already established, has no such thing and has no compatible capabilities. I think this should answer it?

                                      Another question, is there any way to check the dependencies of library?

                                      Whenever I need to look up the symbol table I personally use nm like this:

                                      nm -C mylibrary.so
                                      

                                      I don't often do that, and I have no idea whatsoever if it's available to macs, since I've never worker on such machines, but I suppose it should be possible to use it. This command will produce something similar to this:

                                      0000000000200968 d __TMC_END__                                                                                                                                                                                                                             
                                      0000000000200968 B __bss_start                                                                                                                                                                                                                             
                                                       w __cxa_finalize@@GLIBC_2.2.5                                                                                                                                                                                                             
                                      0000000000000630 t __do_global_dtors_aux                                                                                                                                                                                                                   
                                      0000000000200708 t __do_global_dtors_aux_fini_array_entry                                                                                                                                                                                                  
                                      0000000000200960 d __dso_handle                                                                                                                                                                                                                            
                                      0000000000200700 t __frame_dummy_init_array_entry                                                                                                                                                                                                          
                                                       w __gmon_start__                                                                                                                                                                                                                          
                                      0000000000200968 D _edata                                                                                                                                                                                                                                  
                                      0000000000200970 B _end                                                                                                                                                                                                                                    
                                      00000000000006a0 T _fini                                                                                                                                                                                                                                   
                                      0000000000000560 T _init                                                                                                                                                                                                                                   
                                      0000000000200968 b completed.6971                                                                                                                                                                                                                          
                                      00000000000005a0 t deregister_tm_clones                                                                                                                                                                                                                    
                                      0000000000000670 t frame_dummy                                                                                                                                                                                                                             
                                                       U qt_version_tag@@Qt_5.6                                                                                                                                                                                                                  
                                      00000000000005e0 t register_tm_clones               
                                      

                                      Note the undefined qt_version_tag from Qt 5.6 and the weak __cxa_finalize that is referencing GLIBC 2.2.5! An explanation for the letters' meaning is available through the man pages.

                                      Kind regards.

                                      Read and abide by the Qt Code of Conduct

                                      D 1 Reply Last reply 26 Jan 2016, 11:03
                                      0
                                      • S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 25 Jan 2016, 17:01 last edited by
                                        #19

                                        There's nm available on OS X but also otool -L name_of_exec_or_librarythat will show you the dependencies

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        D 1 Reply Last reply 26 Jan 2016, 11:04
                                        0
                                        • K kshegunov
                                          25 Jan 2016, 15:37

                                          @dianyu
                                          Hello,

                                          It is because it is installed in the /usr/lib folder.

                                          This should be in your default link-path as far as I can tell, so in all probability LIBS += -lz should be just enough.

                                          I've used the dynamic library (without boost) and it works. It compiles and links without errors. Then, my doubts are why it works for the dynamic library and not for the static one? The dependencies should be at least the same, isn't it?

                                          The shared object is supposed to be shared, so it has a header that tells ld, the linker that is, what other binaries to load and possibly (through rpath field in the ELF, or the LD_LIBRARY_PATH environment variable) where to find those dependencies. A static library, as already established, has no such thing and has no compatible capabilities. I think this should answer it?

                                          Another question, is there any way to check the dependencies of library?

                                          Whenever I need to look up the symbol table I personally use nm like this:

                                          nm -C mylibrary.so
                                          

                                          I don't often do that, and I have no idea whatsoever if it's available to macs, since I've never worker on such machines, but I suppose it should be possible to use it. This command will produce something similar to this:

                                          0000000000200968 d __TMC_END__                                                                                                                                                                                                                             
                                          0000000000200968 B __bss_start                                                                                                                                                                                                                             
                                                           w __cxa_finalize@@GLIBC_2.2.5                                                                                                                                                                                                             
                                          0000000000000630 t __do_global_dtors_aux                                                                                                                                                                                                                   
                                          0000000000200708 t __do_global_dtors_aux_fini_array_entry                                                                                                                                                                                                  
                                          0000000000200960 d __dso_handle                                                                                                                                                                                                                            
                                          0000000000200700 t __frame_dummy_init_array_entry                                                                                                                                                                                                          
                                                           w __gmon_start__                                                                                                                                                                                                                          
                                          0000000000200968 D _edata                                                                                                                                                                                                                                  
                                          0000000000200970 B _end                                                                                                                                                                                                                                    
                                          00000000000006a0 T _fini                                                                                                                                                                                                                                   
                                          0000000000000560 T _init                                                                                                                                                                                                                                   
                                          0000000000200968 b completed.6971                                                                                                                                                                                                                          
                                          00000000000005a0 t deregister_tm_clones                                                                                                                                                                                                                    
                                          0000000000000670 t frame_dummy                                                                                                                                                                                                                             
                                                           U qt_version_tag@@Qt_5.6                                                                                                                                                                                                                  
                                          00000000000005e0 t register_tm_clones               
                                          

                                          Note the undefined qt_version_tag from Qt 5.6 and the weak __cxa_finalize that is referencing GLIBC 2.2.5! An explanation for the letters' meaning is available through the man pages.

                                          Kind regards.

                                          D Offline
                                          D Offline
                                          dianyu
                                          wrote on 26 Jan 2016, 11:03 last edited by
                                          #20

                                          @kshegunov said:

                                          @dianyu
                                          Hello,

                                          It is because it is installed in the /usr/lib folder.

                                          This should be in your default link-path as far as I can tell, so in all probability LIBS += -lz should be just enough.

                                          Yep!

                                          I've used the dynamic library (without boost) and it works. It compiles and links without errors. Then, my doubts are why it works for the dynamic library and not for the static one? The dependencies should be at least the same, isn't it?

                                          The shared object is supposed to be shared, so it has a header that tells ld, the linker that is, what other binaries to load and possibly (through rpath field in the ELF, or the LD_LIBRARY_PATH environment variable) where to find those dependencies. A static library, as already established, has no such thing and has no compatible capabilities. I think this should answer it?

                                          I understand... So, in shared objects you don't need to indicate the linker the dependences 'cause it could find them.

                                          Another question, is there any way to check the dependencies of library?

                                          Whenever I need to look up the symbol table I personally use nm like this:

                                          nm -C mylibrary.so
                                          

                                          I don't often do that, and I have no idea whatsoever if it's available to macs, since I've never worker on such machines, but I suppose it should be possible to use it. This command will produce something similar to this:

                                          0000000000200968 d __TMC_END__                                                                                                                                                                                                                             
                                          0000000000200968 B __bss_start                                                                                                                                                                                                                             
                                                           w __cxa_finalize@@GLIBC_2.2.5                                                                                                                                                                                                             
                                          0000000000000630 t __do_global_dtors_aux                                                                                                                                                                                                                   
                                          0000000000200708 t __do_global_dtors_aux_fini_array_entry                                                                                                                                                                                                  
                                          0000000000200960 d __dso_handle                                                                                                                                                                                                                            
                                          0000000000200700 t __frame_dummy_init_array_entry                                                                                                                                                                                                          
                                                           w __gmon_start__                                                                                                                                                                                                                          
                                          0000000000200968 D _edata                                                                                                                                                                                                                                  
                                          0000000000200970 B _end                                                                                                                                                                                                                                    
                                          00000000000006a0 T _fini                                                                                                                                                                                                                                   
                                          0000000000000560 T _init                                                                                                                                                                                                                                   
                                          0000000000200968 b completed.6971                                                                                                                                                                                                                          
                                          00000000000005a0 t deregister_tm_clones                                                                                                                                                                                                                    
                                          0000000000000670 t frame_dummy                                                                                                                                                                                                                             
                                                           U qt_version_tag@@Qt_5.6                                                                                                                                                                                                                  
                                          00000000000005e0 t register_tm_clones               
                                          

                                          Note the undefined qt_version_tag from Qt 5.6 and the weak __cxa_finalize that is referencing GLIBC 2.2.5! An explanation for the letters' meaning is available through the man pages.

                                          I've tried this and the result for libassimpd.a is huge! I used grep to look for @ symbol and no results... I will investigate the man, but I'm not sure if it is what I'm looking for... I would like to know, which dependencies I need to indicate to the linker to make it work...

                                          Kind regards.

                                          Thank you very much! Your help is great!

                                          1 Reply Last reply
                                          0

                                          2/28

                                          22 Jan 2016, 14:39

                                          topic:navigator.unread, 26
                                          • Login

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