Eclipse Neon on Linux: no console for C/C++ programs - c

With Eclipse 4.6.2 on Ubuntu 16.04.1 I'm having trouble getting the console to work with C/C++ programs. When I run my program from a shell, it produces output on stdout and stderr and accepts input from stdin. However, when I "Run as C/C++ Appplication" in Eclipse, the console doesn't seem to work — standard output and error never appear, and there's no place to supply input.
Has anyone seen this? Any idea why it's happening? It's worth noting that Java applications that use the console work fine, so this is specific to C/C++ somehow.
Source code:
Compiler settings:
Run configuration:

There may be so many reasons for your problem but i will give you some to do list in order to solve your problem.
1) Please build your C/C++ code before you run it. You can do it via Ctrl+B button combination or by clicking on menu.
2) Be sure that you have one main function in your current project and there is no debugger errors.
3) The reason why your code is working on shell but not in Eclipse may be that your Eclipse might not know your compiler's name or path. You can check this case by following this path :
Click File on menu -> Click properties -> Expand "C/C++ Build" -> Click on "Settings".
In the opening screen you have to see gcc/g++ compiler is set properly and Command line pattern is true and working on Eclipse.
If you give more detail about your Eclipse version or some screenshots, we can help you more precisely.
Also i reccomend using "Eclipse IDE for C/C++ Developers" version of eclipse in this link : http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/keplersr2
When you install this version, probably you will not need to set so many settings to work on your projects.
Edit: That's the example usage of fputs.
#include <stdio.h>
int main ()
{
FILE *fp;
fp = fopen("file.txt", "w+");
fputs("This is c programming.", fp);
fputs("This is a system programming language.", fp);
fclose(fp);
return(0);
}

Related

VSCode issues when running a C file and displaying output

I'm trying to run C programs/files from VSCode. I've followed a guide to setting up the gcc for VSCode to use, and it "mostly" works. However, when I run a file, it only outputs to the debug console, which is rather messy. I would prefer if it only output to the "output" window.
If I click on the output window and then try to run the file, I get this error.
This is what my tasks.json file looks like, where I've tried to change build from cppbuild to shell, as well as removing the "file" lines that I saw recommended on other threads, which didn't solve my issue.
Also notice how in the drop down menu for my panel, I don't have a "Code" option that I see in other people's VSCode
TLDR: I want VSCode to display the output of a C file into the Output window, not the debug console. I also want to understand why I am given the "Cannot build and debug because the active file is not a C or C++ source file" error. MinGW has been downloaded and GCC has been set up properly, AFAIK.
Have you installed "Code Runner" extension?

VSCode Microsoft C/C++ Extension Using Old MinGW System Path

I'm trying to run a simple Hello World C program in VSCode, on Windows 10, to test whether things are going fine or not (I previously had to reinstall the OS). So this is the code:
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
Should be simple, and it should run perfectly well, I thought. I tried it with these options, which I assume was from the Code Runner (by Jun Han) extension. When I try selecting the "Run Code" option, everything works well, and the code runs perfectly. When I tried the "Debug C/C++ File" or the "Run C/C++ File" option, however, this was what I got.
* Executing task: C/C++: gcc.exe build active file
Starting build...
C:\Compilers\MinGW\bin\gcc.exe -fdiagnostics-color=always -g D:\Alfred\Studies\College\Skripsi\resources\preparations\CTest\HelloWorld.c -o D:\Alfred\Studies\College\Skripsi\resources\preparations\CTest\HelloWorld.exe
The system cannot find the path specified.
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
* Terminal will be reused by tasks, press any key to close it.
Worth noting here that C:\Compilers\MinGW\bin\gcc.exe is my MinGW directory in the system path before I reinstalled the OS. I'm not sure why it pulls that specific path, considering:
I've tested the MinGW installation on the reinstalled OS, and running the gcc --version command works on cmd,
The system environment variable has been set to the new path (C:/MinGW/bin),
If it's really a problem with MinGW paths, logically the "Run Code" option should also fail. Yet it doesn't.
Finally, I've also tried restarting the laptop, reinstalling MinGW, reinstalling VSCode (along with deleting the .vscode folder in %USERPROFILE% and Code folder in %APPDATA%), but this problem still persists.
I've been looking for the possibility as to why for hours now, yet I haven't managed to. Was hoping some of you could tell me what I overlooked here.
P.S.:
The only extensions I have installed are C/C++ by Microsoft and Code Runner by Jun Han.
Please bear with me if my question was missing some details - I have very little experience in asking questions here.
Edit 1: I've been told this was due to Microsoft's C/C++ extension, and not Jun Han's Code Runner. I have edited the title to reflect so.
The two options you mentioned are from the Microsoft's C/C++ extension: they use the C_Cpp.default.compilerPath setting to locate your compiler. You can change it either the settings GUI or in the JSON file.

Windows Defender/Security deletes my "hello world" program

