Search code examples
c++ns2

error while Linking c++ and ns2?


had done following steps Download "ex-linkage.cc" file, and save it under the "ns-2" directory. Open "Makefile", add "ex-linkage.o" at the end of object file list.

Re-compile NS using the "make" command. Download the "ex-linkage.tcl" file

that contains "MyAgent" testing OTcl commands.

Run the OTcl script using command "ns ex-linkage.tcl".


i am getting following error

$ ./ns ex-linkage.tcl
invalid command name "Agent/MyAgentOtcl" 
    while executing 
"Agent/MyAgentOtcl create o3 " 
    invoked from within 
"catch "$className create $o $args" msg" 
    invoked from within 
"if [catch "$className create $o $args" msg] { 
if [string match "__FAILED_SHADOW_OBJECT" $msg] { 
delete $o 
return "" 
} 
global errorInfo 
error "class $..." 
    (procedure "new" line 3) 
    invoked from within 
"new Agent/MyAgentOtcl" 
    invoked from within 
"set myagent [new Agent/MyAgentOtcl]" 
    (file "ex-linkage.tcl" line 8

Solution


  • »» invalid command name "Agent/MyAgentOtcl" «« : Looks like you are using an executable 'ns' with no "Linkage".

    tar xvf ns-allinone-2.35_gcc482.tar.gz
    

    https://drive.google.com/file/d/0B7S255p3kFXNSGJCZ2YzUGJDVk0/view?usp=sharing

    cd ns-allinone-2.35/
    patch -p0 < linkage_ns235.patch
    

    https://drive.google.com/file/d/0B7S255p3kFXNYmZ0SWFQaUNhWTA/view?usp=sharing

    ./install
    cd ns-2.35/
    sudo make install
    cp ns ns235-linkage
    sudo cp ns235-linkage /usr/local/bin/
    
    Simulation : ns235-linkage ex-linkage.tcl
    .
    warning: no class variable Agent/MyAgentOtcl::my_var2_otcl
    .
    Message From MyPrivFunc
         my_var1 = 2
         my_var2 = 3.140000
    

    Using the "ns235-linkage" command makes sure you are using the right 'ns'. P.S. : You are not recompiling with 'make', but with 'make clean && make'. Or by running './install' in the top directory ns-allinone-2.35/.