Linux so export functions

How to list exported functions in a shared lib on Ubuntu

I have just built a shared lib on Ubuntu, and when I attempt to use the function, the application that loads the library is reporting ‘xxx’ symbol not found. I want to check (i.e. list) the functions that are exported by my library so I can investigate this issue further. Relevant details: OS: Ubuntu 9.10 compiler: gcc 4.4.1 linker: GNU ld 2.20

3 Answers 3

GNU nm lists the symbols from object files objfile. If no object files are listed as arguments, nm assumes the file a.out. [reference]

Thanks for that. It appears my symbol is exported, but undefined (it has a ‘U’ next to the function name). How can a function be exported and yet be undefined (IIRC, a linker option prevents this kind of absurbity). More importantly, what can I do to fix it?

By «Fixing it», I mean how can I ensure that my functions are exported AND DEFINED in the shared library?

Could it be that the undefined symbol is contained in another shared object? Check out Void’s advice.

Were you able to find the root cause for your problem? I am trying to link a FORTRAN-based library and it is showing a function as undefined in the output shared library

For exported functions add —defined-only option, otherwise this way you’ll get imports too. Also, to get only functions and not e.g. something like _edata , you should look for the symbols with T or t in the second column. So, something like this: nm -DCg —defined-only $MY_LIB | grep ‘^[0-9a-f]\+ [Tt] ‘

Is your shared library in the library load path or in the application’s run-time search path? It sounds like the dynamic linker can’t find your library. Try running ldd on your application to see if the library can be found at run-time, e.g.:

$ ldd /usr/bin/less linux-gate.so.1 => (0x0072a000) libncurses.so.5 => /lib/libncurses.so.5 (0x00c68000) libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x007c7000) libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00286000) /lib/ld-linux.so.2 (0x002a1000) 

See the ld.so(8) man page for additional details on library search paths.

Читайте также:  Red hat linux лучший

Источник

c++ экспортировании функций из so

в линуксе kept simple — все символы экспортируются по-умолчанию, не надо ничего делать.
если Qt — лучше пользоваться Q_DECL_EXPORT и Q_DECL_IMPORT — меньше гемора будет с виндой. QtCreator генерит такой код по умолчанию при создании shared library проекта. Посмотри.

так у меня статическая либа не создаётся в code blocks для exporta из so

так у меня статическая либа не создаётся в code blocks для exporta из so

она не нужна, .so линкуется в программу напрямую

как мне её подключить к программе?

man gcc, ключи -l -L тебе в помощь

лан буду за компом попробую

как мне её подключить к программе?

gcc object_files path_to_lib.so -o program
gcc object_files -L/dierectory/with/lib -lname -o program

при этом .so файл должен иметь имя libname.so

#define API __attribute__ ((visibility("default"))) #ifdef __cplusplus extern "C" < #endif int API some_api_fun(); #ifdef __cplusplus >#endif 

компилятору скорми -fvisibility=hidden, тогда наружу будут торчать только те, что тебе надо. Это ускорит загрузку приложения.

How To Write Shared Libraries Ulrich Drepper Red Hat, Inc. drepper@redhat.com August 20, 2006

Нинада тибе никакая статическая либо. Под правильными платформами всё сделано без лишнего долбанутого гемора с либфайлами и сошки проверсиированы на уровне имени файла.

Про всякие dllMain, которые безпричинно крешат всё при запуске loadlibrary я вообще молчу. Такие дела.

И вообще, после портирования туда даже кутишных приложений у меня руки потом тресутся два дня. Такое чувство что ту платформу придумали садомазо, ибо на каждом шаге кажется что тебе специально палки в колёса вставляют.

Другое дело линукс. Всё работает из коробки.

nanoolinux ★★★★ ( 15.10.13 14:00:32 MSK )
Последнее исправление: nanoolinux 15.10.13 14:01:40 MSK (всего исправлений: 1)

How To Write Shared Libraries Ulrich Drepper Red Hat, Inc. drepper@redhat.com August 20, 2006

Плюсую Дреппера. Читать обязатлельно для полного понимания.

Источник

Thread: howto export functions in *.so libraries

Vahagn_IV is offline5 Cups of Ubuntu

howto export functions in *.so libraries

I am trying to convert one windows program to Linux.
The question is:
what is linux equivalent for

extern «C» int (__declspec(dllexport))someFunction(char* someparam)

Emanuele_Z is offlineFrothy Coffee!

ArrowRe: howto export functions in *.so libraries

