Error in linking user defined .cc files with ns-3 program

1,308 views
Skip to first unread message

Rohit Kalsekar

unread,
Nov 30, 2016, 12:39:29 AM11/30/16
to ns-3-users
Hello Everyone,

I wanted to incorporate a few " .cc " files in an ns-3 program. I called the corresponding header files in the ns-3 code and kept all those files in the scratch folder while running the ns-3 program as well. However, I received "Undefined reference" for all the functions which were written in those ".cc" files. How to tackle this issue ? 

Thanks,
Rohit 

Konstantinos

unread,
Nov 30, 2016, 5:31:01 AM11/30/16
to ns-3-users
Hi,

Those ".cc" files are definitions of classes etc? 
In order to compile them, you need to place them either inside a new module or for simplicity, inside a folder in scratch.
So, create a folder inside your scratch, place there your ".cc" and ".h" files you need to compile, and also have there your scenario file.
Note that ONLY ONE ".cc" file with a main() method has to be inside that folder.

Regards,
K.

Rohit Kalsekar

unread,
Nov 30, 2016, 10:49:21 AM11/30/16
to ns-3-users
Hi,

Thank you for your reply. 
Yes, those are those ".cc" files are the definitions of classes and functions. 
So, I have to placed the my ()main ".cc" file (ns-3 file) inside a new folder created in scratch along with other .cc & .h files. Also, I have kept the same file ()main ".cc" file (ns-3 file) in the scratch folder. Is it the correct way to link all those files with ns-3 code ? Moreover, in this case, do I have to run the ()main ns-3 program by the same command ./waf --run scratch/filename.cc ? 

Thanks,
Rohit

Konstantinos

unread,
Nov 30, 2016, 11:08:20 AM11/30/16
to ns-3-users
Only one copy of your ns-3 file should exist and that should be inside the sub-folder in scratch.
To run the code, you would need to call the subfolder name, e.g. ./waf --run subfolder

It is all documented in the ns-3 manual/tutorial.

Regards,
K

Rohit Kalsekar

unread,
Nov 30, 2016, 3:21:20 PM11/30/16
to ns-3-users
Thank you sir. It worked correctly after putting that command.

Best Regards,
Rohit K

Mahesh

unread,
Aug 1, 2017, 7:11:32 AM8/1/17
to ns-3-users
Hello,

I am running a simulation present at this link: 


I have copied all the files (both .cc and .h) to a directory "wifi-spectrum-directional-test" inside scratch folder. However, when I run the program using

./waf --run scratch/wifi-spectrum-directional-test/wifi-spectrum-directional-test

I am getting errors.

Waf: Entering directory `/home/mahesh/ns3/ns-allinone-3.26/ns-3.26/build'
program 'scratch/wifi-spectrum-directional-test/wifi-spectrum-directional-test' not found; available programs are: ...

How do I get the program "wifi-spectrum-directional-test.cc" running ? Please reply.

- Mahesh

Mahesh

unread,
Aug 1, 2017, 11:17:20 AM8/1/17
to ns-3-users
Someone please reply. The files are not being linked. Is there anything else that I have to do, like editing wscript file etc ?

Thanks,
Mahesh

Rohit Kalsekar

unread,
Aug 1, 2017, 11:30:20 AM8/1/17
to ns-3-users
Hi Mahesh,

Try putting only one folder "wifi-spectrum-directional-test" containing all your files in the scratch. Make sure that you don't have any files other than this folder in the scratch.
Use this command:
  ./waf --run scratch wifi-spectrum-directional-test

Good Luck !

Regards,
Rohit

Mahesh

unread,
Aug 1, 2017, 11:42:41 AM8/1/17
to ns-3-users
Hi Rohit,

I have only one folder "wifi-spectrum-directional-test" inside my scratch folder, I have even removed the subdir folder from scratch. Now when I run the following command:

./waf --run scratch/wifi-spectrum-directional-test

I get the following error:
Waf: Entering directory `/home/mahesh/ns3/ns-allinone-3.26/ns-3.26/build'
program 'scratch/wifi-spectrum-directional-test' not found; available programs are:...

When I run the following command (without / between scratch and wifi-spectrum-directional-test)
./waf --run scratch wifi-spectrum-directional-test

I get 
No function wifi-spectrum-directional-test defined in /home/mahesh/ns3/ns-allinone-3.26/ns-3.26/wscript

How do I resolve it ? Please reply. I am stuck on this for so long.

Thanks,
Mahesh

Konstantinos

unread,
Aug 1, 2017, 12:00:48 PM8/1/17
to ns-3-users
Dear Manesh,

If you read the output you get from the compiler more carefully, you wouldn't make this questions.
It explicitly mentions which 'programms' are available  
program 'scratch/wifi-spectrum-directional-test' not found; available programs are:...

There is no 'scrach/wifi-spectrume-directional-test' but I bet there is one named 'wifi-spectrum-directional-test' (note: no scratch in front).
This is documented in the ns-3 website https://www.nsnam.org/support/faq/writing-scripts/ and elsewhere in the documentation if you search how to run in scratch subdir.

Regards
K

Mahesh

unread,
Aug 1, 2017, 12:16:02 PM8/1/17
to ns-3-users
Hi Konstantinos,

When I run ./waf, I get

Waf: Entering directory `/home/mahesh/ns3/ns-allinone-3.26/ns-3.26/build'
[ 928/2634] Compiling scratch/ wifi-spectrum-directional-test/wild-helper.cc
[ 929/2634] Compiling scratch/ wifi-spectrum-directional-test/wifi-spectrum-directional-test.cc
[2263/2634] Compiling scratch/ wifi-spectrum-directional-test/wifi-callbacks.cc
[2300/2634] Compiling scratch/ wifi-spectrum-directional-test/wifitools.cc
[2608/2634] Linking build/scratch/ wifi-spectrum-directional-test/ wifi-spectrum-directional-test
Waf: Leaving directory `/home/mahesh/ns3/ns-allinone-3.26/ns-3.26/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (30.036s)

Then I execute ./waf --run wifi-spectrum-directional-test, I get

Waf: Entering directory `/home/mahesh/ns3/ns-allinone-3.26/ns-3.26/build'
program 'wifi-spectrum-directional-test' not found; available programs are:...

The error still persists, although without "scratch/wifi-spectrum-directional-test". Where am I going wrong still ? Kindly respond.

Thanks,
Mahesh

Konstantinos

unread,
Aug 1, 2017, 12:23:00 PM8/1/17
to ns-3-users
What is the continuation of this sentence?
program 'wifi-spectrum-directional-test' not found; available programs are:...

which are the available programms?

Mahesh

unread,
Aug 1, 2017, 12:25:55 PM8/1/17
to ns-3-users
Please find attached the error message in log.txt file.

Thanks,
Mahesh
log.txt

Konstantinos

unread,
Aug 1, 2017, 12:30:03 PM8/1/17
to ns-3-users
The program exists in the list, but the name is not the same. 
It looks as if there is a space at the beginning.  ' wifi-spectrum-directional-test', 'scratch/ wifi-spectrum-directional-test/ wifi-spectrum-directional-test'
Please check the folder name.

Mahesh

unread,
Aug 1, 2017, 12:36:52 PM8/1/17
to ns-3-users
Thanks Konstantinos ! Solved it.

It was really a stupid error of having a space at the start of folder name. Sorry for such a stupid issue ! It was frustrating me like anything.

- Mahesh
Reply all
Reply to author
Forward
0 new messages