QtCreator + ns-3 for newbie

664 views
Skip to first unread message

Stanislav Fateev

unread,
Mar 17, 2013, 8:12:06 AM3/17/13
to ns-3-...@googlegroups.com
Hi! I want to use ns-3 scripts with my programs(interface) written in Qt (QtCreator 2.5.0). I have read http://www.nsnam.org/wiki/index.php/HOWTO_configure_QtCreator_with_ns-3 and used second variant. I have added tutorial/hello-simulator.cc, copied the code to main.cpp, removed hello-simulator and added INCLUDEPATH += ~/ns-allinone-3.15/ns-3.15/build/ in .pro file. In result i've got this error message:
main.o:-1: In function `_GLOBAL__sub_I_main':
main.cpp:-1: error: undefined reference to `ns3::LogComponent::LogComponent(char const*)'
:-1: error: collect2: error: ld returned 1 exit status


I've tried to use tutorial/first.cc but got same error messages. It's a really trouble to me due to my poor knowledge of C++/Qt. What can i do to solve it?


John Abraham

unread,
Mar 17, 2013, 10:55:41 AM3/17/13
to ns-3-...@googlegroups.com
Have you added the following defines to the end in the *.pro file?

DEFINES += NS3_LOG_ENABLE
DEFINES += NS3_ASSERT_ENABLE

if not try and rebuild.
> --
> You received this message because you are subscribed to the Google Groups
> "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ns-3-users+...@googlegroups.com.
> To post to this group, send email to ns-3-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ns-3-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Stanislav Fateev

unread,
Mar 18, 2013, 12:08:05 AM3/18/13
to ns-3-...@googlegroups.com
I have added this defines now but there is no change. Maybe linker couldn't find a source of some ns3 functions?

John Abraham

unread,
Mar 18, 2013, 12:09:56 AM3/18/13
to ns-3-...@googlegroups.com
is the object file being created? you could search for "log.o"

On Sun, Mar 17, 2013 at 9:08 PM, Stanislav Fateev <ftu...@gmail.com> wrote:
> I have added this defines now but there is no change. Maybe linker couldn't
> find a source of some ns3 functions?
>

Stanislav Fateev

unread,
Mar 18, 2013, 12:27:53 AM3/18/13
to ns-3-...@googlegroups.com
There is no "log.o". I have added all cc and h files from /src/core/model but there is no change. "log.o" must have been created with waf - "waf build"?

John Abraham

unread,
Mar 18, 2013, 12:36:07 AM3/18/13
to ns-3-...@googlegroups.com
i thought you were trying to build ns-3 without waf. Qt can build it ,
for instance my Qt directory after building core looks like

John-Abrahams-MacBook-Pro:qtns3 john$ ls
Makefile double.o list-scheduler.o qtns3.pro string.o unix-fd-reader.o
attribute-construction-list.o enum.o log.o qtns3.pro.user synchronizer.o unix-system-condition.o
attribute.o event-id.o make-event.o random-variable-stream.o system-path.o unix-system-mutex.o
boolean.o event-impl.o map-scheduler.o random-variable.o system-thread.o unix-system-wall-clock-ms.o
breakpoint.o fatal-impl.o names.o realtime-simulator-impl.o test.o vector.o
cairo-wideint.o global-value.o object-base.o ref-count-base.o time.o wall-clock-synchronizer.o
calendar-scheduler.o heap-scheduler.o object-factory.o rng-seed-manager.o timer.o watchdog.o
callback.o hello-simulator.o object-ptr-container.o rng-stream.o trace-source-accessor.o
command-line.o int64x64-128.o object.o scheduler.o type-id.o
config.o int64x64.o pointer.o simulator-impl.o type-name.o
default-simulator-impl.o integer.o qtns3.app simulator.o uinteger.o

If you trying ns-3 for the first time, I would not recommend building
it without waf.

-john

Stanislav Fateev

unread,
Mar 18, 2013, 12:59:39 AM3/18/13
to ns-3-...@googlegroups.com
So, i have to use 1st variant from the FAQ (with waf)? It is runnig OK, but i dont understand how to add existing Qt forms and some code using QXml, QFile etc to this. Working environment look like not Qt project, there is no .pro file, I need to write a gui program which takes some data from user, use this data in modified code of one of the ns3 examles and display a result. Maybe if i see code of simple project using Qt gui&ns-3 it will be clear for me.

John Abraham

unread,
Mar 18, 2013, 1:07:28 AM3/18/13
to ns-3-...@googlegroups.com
my suggestion is to create a simple QML/GUI app first via QtCreator.
Right-click the project and "Add existing files" (ofcourse they should
not contain main() ), from the model and helper directories of ns-3.
Then click build, check if Qt is indeed creating *.o files.