Is just a mere macro to usually force the compiler to produce stdcall calling convention. In Linux AFAIK we only use cdecl ( http://en.wikipedia.org/wiki/X86_calling_conventions ).
Have fun!

Читайте также:  Удаление лишних ядер astra linux

Vahagn_IV is offline5 Cups of Ubuntu

Re: howto export functions in *.so libraries

Emanuele_Z is offlineFrothy Coffee!

WinkRe: howto export functions in *.so libraries

to be precise, the calling convention applies to i386 arch.
For x86-64 Windows and Linux follow 2 slightly different conventions: Linux follows AMD ABI calling convention, instead, as usual, M$ way is to slightly diverge from it from no apparent reason. sigh.
Anyway, given more registers in x86-64, a lot of variables are passed into them, instead of being put onto the stack then read (as happens with i386 convention). So even just for this reason (and believe me there are many more) x86-64 is faster than i386.

  • Site Areas
  • Settings
  • Private Messages
  • Subscriptions
  • Who’s Online
  • Search Forums
  • Forums Home
  • Forums
  • The Ubuntu Forum Community
    1. Ubuntu Official Flavours Support
      1. New to Ubuntu
      2. General Help
      3. Installation & Upgrades
      4. Hardware
      5. Desktop Environments
      6. Networking & Wireless
      7. Multimedia Software
    2. Ubuntu Specialised Support
      1. Ubuntu Development Version
      2. Security
      3. Virtualisation
      4. Ubuntu Servers, Cloud and Juju
        1. Server Platforms
        2. Ubuntu Cloud and Juju
      5. Gaming & Leisure
        1. Emulators
      6. Wine
      7. Development & Programming
        1. Packaging and Compiling Programs
        2. Development CD/DVD Image Testing
        3. Ubuntu Application Development
        4. Ubuntu Dev Link Forum
        5. Programming Talk
        6. Repositories & Backports
          1. Ubuntu Backports
            1. Bug Reports / Support
      8. System76 Support
      9. Apple Hardware Users
    3. Ubuntu Community Discussions
      1. Ubuntu, Linux and OS Chat
        1. Recurring Discussions
        2. Full Circle Magazine
      2. The Cafe
        1. Cafe Games
      3. Market
      4. Mobile Technology Discussions (CLOSED)
      5. Announcements & News
      6. Weekly Newsletter
      7. Membership Applications
      8. The Fridge Discussions
      9. Forum Council Agenda
      10. Forum Feedback & Help
        1. Request a LoCo forum
      11. Resolution Centre
    4. Other Discussion and Support
      1. Other OS Support and Projects
        1. Other Operating Systems
          1. Ubuntu/Debian BASED
          2. Debian
          3. MINT
          4. Arch and derivatives
          5. Fedora/RedHat and derivatives
          6. Mandriva/Mageia
          7. Slackware and derivatives
          8. openSUSE and SUSE Linux Enterprise
          9. Mac OSX
          10. PCLinuxOS
          11. Gentoo and derivatives
          12. Windows
          13. BSD
          14. Any Other OS
      2. Assistive Technology & Accessibility
      3. Art & Design
      4. Education & Science
      5. Documentation and Community Wiki Discussions
      6. Tutorials
        1. Outdated Tutorials & Tips
      7. Ubuntu Women
      8. Ubuntu LoCo Team Forums
        1. Americas LoCo Teams
          1. Argentina Team
            1. Software
            2. Hardware
            3. Comunidad
          2. Arizona Team — US
          3. Arkansas Team — US
          4. Brazil Team
          5. California Team — US
          6. Canada Team
          7. Centroamerica Team
          8. Chile Team
            1. Comunidad
            2. Hardware
            3. Software
            4. Instalaci�n y Actualizaci�n
          9. Colombia Team — Colombia
          10. Georgia Team — US
          11. Illinois Team
          12. Indiana — US
          13. Kentucky Team — US
          14. Maine Team — US
          15. Minnesota Team — US
          16. Mississippi Team — US
          17. Nebraska Team — US
          18. New Mexico Team — US
          19. New York — US
          20. North Carolina Team — US
          21. Ohio Team — US
          22. Oklahoma Team — US
          23. Oregon Team — US
          24. Pennsylvania Team — US
          25. Peru Team
          26. Texas Team — US
          27. Uruguay Team
          28. Utah Team — US
          29. Virginia Team — US
          30. West Virginia Team — US
        2. Asia and Oceania LoCo Teams
          1. Australia Team
          2. Bangladesh Team
          3. Hong Kong Team
          4. Myanmar Team
          5. Philippine Team
          6. Singapore Team
        3. Europe, Middle East, and African (EMEA) LoCo Teams
          1. Albania Team
          2. Catalan Team
          3. Portugal Team
          4. Egypt Team
          5. Georgia Team
          6. Ireland Team — Ireland
          7. Kenyan Team — Kenya
          8. Kurdish Team — Kurdistan
          9. Lebanon Team
          10. Morocco Team
          11. Saudi Arabia Team
          12. Sudan Team
          13. Tunisia Team
        4. Other Forums & Teams
        5. LoCo Archive
          1. Afghanistan Team
          2. Alabama Team — US
          3. Alaska Team — US
          4. Algerian Team
          5. Andhra Pradesh Team — India
          6. Austria Team
          7. Bangalore Team
          8. Bolivia Team
          9. Cameroon Team
          10. Colorado Team — US
          11. Connecticut Team
          12. Costa Rica Team
          13. Delhi Team
          14. Ecuador Team
          15. El Salvador Team
          16. Florida Team — US
          17. Galician LoCo Team
          18. Greek team
          19. Hawaii Team — US
          20. Honduras Team
          21. Idaho Team — US
          22. Iowa Team — US
          23. Jordan Team
          24. Kansas Team — US
          25. Libya Team
          26. Louisiana Team — US
          27. Maryland Team — US
          28. Massachusetts Team
          29. Michigan Team — US
          30. Missouri Team — US
          31. Montana Team — US
          32. Namibia Team
          33. Nevada Team — US
          34. New Hampshire Team — US
          35. New Jersey Team — US
          36. Northeastern Team — US
          37. Panama Team
          38. Paraguay Team
          39. Qatar Team
          40. Quebec Team
          41. Rhode Island Team — US
          42. Senegal Team
          43. South Carolina Team — US
          44. South Dakota Team — US
          45. Switzerland Team
          46. Tamil Team — India
          47. Tennessee Team — US
          48. Trinidad & Tobago Team
          49. Uganda Team
          50. United Kingdom Team
          51. US LoCo Teams
          52. Venezuela Team
          53. Wales Team
          54. Washington DC Team — US
          55. Washington State Team — US
          56. Wisconsin Team
          57. Yemen Team
          58. Za Team — South Africa
          59. Zimbabwe Team
Читайте также:  Виртуализация astra linux фстэк

Bookmarks

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

Источник

Оцените статью
Adblock
detector