I'm trying to start a new C project using BearLibTerminal, compiling with gcc.
I'm able to compile the hello world, but when I try to launch, Windows Security gives an error, which reads
"Operation did not complete successfully because the file contains a
virus or potentially unwanted software."
Shortly after compilation, whether I attempt to run or not Windows deletes the executable.
I can of course disable Windows Security real-time protection, but this seems like a bad workaround. Does anyone know what could be changed so that Windows doesn't think my program is a virus?
Here is the code:
#include "BearLibTerminal.h"
int main()
{
terminal_open();
// Printing text
terminal_print(1, 1, "Hello, world!");
terminal_refresh();
// Wait until user close the window
while (terminal_read() != TK_CLOSE);
terminal_close();
}
and this is the makefile:
gcc -IC:/foo/include -LC:/foo/bin main.c -lBearLibTerminal -o test.exe
Thanks kindly for the assistance.
EDIT: I seem to have fixed the problem. For some reason, the version of MinGW found here, which is where I was directed to from mingw.org, causes things I compile to be detected as a virus. I removed MinGW completely, and downloaded the version found on SourceForge, and I no longer have the issue. I have no idea if the compiler was somehow compromised, or if Windows Security was just looking out for things made by a specific version of MinGW, but I would note that the version of "Hello World" from the first compiler was 4kb larger than the version from the SourceForge compiler, and likewise the installer was around 6kb larger too.
As a temporary fix you can exclude your compilation folder from Windows Defender.

how do I get my eclipse CPP lunar to show ouput?

I just installed Eclipse CPP lunar for my windows 64, and I ran a couple of C code (not c++), but for some reason I can get to the console to show any output, I did the build PATH in the environment part in my properties, but still can't get anything to show. I run my C code in cmd, and everything was perfect! what should I do? do I need to add new flags, it seems the code can run well just no ouput.
update: I watched a video on youtube, and I run some c++ code and the output console is perfect for some reason, just C code I can't get any output. did I built the path wrong?
According to http://www.mochaz.com/2012/03/solution-for-no-console-output-in.html there is a workaround, where you have to add the path of the MinGW compiler (which you most likely use) to the Environment variable of your project (project specific settings).
Goto Project->Properties->Run/Debug Settings, choose the .exe file and press Edit
In the Environment tag, press New, and set it as: Name: PATH, Value: C:\MinGW\bin

Source file not compiled Dev C++

I just installed Dev C++ and I am learning C programming.
the code i used was
#include <stdio.h>
int main()
{
printf("Hello world");
getch();
}
I saved it as a .c file. When I compile it works fine, but when I compile and run it says source file not compiled. So I googled buncha things and came across this video on youtube which shows you how to fix it. I also saw other forums on google which suggest the same thing... However, after doing whats asked, Now I can't even compile my code. I get this error
Compiler: Default compiler
Executing C:\Dev-Cpp\bin\gcc.exe...
C:\Dev-Cpp\bin\gcc.exe "C:\Users\ubaid\Documents\C\Untitled1.c" -o "C:\Users\ubaid\Documents\C\Untitled1.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
gcc.exe: Internal error: Aborted (program collect2)
Please submit a full bug report.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
Execution terminated
I have also used what is asked on this link, and still no luck..
http://learntogeek.com/miscellaneous/solved-source-file-not-compiled-error-in-dev-cpp/
I am using windows 8
I was having this issue and fixed it by going to:
C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2
, then deleting collect2.exe
Install new version of Dev c++. It works fine in Windows 8. It also supports 64 bit version.
Download link is http://sourceforge.net/projects/orwelldevcpp/ .
I guess you're using windows 7 with the Orwell Dev CPP
This version of Dev CPP is good for windows 8 only. However on Windows 7 you need the older version of it which is devcpp-4.9.9.2_setup.exe
Download it from the link and use it.
(Don't forget to uninstall any other version already installed on your pc)
Also note that the older version does not work with windows 8.
This maybe because the c compiler is designed to work in linux.I had this problem too and to fix it go to tools and select compiler options.In the box click on programs
Now you will see a tab with gcc and make and the respective path to it.Edit the gcc and make path to use mingw32-c++.exe and mingw32-make.exe respectively.Now it will work.
The reason was that you were using compilers built for linux.
You can always try doing it manually from the command prompt. Navigate to the path of the file and type:
gcc filename.c -o filename
I found a solution. Please follow the following steps:
Right Click the My comp. Icon
Click Advanced Setting.
CLick Environment Variable. On the top part of Environment Variable Click New
Set Variable name as: PATH then
Set Variable Value as: (" the location of g++ .exe" )
For ex. C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
Click OK
This error occurred because your settings are not correct.
For example I receive
cannot open output file Project1.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [Project1.exe] Error 1
Because I have no permission to write on my exe file.
After some investigation, and with Dr.Topaz's help, I have learned that you will want to confirm that the program set for g++ in the Compiler Options really does compile the source code. In my case, the C:\Dev-Cpp\bin\g++.exe program did not create an exe, but the C:\Dev-Cpp\bin\c++.exe program did. Either program appears to be intended to take the same arguments and options as GNU g++. I would love to find an actual doc on the Dev-C++ compiler programs, but I have not so far.
You can test the compiler program with a simple example like this:
C:\Dev-Cpp\bin\c++.exe hello.cpp -o hello.exe
Currently in 2021, the Dev-C++ site invites you to download either original Dev-C++ or a newer fork by a group named Embarcadero.
I decided to try the Embarcadero version and the experience was slightly better. The UI is still a tad dated, but the g++.exe program it came with was able to compile programs without issue. Again, take note of where the program is being installed, but in my case, the Embarcadero compiler programs were in C:\Program Files (x86)\Embarcadero\Dev-Cpp\TDM-GCC-64\bin.
Both original Dev-C++ and Embarcadero come with mingw-32 versions of the compiler programs that from what I see do work in a Git Bash console, with slight differences such as not recognizing a default locale when using the command std::cout.imbue(std::locale("")).
I faced this similar error, and none of the solutions worked.
so I tried to download the latest version from here, https://www.bloodshed.net/
I rerun the program.
and everything is now working correctly.
I was facing the same issue as described above.
It can be resolved by creating a new project and creating a new file in that project.
Save the file and then try to build and run.
Hope that helps. :)

Resources