also linking into the boost binaries when I run cling .
cling -std=c++11 -I /opt/local/include etc
and runnning the following code (simple example from boost website)
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp>
int add (int i, int j) { return i + j ; }
BOOST_AUTO_TEST_CASE( my_test ) {
BOOST_CHECK ( add(2,2) == 6 ) ;
}
This compiles links and runs using clang but the cling interpreter seems to struggle with the macro implementation in 1) and won’t run when loaded using .x or .L in case 2) .
My guess is that it’s looking for main in 2) - but the main function expects three arguments - a function pointer , argc = 1 and argv[0] path to the binary as far as I can tell.
Subsidiary question - Is it possible to pass function pointers around on the command line in cling.
Context:
I’m trying to write a unit test library to demonstrate std lib code for training purposes, the idea being that you fix the tests to learn the various features of algos strings etc etc . I am trying out cling so that a REPL approach can be used as an alternative to the time consuming way of compiling and linking.
NB I’ve found cling very useful in getting up to speed with c++ after a break. Great job!
Hi,
I am not sure, what happens here: could you come up with a standalone reproducer? Also could you show what are the output/errors you are getting?
Yes, cling supports full set of C++ so you should be able to work with function pointers at the prompt. (This is a generic answer to a generic question, if not sufficient please narrow it down)
Hi steps to generate errors as follows - example code and error output attached
header only version built as follows: booststuff.cpp (179 Bytes)
c++ booststuff.cpp -std=c++11 -I /opt/local/include -o booststuff
output of ./booststuff below:
Running 1 test case…
booststuff.cpp:6: error: in “my_test”: check 2 == 6 has failed
*** 1 failure is detected in the test module “MyTest"
running same code via cling as follows:
cat booststuff.cpp | cling -std=c++11 -I /opt/local/include 2> include_only_errors include_only_errors.txt (2.77 KB)
to check to see whether there was a problem with loading complex macros I built and linked to boost libs as follows: booststuff_dyn.cpp (168 Bytes)
c++ booststuff_dyn.cpp -std=c++11 -I /opt/local/include -o booststuff_dyn -L /opt/local/lib -lboost_unit_test_framework-mt
the compiled binary version generates the same output as above