How to specify standard input to Cevelop/EclipseC/C++ when running the program? - eclipse-cdt

I currently have the input file hard coded in the C++ code:
constexpr auto SELECTED_COLLEGES {"rva-ceeb-working.txt"};
std::ifstream ifs {SELECTED_COLLEGES, std::ios::in};
I intend to change the code to use standard input instead. When I run the program from the command line I will specify the file as:
$ aptcp <rva-ceeb-working.txt
How do I tell Cevelop/EclipseC/C++ that when it runs the program to use rva-ceeb-working.txt for standard input?
Cevelop C++ IDE
Version: 1.8.0-201707131430
Eclipse C/C++ Development Tools
Version: 9.3.0.201706122201
Build id: #build#
Eclipse Help
Version: 2.2.100.v20170612-0950
Build id: I20170612-0950
OS: Linux, v.4.10.0-37-generic, x86_64 / gtk 3.22.11

Run > Run Configurations... > Common > Input File

Related

Gradle Cpp-Application not detecting gcc in windows

I am starting to get into c++ more and I have began learning gradle to use as the build too for it. I am using gradle's cpp-application plugin for compiling the code. However when I try to build it gradlew tells me that it can't detect gcc, my only installed compiler.
I have for the most part followed the guide on gradle's website (https://guides.gradle.org/building-cpp-executables/). That is where I came up with most of the code so far.
I have gcc from ming-w32 installed in my path correctly (I can run it from the command prompt and through make without any issues)
I am also using a gradlew install that was made with gradle 5.2.1
I am, for the most part, using the exact setup in the gradle guide.
apply plugin : 'cpp-application'
application {
baseName = "test"
}
^ /$Project/build.gradle
This is the command line output when i run gradlew assemble
* What went wrong:
Execution failed for task ':compileDebugCpp'.
> No tool chain is available to build C++ for host operating system 'Windows 10' architecture 'x86-64':
- Tool chain 'visualCpp' (Visual Studio):
- Could not locate a Visual Studio installation, using the command line tool, Windows registry or system path.
- Tool chain 'gcc' (GNU GCC):
- Could not determine GCC metadata: failed to execute gcc.exe -m64 -dM -E -v -.
- Tool chain 'clang' (Clang):
- Could not find C++ compiler 'clang++' in system path.
When I run the command that they say failed to execute in the same command prompt (gcc.exe -m64 -dM -E -v -.)
I do get output from gcc without any errors that I can see
If you are curious on what it outputs you can find it here
I would expect that the issue isn't with my cpp code because it isn't ever recognizing the compiler but it is fairly short so I might as well.
#include <iostream>
int main(int argc, char** argv) {
std::cout << "Hello World!!" << std::endl;
return 0;
}
^ /$Project/src/main/cpp/main.cpp
By default, Gradle tries to locate a tool chain that matches your system's architecture (x86_64), but you only have a 32-bit MinGW
A workaround is to explicitly configure a 32-bit target in your Gradle script:
application {
targetMachines = [ machines.windows.x86 ]
}

eclipse CDT pretty-printing not working for strings

I am trying to Get gdb pretty-print working in eclipse, it seems to be working for all stl elements and containers baring std::string
basically if i have a vector like:
std::vector<std::string> m_vec = {"hello" , "world"};
each element of the vector shows a string and it shows the contents like "hello" and "world".
but if i have a code like
std::string m_string = "hello world";
m_string shows up empty, even though i can do string operations on the contents. Not sure why only strings alone is causing as issue with pretty print.
Any help/pointers would be much appreciated.
Edited:
Few more details regarding the setup:
IDE: Eclipse Luna 4.4.2
Compiler: Cygwin g++ 5.4.0
Debugger: Cygwin gdb 7.10.1
phython : Cygwin phython 3.6
Update: Don't know how exactly, but windows restart solved it, can see string now in preety-print.
For adding support for gdb pretty-printing in cygwin you need the following file available:
/usr/share/gdb/auto-load/usr/bin/cygstdc++-6.dll-gdb.py
It is available in gcc-debuginfo-5.4.0-1 package in cygwin package installer.
Note: This might break once packages get updated in Cygwin repository. So you will need to again locate this file in the Cygwin package search.
Update: Check the version of python interpreter supported by gdb by running the following commands in the gdb console:
(cygwin console) $ gdb
(gdb) python
>import sys
>print(sys.version)
>end
You should see output something like this(in my case it defaults to python2.7 interpreter):
2.7.13 (default, Mar 13 2017, 20:56:15)
[GCC 5.4.0]

Codelite issue--No executable specified,use 'target exec

I have just installed codelite in my windows 8.1.It shows error
Debugger exited with the following error string:
"No executable
specified,use 'target exec'"
I searched and found this (another stackoverflow question) I did the same as mentioned there but nothing really worked for me.I made a new project and selected Simple executable (g++) and GNU debugger as default debugger.Can anybody help me with this.Also it shows "Program exited with return code: 4199040".
It seems that you don't provide executable to run/debug:
Go to
Project settings... -> Common settings -> General
and fill correct information for
Executable to Run / Debug
Jarod42 provided a 'close enough' answer. On Linux the steps seem to be:
Workspace -> Open Active Project Settings... -> General
and fill correct information for
Executable to Run / Debug
In the command prompt:
gdb (program type: example python or c or c++ etc)
If am running python program then the command will be gdb python
then (gdb) run program_name.py

How do redirect STDOUT out of XCode compiled Command Line executable?