If you get past compilation/linker errors, call some ns-3 code from
the main function.

John Abraham

unread,
Mar 18, 2013, 1:11:03 AM3/18/13
to ns-3-...@googlegroups.com
and dont forget the DEFINE s in the pro file

Stanislav Fateev

unread,
Mar 18, 2013, 1:43:05 AM3/18/13
to ns-3-...@googlegroups.com
Thank you very much, John. I have added log.h, log.cc, fatal-error.h, fatal-impl.h, fatal-impl.cc and have got a working GUI hello simulator. Now i'll try something more difficult.

Stanislav Fateev

unread,
Apr 1, 2013, 11:32:14 AM4/1/13
to ns-3-...@googlegroups.com
Ok. I have a working GUI that runs scenario and model (written by other programmer). This scenario uses the data from GUI. I want to run this scenario many times, with the button 'Compute' in GUI, for example. Scenario starting and printing some calculated data, but every time when i click button 'Compute' it gives me different data values. I think this happens because i'm not cleaned something from last run, and i stuck here. How to make that everything runs as if for the first time?

piece of code (button 'Compute'):


  Ptr<MyScenario> obj1 = CreateObject<MyScenario> (filename, nodeCount, totalTime);
   obj1->CreateScenario();
   obj1>SetBackgroundNstreamTraffic (load);
   obj->InstallTraffic ();
   MyDetermAccessStatistics *stat = MyDetermAccessStatistics::GetInstance();
   stat>SetWarmUpTime(warmUpTime);
   Simulator::Stop (Seconds (totalTime));
   lrr::GlobalGraph::Instance ()->Start ();
   Simulator::Run ();
   lrr::GlobalGraph::Instance ()->Stop ();
   obj1->ReportScenario ();
   obj1->ReportPdrBySequenceNumber();
   MyDetermAccessStatistics::Destory();
   Simulator::Destroy ();
   obj1  = 0;

John Abraham

unread,
Apr 1, 2013, 11:44:30 AM4/1/13
to ns-3-...@googlegroups.com
i think you are asking for Simulator Restart? I don't believe it is possible to do that currently because once the Simulator object comes into existence , a lot of initialization is done.  I am not sure if "Simulator::Destroy" does all the clean up.

You might want to create a new thread with a different subject line about multiple instances of the simulator.


Dimitri Podborski

unread,
Mar 6, 2015, 12:08:17 PM3/6/15
to ns-3-...@googlegroups.com, ftu...@gmail.com
If you want to build with qmake within qtcreator (second variant) you also have to specify the libs you are using. For example in order to compile first.cc with qmake add following lines to the project file:
LIBS += -L$$PWD/../ns-allinone-3.22/ns-3.22/build/ -lns3.22-core-debug -lns3.22-internet-debug -lns3.22-network-debug -lns3.22-point-to-point-debug -lns3.22-applications-debug -lns3.22-bridge-debug -lns3.22-mpi-debug -lns3.22-stats-debug
INCLUDEPATH += $$PWD/../ns-allinone-3.22/ns-3.22/build
DEPENDPATH += $$PWD/../ns-allinone-3.22/ns-3.22/build

Ivan Senin

unread,
Mar 13, 2015, 4:44:32 AM3/13/15
to ns-3-...@googlegroups.com, ftu...@gmail.com
Thank you, Dimitri! It really works good. It would be great if this guide will be added to HOWTO.
BTW, it is not necessary anymore to write DEPENDPATH  for qmake in Qt5 (regard to SO)
Also I wrote simple script for qmake to add all libraries (maybe it would be useful): http://pastebin.com/HvcrKjqy 

NS_BUILD_DIR = $$PWD/../3dparty/ns-3-allinone/ns-3.22/build

LIBS += -L$$NS_BUILD_DIR
INCLUDEPATH += $$NS_BUILD_DIR
win32 {
    SHARED_LIB_FILES = $$files($$NS_BUILD_DIR/*.dll)
    for(FILE, SHARED_LIB_FILES) {
	BASENAME = $$basename(FILE)
	LIBS += -l$$replace(BASENAME,.dll,)
    }
}
unix {
    SHARED_LIB_FILES = $$files($$NS_BUILD_DIR/*.so)
    for(FILE, SHARED_LIB_FILES) {
	BASENAME = $$basename(FILE)
	CLEARNAME = $$replace(BASENAME,libns,ns)
	CLEARNAME = $$replace(CLEARNAME,.so,)
	LIBS += -l$$CLEARNAME
    }
}
Reply all
Reply to author
Forward
0 new messages