Wow! Fantastic work. A few questions / issues

I just bumped into Cling and I wanted to congratulate you guys, this is some great work!

I literally just build cling and obviously I’m a complete newbee but I did run into some issues and I was hoping to get some questions down as well.

Firstly, it appears .U does not work (at least on OSX 10.9) with the latest git repo. I built cling from source and had a very simple Test.cpp, which loads fine in cling and executes its function just fine. However, when I try to unload it via .U I get the following assertion hit:

Hello World[cling]$ .U Test.cpp
Assertion failed: (Pos != Map->end() && “no lookup entry for decl”), function removeDecl, file /Users/lasti/Documents/Source/cling/src/tools/clang/lib/AST/DeclBase.cpp, line 1162.
Abort trap: 6

after which cling just exits. The Test.cpp is completely trivial:

#include
void Test()
{
printf(“Hello World”);
}

So, I’m not sure if this is a known bug or?..

My other question is, I see how people have already integrated cling into their application and the interpreter can be embedded to provide ‘interactive’ C++ from within an app. This is already awesome! However, I’m not clear if it is possible, and how would one go about, completing the circle and actually re-linking the newly compiled symbols into the running binary?

Let me try to explain what I mean: Say you have a program main(), which has an object Foo in Foo.cpp. Foo is compiled and linked in and used in your program. Is it then possible to use cling to change Foo.cpp at runtime and have that object/symbol relinked into the program dynamically? If so, what would be the approach to take?

Thanks so much, and again, great work!

#include // for printf … cplusplus.com/reference/cstdio/

Oh yes, the fixes the .U problem.

Hmm, this still appears to have issues or maybe I’m not using it properly? Firstly I found that although .U appears to work, attempting to reload with .L fails unless you get rid of the include altogether from the script file.

When you get rid of the include and manually include the header before the .L reload you don’t get errors but the symbol is stale. That is, if I change Test.cpp after .U and load it again with .L the function is not updated.

So there’s something going wrong here or is there something special you need to do to reload a script?

Hi,

I can reproduce that; I get the following errors:

[cling]$ .x Test.C
Hello World[cling]$ .U Test.C
[cling]$ .x Test.C
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:35:
/usr/include/x86_64-linux-gnu/bits/types.h:134:26: error: typedef redefinition with different types ('struct __fsid_t' vs 'struct __fsid_t')
__STD_TYPE __FSID_T_TYPE __fsid_t;      /* Type of file system IDs.  */
                         ^
/usr/include/x86_64-linux-gnu/bits/types.h:134:26: note: previous definition is here
__STD_TYPE __FSID_T_TYPE __fsid_t;      /* Type of file system IDs.  */
                         ^
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:74:
In file included from /usr/include/libio.h:31:
In file included from /usr/include/_G_config.h:20:
/usr/include/wchar.h:94:3: error: typedef redefinition with different types ('struct __mbstate_t' vs 'struct __mbstate_t')
} __mbstate_t;
  ^
/usr/include/wchar.h:94:3: note: previous definition is here
} __mbstate_t;
  ^
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:74:
In file included from /usr/include/libio.h:31:
/usr/include/_G_config.h:25:3: error: typedef redefinition with different types ('struct _G_fpos_t' vs 'struct _G_fpos_t')
} _G_fpos_t;
  ^
/usr/include/_G_config.h:25:3: note: previous definition is here
} _G_fpos_t;
  ^
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:74:
In file included from /usr/include/libio.h:31:
/usr/include/_G_config.h:30:3: error: typedef redefinition with different types ('struct _G_fpos64_t' vs 'struct _G_fpos64_t')
} _G_fpos64_t;
  ^
/usr/include/_G_config.h:30:3: note: previous definition is here
} _G_fpos64_t;
  ^
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:74:
/usr/include/libio.h:160:8: error: redefinition of '_IO_marker'
struct _IO_marker {
       ^
/usr/include/libio.h:160:8: note: previous definition is here
struct _IO_marker {
       ^
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:74:
/usr/include/libio.h:245:8: error: redefinition of '_IO_FILE'
struct _IO_FILE {
       ^
/usr/include/libio.h:245:8: note: previous definition is here
struct _IO_FILE {
       ^
In file included from input_line_5:1:
In file included from /home/axel/build/root/github/src/Test.C:1:
In file included from /usr/include/stdio.h:74:
/usr/include/libio.h:375:3: error: typedef redefinition with different types ('struct _IO_cookie_io_functions_t' vs 'struct _IO_cookie_io_functions_t')
} _IO_cookie_io_functions_t;
  ^
/usr/include/libio.h:375:3: note: previous definition is here
} _IO_cookie_io_functions_t;
  ^

I have created sft.its.cern.ch/jira/browse/ROOT-7784 for it.

Thanks for reporting!

Axel.

Have you found an answer to this?

Hi,

Sorry - I overread that question :frowning:

What I’d recommend is to not have Foo linked in, but let the interpreter deal with it. Then you can unload the old one and load a new one.

Cheers, Axel.