I have a C++ program that writes to stdout that I am trying to compile into a command line utility in XCode. I need the program compiled into a release build (which it seems, XCode calls an Archive - go figure), not run it as debug.
I basically want to pipe the output of my program into a textfile like this
MyProgram > TextFile.txt
I can compile the program into a command line and run it like this via a Bash shell like this:
Open MyProgram
This spawns a new process (not what I want). However, I could live with that if this worked:
Open MyProgram > TextFile.txt
...But it doesnt :-(. If I try to just run MyProgram directly from Bash, I get the error: -bash: MyProgram: command not found.
What am I doing wrong? How can I compile my command line tool to NOT require the Open command under Mac OSX?
Thanks for any help you can provide. I am picking up C++ on the Mac platform and I am beginning to find it quite it a bit more troublesome than Visual Studio. Does it ever get less painful to work with? :-)
Make your project a Command Line Tool. This will make it so you can run it from the command line directly.
Run it by typing ./MyProgram or ./MyProgram > TextFile.txt not open MyProgram.

What is a 'shebang' line?

Currently I'm trying to start programming on my new Mac. I installed TextWrangler, and chose C++ as my language of choice; since I have some prior knowledge of it, from when I used Windows.
So, I wrote the ever so common "Hello World" program. Although, when I tried to run it, I got an error:
"This file doesn’t appear to contain a valid ‘shebang’ line (application error code: 13304)"
I tried searching the error code to find out how to fix this, but I couldn't find anything.. I have no idea what a 'shebang' line is... Can someone help me out?
You need to compile it with a compiler first. I assume you tried to run the source file like ./source but C++ doesn't work this way.
With some compilers however, you can provide a shebang-line as the first line of the source file (the #! is known as shebang or crunchbang, hence the name), like so:
#!/path/to/compiler
So that the shell knows what application is used to run that sort of file, and when you attempt to run the source file by itself, the compiler will compile and run it for you. That's a compiler-dependent feature though, so I recommend just plain compiling with G++ or whatever Macs use to get an executable, then run that.
While I wouldn't recommend it for regular C++ development, I'm using a simple shell script wrapper for small C++ utilities. Here is a Hello World example:
#if 0 // -- build and run wrapper script for C++ ------------------------------
TMP=$(mktemp -d)
c++ -o ${TMP}/a.out ${0} && ${TMP}/a.out ${#:1} ; RV=${?}
rm -rf ${TMP}
exit ${RV}
#endif // ----------------------------------------------------------------------
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Hello world" << std::endl;
return 0;
}
It does appear that you are trying to run the source file directly, however you will need to compile using a C++ compiler, such as that included in the gcc (GNU Compiler Collection) which contains the C++ compiler g++ for the Mac. It is not included with the Mac, you have to download it first:
from http://www.tech-recipes.com/rx/726/mac-os-x-install-gcc-compiler/ : "To install the gcc compiler, download the xcode package from http://connect.apple.com/. You’ll need to register for an Apple Developer Connection account. Once you’ve registered, login and click Download Software and then Developer Tools. Find the Download link next to Xcode Tools (version) – CD Image and click it!"
Once it's installed, if you are going for a quick Hello World, then, from a terminal window in the directory of your source file, you can execute the command g++ HelloWorld.cpp -o HelloWorld. Then you should be able to run it as ./HelloWorld.
Also, if you're coming from a Visual Studio world, you might want to give Mono and MonoDevelop a try. Mono is a free implementation of C# (and other languages), and MonoDevelop is an IDE which is very similar to Visual Studio. MonoDevelop supports C# and other .NET languages, including Visual Basic .NET, as well as C/C++ development. I have not used it extensively, but it does seem to be very similar to VS, so you won't have to learn new everything all in a day. I also have used KDevelop, which I liked a lot while I was using it, although that's been a while now. It has a lot of support for GNU-style development in C/C++, and was very powerful as I recall.
Good luck with your endeavors!
Links:
Mono: http://mono-project.com/Main_Page
MonoDevelop: http://monodevelop.com/
KDevelop: http://kdevelop.org/
shebang is http://en.wikipedia.org/wiki/Shebang_%28Unix%29.
not sure why your program is not running. you will need to compile and link to make an executable.
What I find confusing (/interesting) is C++ program giving "Shebang line" error. Shebang line is a way for the Unix like operating system to specify which program should be used to interpret the rest of the file. The shebang line usually points to the path of the interpreter. C++ is a compiled language and does not have interpreter for it.
To get the real technical details of how shebang lines work, do a man execve and get that man page online here - man execve.
If you're on a mac then doing something like this on the commandline:
g++ -o program program.cpp
Will compile and link your program into an executable called program. Then you can run it like:
./program
The reason you got the 'shebang' error is probably because you tried to run the cpp file like:
./program.cpp
And the shell tries to find an interpreter to run the code in the file. Because this is C++ there is no relevant interpreter but if your file contains Python or Bash then having a line like this
#!/usr/bin/python
at the 1st line in your source file will tell the shell to use the python interpreter
The lines that start with a pattern like this: #!/.../.../.. is called a shebang line. In other words, a shebang is the character sequence consisting of the characters number sign and exclamation mark (#!).In Unix-like operating systems, when a text file with a shebang is used as if it is an executable, the program loader mechanism parses the rest of the file's initial line as an interpreter directive. The loader executes the specified interpreter program, passing to it as an argument the path that was initially used when attempting to run the script, so that the program may use the file as input data.