V
V
Vadim Ushakov2021-07-31 13:30:55
C++ / C#
Vadim Ushakov, 2021-07-31 13:30:55

Exporting functions from .so library?

__attribute__((dllexport)) bool exported_test_function()
{
    std::cout << "Function Called Externally" << std::endl;
    return true;
}


src/cpp.licenses.cpp:25:56: warning: 'dllexport' attribute directive ignored [-Wattributes]
25 | __ __attribute ((dllexport)) bool exported_test_function ()

bin / Release / libdlicenses.so: file format elf64-x86-64

DYNAMIC SYMBOL TABLE:
0000000000000000 w D * UND * __cxa_finalize
0000000000000000 0000000000000000 w D * UND * _ITM_registerTMCloneTable
0000000000000000 0000000000000000 w D * UND * 0000000000000000 _ITM_deregisterTMCloneTable
0000000000000000 w D *UND* 0000000000000000 __gmon_start__


At
__attribute__((visibility("default"))) bool exported_test_function()


The same problem, there is no exported_test_function in the export table, how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2021-07-31
@D3Nd3R

Since in gcc tags:
If I remember correctly, in gcc, by default, exports
dll[export|import] symbols, these are msvc attributes
when developing on msvc, it is customary to write macros for such attributes

#if defined(BUILDING)
#define DLL_ATTR  __declspec(dllexport)
#else
#define DLL_ATTR   __declspec(dllimport)
#endif

BUILDING must be defined at build
if cmake is used, then /DBUILDING must be added to CMAKE_CXX_FLAGS

J
jcmvbkbc, 2021-07-31
@jcmvbkbc

The same problem, there is no exported_test_function in the export table, how to fix it?

I do this, the function is in place:
$ cat > 1027136.cс
__attribute__((visibility("default"))) bool exported_test_function()
{
        return true;
}
$ g++ -fPIC -shared 1027136.cc -o 1027136.so
$ objdump -T 1027136.so

1027136.so:     file format elf64-x86-64

DYNAMIC SYMBOL TABLE:
0000000000000000  w   DF *UND*  0000000000000000  GLIBC_2.2.5 __cxa_finalize
0000000000000000  w   D  *UND*  0000000000000000              _ITM_deregisterTMCloneTable
0000000000000000  w   D  *UND*  0000000000000000              __gmon_start__
0000000000000000  w   D  *UND*  0000000000000000              _ITM_registerTMCloneTable
00000000000010f5 g    DF .text  000000000000000b  Base        _Z22exported_test_functionv

What is the platform, how is the assembly performed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question