How to use printf in NS-2 - c++

I am trying to modify the NS-2 core code by adding a simple printf statement in the function Mac802_11::command. However, no matter how many times I add the line of code (printf("hello there!\n");) and then execute ./install, nothing comes up.
Is there any other requirement before the text is displayed? By the way, I am making use of NS-2.34 on an Ubuntu 11.04.

Go to the ns2.34 directory where your Makefile is located. Issue a make after you have made changes to the existing .cc file. Do NOT issue install.
ns-2.34$make

Related

getting include paths to work with Neovim and LSP-zero/Clangd

I'm currently Studying Computer enginering and taking embeded systems class, My isuse is that we use a custom library then compile it in a old version of Codewarrior.
how I would go about creating an include path for my lsp with nvim
I was woundering how I would go about creating an include path for my lsp with nvim, when I am not compiling the code localy but later compiling it with an old IDE
any wisdom would be apreciated.
note: in class we are required to use an exterior editor and the older version of code warrior is verry bad it is used for compiling for our micro controler but is unusable for writting code.
things I have done
I have atempted using compile_commands.json by coppying my vscode config for path location
I have tryed using a .clangd file with -I ...
I have tried other method but had no sucess so far
over all I was hopping to find a solution and have poured over the getting started page and stack overflow for several hours trying diffrent method to no avail.
The easiest approach is probably to use a .clangd file. Based on the path in your comment, the .clangd file should look like this:
CompileFlags:
Add: -I/home/bjc1269/Documents/github/libraries/lib/hc12c/include
A few things that I'm seeing in the .clangd file in your comment that don't work are:
Variable substitutions like ${workspaceFolder}. This is a VSCode feature that works in some VSCode settings like "clangd.arguments", but is not supported in a .clangd file, which is editor-agnostic (for example, it works with editors that don't have a concept of a "workspace").
Referring to your home directory as ~. Expanding ~ to /home/<username> is a feature of your shell. Command-line arguments specified in .clangd are passed directly to the compiler without being processed by the shell, so ~ will not work.
Globs like **. To be honest, I'm not even sure what the intended semantics for this could be in the context of specifying include directories.
Square brackets inside the argument to -I. Square brackets may appear in a .clangd file as YAML syntax for specifying multiple values in a list, for example you might have:
CompileFlags:
Add: [-I/path/to/directory1, -I/path/to/directory2]
But if you write -I=[/path/to/directory], the brackets just get passed on verbatim to the compiler, which does not understand this syntax.
First of all: Welcome to stackoverflow! :D
I'd recommend to use bear for this. You just simply invoke it with your build-command and the clangd LSP will read the includes automatically.

Xcode writing to file issue

I'm trying to help my son with a Programming C++ for Engineers course. I got him set up with Xcode 13.1 on his iMac but I've never used it myself. That was working great until his first assignment that required writing output to a file. We created a new Command Line Tool project and then used the File->New->File... option to create an Empty file. After doing so, selecting that file and looking at the info on the right side of the window shows that the Full Path is pointing to the directory where his main.cpp file is. Yet, when running his code nothing was being written to the file. I had assumed that just referencing the file name in his code would cause it to use a local reference and look in the same directory as main.cpp. After much Googling I found a reference that said to go to Product->Scheme->Edit Scheme... then select the Options tab in the window that opens and change the Working Directory from "$(BUILT_PRODUCTS_DIR)" to the directory containing the main.cpp file. That got the programming working correctly. My questions are:
Is there a preference setting that would tell it to always use the current project directory so that we don't have to change this every time?
Where does "$(BUILT_PRODUCTS_DIR)" point to?
What should we be doing differently?

How to set up C++ Testmate in VS Code

Ok, n00b question. I have a cpp file. I can build and run it in the terminal. I can build and run it using clang++ in VSCode.
Then I add gtest to it. I can compile in the terminal with g++ -std=c++0x $FILENAME -lgtest -lgtest_main -pthread and then run, and the tests work.
I install the C++ TestMate extension in VSCode. Everything I see on the internet implies it should just work. But my test explorer is empty and I don't see any test indicators in the code window.
I've obviously missed something extremely basic. Please help!
Executables should be placed inside the out or build folder of your workspace. Or one can modify the testMate.cpp.test.executables config.
I'd say, never assume something will "just work".
You'll still have to read the manual and figure out what are the names of config properties. I won't provide exact examples, because even though I've only used this extension for a short time, its name, and therefore full properties path, has already changed, so any example might get obsolete quite fast.
The general idea is: this extension monitors some files/folders, when they change, it assumes those are executables created using either gtest or catch2. The extension tries to run them with standard (for those frameworks) flags to obtain a list of test suites and test cases. If it succeeds, it will parse the output and create a nice list in the side panel. Markers in the code are also dependent on the exactly same parsed output, so if you have one, you have the other as well.
From the above, you need 3 things to make this work:
Provide correct path (or a glob pattern) for finding all test executables (while ignoring all non-test executables) in the extension config. There are different ways to do this, depending on the complexity of your setup, they are all in the documentation though.
Do not modify the output of the test executable. For example, if you happen to print something to stdout/stderr before gtest implementation parses and processes its standard flags, extension will fail to parse the output of ./your_test_binary --gtest-list_tests.
If your test executable needs additional setup to run correctly (env vars, cwd), make sure, that you use the "advanced" configuration for the extension and you configure those properties accordingly.
To troubleshoot #2 and #3 you can turn on debug logging for the extension (again, in the VSCode's config json), this will cause an additional "Output" tab/category to be created, where you can see, which files were considered, which were run, what was the output, and what caused this exact file to be ignored.
This messed with me for a while, I did as Mate059 answered above and it didn't work.
Later on I found out that the reason it didn't work was because I was using a Linux terminal inside windows (enabled from the features section) and I previously had installed the G++ compiler using the linux terminal so the compiler was turning my code into a .out file, for some reason TestMate could not read .out files.
Once I compiled the C++ source file using the powershell terminal it created a .exe file which I then changed the path in the setting.json as Mate059 said and it showed up.
TL;DR
Mate059 gave a great answer, go into settings.json inside your .vscode folder and modify "testMate.cpp.test.executables": "filename.exe".
For me it also worked using the wildcard * instead of filename.exe but I do not suggest to do that as in that might mess up something with the .exe from the main cpp file and what not.

Running C++ exe file in PowerShell

I'm usually not programming in C++, but this time I had to and I've got a problem executing my code in PowerShell (which I have never done before).
The program is written using CodeBlocks, it works fine. I specify arguments in Project_> Set program arguments and in does what it should, if no arguments are specified it returns an info about that, as it should.
The thing is, I built my program in CodeBlocks, then wanted to run the generated \bin\Program.exe' file in PowerShell. I enter:
C:\path\to\Program.exe
and nothing happens. I tried that with arguments, still nothing at all.
I fixed all missing .dll files, but I'm lost. Do I produce the .exe file in a wrong way? Is there any way to fix this issue?
First, make sure you're in the directory of the executable.
cd "C:\path\to\"
Then, execute the program as so:
.\"Program.exe"

How can I pass commands to the elevated application in a batch file?

I was wondering if anyone can help me. I'm currently working on a game engine project which involves its own c++ compiler. For this I'm "borrowing" the visual studio 2013 c++ compiler. everything works fine. The problem I am having is a cant figure out how I would pass commands to the elevated program in a batch file.
Let me Explain, right now I am using a program which calls the "vcvarsall.bat" file and passes in "x86" as a parameter. This is great for manual entry as it then allows me to input the commands to compile files. E.G "cl /EHsc <cpp files>"
As of now, when I add commands after I call "vcvarsall.bat", they just give me a command reference error saying the command is not recognized.
What I want to achieve is being able to call one bat file which executes and compiles all of my code for me. instead of having to manually type in the commands every time. This way the entire process is easier for the user.
Any help would be appreciated,
Thank you in advance!
when I add commands after I call "vcvarsall.bat"
Maybe it has been too long since I last did a batch file .. hope the following gets you started:
I think any .bat file will accept parameters, and internally, the .bat writer (i.e. you) uses special identifiers. Often they are named something like %1 and %2, etc. (some scripting languages use $1, and probably a few other approaches)
Without consuming these parameters in your .bat file, the command line interpreter tries to use the parameter as another command (so you get 'command not recognized')
Search all .bat files on your system for %1 (or $1 or whatever) ... maybe you'll find enough hints.
Thank you all for the help, the way I solved the problem was by finding the last batch file which was called and making the end of the file call another batch file in the main compile directory, this means I can programatically generate this batch file making it incredibly easy to generate custom compilations. thank you all,
Alister