Hi,
I built stand alone cling on Ubuntu Linux version 20.04.1 using gcc 9.4.0. It seems to have built without issue.
If I run the following simple commands interactively, it prints “a = 9”.
< ****************** CLING ******************
< * Type C++ code and press enter to run it *
< * Type .q to exit *
< *******************************************
< [cling] #include <iostream>
< [cling] int a = 9;
< [cling]$ std::cout << "a = " << a << “\n”;
< a = 9
< [cling]$ .q
If I put these exact commands in a file called test.cpp, and load test.cpp with .L it causes errors because cout is not within the scope of main or a function.
< ****************** CLING ******************
< * Type C++ code and press enter to run it *
< * Type .q to exit *
< *******************************************
< [cling]$ .L test.cpp
< In file included from input_line_3:1:
< /home/ubuntu/software/cling/junk/test.cpp:3:6: error: no type named ‘cout’ in namespace ‘std’
< std::cout << "a = " << a << “\n”;
< ~~~~~^
< /home/ubuntu/software/cling/junk/test.cpp:3:11: error: expected unqualified-id
< std::cout << "a = " << a << “\n”;
< ^
< [cling]$ .q
If the instructions are put in the body of main, nothing is printed. If these same lines are put in a file and loaded with .L the result the same, nothing printed.
< ****************** CLING ******************
< * Type C++ code and press enter to run it *
< * Type .q to exit *
< *******************************************
< [cling] #include <iostream>
< [cling] int main(int argc, char** argv) {
< [cling] ? int a = 9;
< [cling] ? std::cout << "a = " << a << “\n”;
< [cling]$ ? }
< [cling]$ .q
I also tried:
.> test.out
.L test2.cpp
It created an empty file.
Is this the expected behavior? Is there some way to make it print?
Thanks,
Gene