Results 1 to 7 of 7

Thread: Using .so libraries under Mac

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Using .so libraries under Mac

    Hi,

    I would like to ask, can I use .so library files under mac ?
    I have compiled one library(OGDI) under linux. Is macx and unix may use the same lib files? is linking done the same way?

    For example,

    When I write this code for linux(in the .pro file):

    Qt Code:
    1. LIBS += -L /ogdi/lib/linux -logdi -lvrf -l.....
    To copy to clipboard, switch view to plain text mode 
    can I do the same for mac?

    I am asking as I have a strange linking problem:
    "/usr/bin/ld -L : directory name missing" when I use the same code in the .pro for mac as for linux.

    Thank you for any help.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using .so libraries under Mac

    Short answer: you cannot use libraries compiled for OS Foo with OS Bar. So, no, you cannot reuse Linux libraries for MacOS.

    Log story: this heavily depends on the OSes' ABI - Application Binary Interface. They are dependent on the OS type (Linux, Solaris, BSD, etc.) and and the CPU for which the code has been compiled (PowerPC, Sparc, IA32). An easy way to find out if your OS can handle libraries which have been compiled for other OSes is to the program file with the library in question:

    thomas@mac ~ $ file /lib/libpthread-2.6.1.so
    /lib/libpthread-2.6.1.so: ELF 32-bit MSB shared object, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.6.9, stripped
    thomas@mac ~ $ file /mnt/fw/win/windows/system/mfc42.dll
    /mnt/fw/win/windows/system/mfc42.dll: MS-DOS executable PE for MS Windows (DLL) (GUI) Intel 80386 32-bit

    The output will tell you for which CPU/architecture the executable/library had been compiled and for which OS, i.e. ABI.
    There are 10 people in the world. Those who understand binary and those who don't.

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using .so libraries under Mac

    Ok, that explains a lot. Thanks

    So what does this mean:
    libproj.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), not stripped
    2 Questions more:

    1) so if I want to use a library uner mac I have to compile it under mac(talking about the same processors)
    2) what are libraries extensions under mac? I see ".a" is this the only possible lib extension? Is it possible to compile a library and have .so files?

    I understant that these questions are quite newbie'like, but please be patient : ) Thanks.

    Thanks.

    Maverick

    P.S.

    one more:
    3) While linking libs under mac, is this ok:

    LIBS+= -L path_to_libs -lfristLib -lndLib.... ?
    Last edited by maverick_pol; 6th January 2008 at 21:18.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using .so libraries under Mac

    Furthermore ABI also depends on the compiler used, so even on the same platform you can't use a library if it was compiled with an incompatible compiler.

    Quote Originally Posted by maverick_pol View Post
    1) so if I want to use a library uner mac I have to compile it under mac(talking about the same processors)
    Yes. And you have to compile it with the same family of compilers (GCC probably) and the same architecture (you can't use a PPC library with an Intel application or 64b library with a 32b app).

    2) what are libraries extensions under mac?
    ".dylib"

    3) While linking libs under mac, is this ok:

    LIBS+= -L path_to_libs -lfristLib -lndLib.... ?
    Yes, it's fine.

  5. The following user says thank you to wysota for this useful post:

    maverick_pol (6th January 2008)

  6. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using .so libraries under Mac

    Thanks...so..

    I have compiled the ogdi with gcc 4.0 and I am using the same gcc 4.0 under mac 10.4.
    I have compiled Qt under Linux to use linux-g++ mkspec and compiled Qt under Mac to use the macx-g++ (in both cases using the same gcc version). What is more I am working on the same processor(machine).

    So, just to be 100% sure, I can't use the same .so libs(compiled under linux, on Mac?) ? yes?

    Secondly, ".dylib" are libs on Mac and what about ".a"? Is ".a" also a lib extension? Or, ".dylib" is the only lib ext.?

    I do appreciate your understanding and patientce. I am new to Mac system and need some basic knowledge.

    Beforehand thank you!

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using .so libraries under Mac

    Quote Originally Posted by maverick_pol View Post
    So, just to be 100% sure, I can't use the same .so libs(compiled under linux, on Mac?) ? yes?
    Correct.

    Secondly, ".dylib" are libs on Mac and what about ".a"? Is ".a" also a lib extension? Or, ".dylib" is the only lib ext.?
    .a is a static library ("archive").

  8. The following user says thank you to wysota for this useful post:

    maverick_pol (6th January 2008)

  9. #7
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using .so libraries under Mac

    Quote Originally Posted by wysota View Post
    Correct.



    .a is a static library ("archive").
    Let me give a more detailed explanation since you mentioned you are a newbie.

    .a libraries are files which contain compiled code in an archive format. Under Linux/Unix the program ar is used to create those. Extracting a .a library gives you .o files (compiled files, object files, binary, not executable). Each .o file is the result of a single compilation (which can contain multiple source files) like "gcc -c -o myStuff.o foo.c bar.c". You would link against a .a library libfoo.a if your code shall be self sufficient in respect to code in libfoo.a which means that it should not depend on a library libfoo.so on the platform where your application runs. This can have several reasons. Eittther you are not allowed to distribute the ldynamic version of the library or your company restricts distributed binaries to be single files only. Your application would then contain all the parts (.o files) of libfoo.a which your application needs. GCC takes care of this process when your application is linked together.

    .dylib on MacOS or .so files are libraries which contain essentially the same code which a static library would contain. The difference is that these libraries will be loaded by the system's dynamic library loader as soon as your application is executed. The dynamic library loader checks if your application is linked against certain libraries (at link time you specify -lfoo, really just a place holder) and looks in the dynamic library on the system for methods, functions, classes, variables, etc. which are missing in your application but in the library and makes them available to the application. The benfit is here that multiple applications can reuse the same library. This makes maintenance very easy and saves tons of space.
    There are 10 people in the world. Those who understand binary and those who don't.

  10. The following user says thank you to Thomas for this useful post:

    maverick_pol (6th January 2008)

Similar Threads

  1. Qt + Eclipse + MinGW + Windows: How to include libraries?
    By jambrek in forum General Programming
    Replies: 3
    Last Post: 19th December 2007, 13:57
  2. how to add new libraries to QT
    By whoops.slo in forum Newbie
    Replies: 3
    Last Post: 12th January 2007, 11:15
  3. Qt 3.3 libraries
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2006, 17:25
  4. Standardization on libraries
    By brcain in forum General Discussion
    Replies: 13
    Last Post: 16th August 2006, 22:56
  5. Replies: 4
    Last Post: 7th March 2006, 08:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.