Undefined symbol when i load a dynamic library(.so)

HI
i am loading a dynamic library(.so) in cling shell,
for some reason, the dynamic library is depended on an external variable,
so it’s obvious to report error when i .L the .so,
can i define the variable in cling shell then load the .so?

the result shows me that it’s still failed, seems the variable i defined in cling shell can not be “recognized” by the .so during the loading.

any suggestion?

Xinghao Chen
Thanks a lot

What is the error that you get exactly?

How does this relate to How to upload two .so which are depended on each other ? If it’s the same: please don’t open two topics on the same - well, topic, at the same time. If it’s different, please provide the info that Wile_E asked for. Thanks!

it’s not the same topic,
since it’s a private library, so exact missing symbol should not be relevant.
anyway, see below

[cling]$ .L libcpss.so
cling::DynamicLibraryManager::loadLibrary(): /mnt/disk1/ericxh/work/git_work/compilation_root/sim64_DX_SHARED/libcpss.so: undefined symbol: multiProcessAppDemo

[cling] int multiProcessAppDemo=1; [cling] multiProcessAppDemo
(int) 1
[cling] .g multiProcessAppDemo input_line_3 2 (address: NA) int multiProcessAppDemo = 1 [cling] .L libcpss.so
cling::DynamicLibraryManager::loadLibrary(): /mnt/disk1/ericxh/work/git_work/compilation_root/sim64_DX_SHARED/libcpss.so: undefined symbol: multiProcessAppDemo

can i define global variable in cling shell, then upload .so which depends on this variable?

Thanks
Xinghao Chen

Hi,
Shared libraries cannot resolve symbols from the interpreter - they don’t see those.
Cheers, Axel.

Thanks Axel,

i tried a simple case to load one libhello.so, seems the libhello.so is loaded, while i can’t call the function defined in the libhello.so from the cling shell.

sorry i am a newbie for cling, sorry to wast your time if it’s too simple a problem.
see below -

hello.h
#include <stdio.h>
void pppp();

hello.c
#include “hello.h”
void pppp()
{
printf(“hello world!\n”);
}

gcc -fPIC -shared hello.c -o libhello.so
file libhello.so
libhello.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3d0d016907ebe423337f726d96ef40d61981d14b, not stripped

[cling] .L libhello.so [cling] .L hello.h
[cling] pppp(); IncrementalExecutor::executeFunction: symbol '_Z4ppppv' unresolved while linking [cling interface function]! You are probably missing the definition of pppp() Maybe you need to load the corresponding shared library? [cling]

ericxh@MSH-PC2973:/proc/4962$ cat maps
55edf2696000-55edf712a000 r-xp 00000000 08:11 25711313 /mnt/disk1/ericxh/work/git_work/interpreter/inst/bin/cling
55edf732a000-55edf772c000 r–p 04a94000 08:11 25711313 /mnt/disk1/ericxh/work/git_work/interpreter/inst/bin/cling
55edf772c000-55edf779f000 rw-p 04e96000 08:11 25711313 /mnt/disk1/ericxh/work/git_work/interpreter/inst/bin/cling
55edf779f000-55edf77ec000 rw-p 00000000 00:00 0
55edf787c000-55edf7be3000 rw-p 00000000 00:00 0 [heap]
7f7b4c8a4000-7f7b4c8a5000 r-xp 00000000 08:11 28844635 /mnt/disk1/ericxh/work/git_work/marvell/cpss/testScript/libhello.so
7f7b4c8a5000-7f7b4caa4000 —p 00001000 08:11 28844635 /mnt/disk1/ericxh/work/git_work/marvell/cpss/testScript/libhello.so
7f7b4caa4000-7f7b4caa5000 r–p 00000000 08:11 28844635 /mnt/disk1/ericxh/work/git_work/marvell/cpss/testScript/libhello.so
7f7b4caa5000-7f7b4caa6000 rw-p 00001000 08:11 28844635 /mnt/disk1/ericxh/work/git_work/marvell/cpss/testScript/libhello.so

—it’s working with gcc built –
gcc main.c -L . -lhello -o main
./main
hello world!

Thanks
Xinghao Chen

Try to create your library using a C++ compiler:
g++ -fPIC -shared hello.c -o libhello.so

If you want to stay with a pure C compiler, use:

/* hello.h */
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
  void pppp();
#ifdef __cplusplus
}
#endif

You’re building a C library (gcc, .c), but including the header into a C++ interpreter. Either compile as C++ or enclose the declarations in extern "C".

Thanks Axel & Wile_E

extern “C” {} solve this problem.

i think this topic can be closed.
Thanks a lot
Xinghao Chen

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.