I'm beginner for C language and for Eclipse IDE. I've downloaded and installed Eclipse ide for c/c++ developers i.e. Mars 2.0. I've created a new project and selected the appropriate compiler and typed the following code:
#include <stdio.h>
int main()
{
printf("Hello, World! \n");
return 0;
}
After, when click build project it creates .exe file for me and when I click on Debug it successfully Debugs but shutdowns automatically within a fraction of a second.
From what you've told us, that would be correct. If you want to step through the code, you have to set a breakpoint. You should be able to double-click in the margin on the "printf" line to set a breakpoint there.
Related
I have a dart method that invokes some C code using dart:ffi. When the C code fails (for example due to some memory violation), I don't get any error message to indicate what's wrong, but only the whole process exits immediately with these messages:
[+41627 ms] Service protocol connection closed.
[ ] Lost connection to device.
[ +1 ms] DevFS: Deleting filesystem on the device (file:...)
I am not asking about catching the error, as I know these kinds of errors are fatal, I just want some useful logs to see whats happening.
Can I debug the native code somehow or at least get useful error messages about the reason/location of the crash?
Assumptions: debugging a Windows DLL on Windows using a pure Dart test harness. It should work pretty much the same for a Flutter test harness (i.e. the example app in a Flutter plugin project), but in all likelihood you'll want to do much of the testing in as simple a test environment as you can.
You are going to need two projects: a Visual Studio DLL project and a pure Dart command line. (In what follows my examples are in d:\vcc\Dll2\ and d:\source\testffi2\ respectively. The Dart project has a main function in bin\testffi2.dart.)
For testing I removed the VS C++ DLL project boilerplate and replaced it with:
#include "pch.h"
#include "framework.h"
#include "Dll2.h"
#include <cstdint>
extern "C" __declspec(dllexport) int32_t sum(int32_t a, int32_t b) {
return a + b;
}
and checked that it compiled OK (in Debug/x64 configuration). This built: D:\vcc\Dll2\x64\Debug\Dll2.dll as expected.
In the Dart project I created a simple test harness to load the DLL and the function and call it.
import 'dart:ffi';
import 'dart:io';
void main() {
final dll = DynamicLibrary.open('D:\\vcc\\Dll2\\x64\\Debug\\Dll2.dll');
final sumFunction = dll.lookupFunction<
Int32 Function(
Int32 a,
Int32 b,
),
int Function(
int a,
int b,
)>('sum');
print(sumFunction(123, 321));
sleep(Duration(seconds: 5)); // this is just there so that the VCC debug
// window doesn't immediately close
}
Running this is the Dart IDE or from the command line does, indeed, print 444 as expected, but doesn't give you an opportunity to debug the C.
Finally, back in the Visual Studio project, change the debugging properties to launch the Dart test harness. Set the exe path to the Dart sdk binary, the command line to the Dart main file, and the working folder to the Dart project folder.
Finally, set a breakpoint on the return a + b line and click the Local Windows Debugger button. Execution pauses as expected in the Visual Studio debugger and the values of local variables a and b are visible, etc.
I haven't found any extension, or tutorial to make and execute a C console application in the VSCode Terminal.
A simple program like
int main()
{
printf("Hello World!");
return 0;
}
And have the output in the VSCode Terminal.
Does someone know how to realize this? And/or are there solutions?
Thanks in advance
Regards
There actually is an extension for c/c++ on VSCode:
When you click the arrow in the top right (to run the file) you will be asked which compiler you want to use. In our case we can use the gcc compiler:
Then you can paste your code into a .c file and run it with the compiler. It should automatically also execute the binary and print your output into the debug-console:
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
Hello World!
You even have a debugger, if you set certain breakpoints!
Extra:
Make sure that you have the correct OS set in the bottom right (in the status bar), so your c code compiles for your machine specifically.
I installed VSC and wrote this program
#include <stdio.h>
int main( void )
{
printf("Hello world!");
}
Then I installed a C/C++ debugger and I saved the file on the desktop as "hello.c" and magically the syntax became higlighted.
Now I would like to run the program, but can't find a way.
There's no "run" or "build" option anywhere, and if I start the debugging and choose the debugger then I got a new tab named "settings.json" with a couple of brackets waiting for me to write something.
Also in the left I can read that I "have not yet opened a folder". What does it even mean?
And the line #include <stdio.h> is underlined in red, like there's something wrong going on, maybe I have to download the library?
I would do anything to see the output of the program, please help me.
have you added c/c++ and code runner extensions?
I coded this simple C Hello World program, but i don't know why it's not working in command line? I'm using MinGW C compiler which I downloaded per site instructions and I'm using Sublimetext for my text editor. I compiled the program fine it seems b/c the .exe file shows up, but when I try to run that file it prints
the problem seems pretty basic, my bad if it the question is amateur, just started trying to learn C.
Here's my code from Sublime text for it.
#include <stdio.h>
int main (){
printf("Hello World\n");
return 0;
}
You need to specify the directory of the executable within PowerShell. Your alternative is to launch the program through cmd.exe.
.\helloworld.exe
or
C:\Users\Zanel\OneDrive\documents\code\C\helloworld.exe
. represents current directory.
I am learning C. I am using Ubuntu as main OS but I also have Windows 7 for testing in another partition. I have made a program in C in both OSes using Code Blocks. When I double click the compiled file of program in windows it runs, but when I do the same in Ubuntu it does not run. I have also created .desktop file for it, but even then it doesn't run. But using the command.someone told me code GUI in.so how can i code GUI in it? also why it runs on windows?
./addition
makes it run in terminal. But I want to run it using GUI. I am clicking on its icon but its not opening.Do i need to code GUI for it?
source code is
#include <stdio.h>
int main(){
int a,s,d;
printf("type the values u want to add and give tab between them\n");
scanf("%d %d",&a,&s);
d=a+s;
printf("addition is %d",d);
system("read -p 'Press Enter to EXIT...' var");
return 0;
}
in linux if you run a shell program from the desktop, it does not have a std input or output attached. For this reason you cannot see anything about it.
A quick solution would be to open a terminal and run it from there.
Two easy options if you don't know how to run the program from terminal:
A) Drag the icon of the program into the terminal, it will automatically build the full path to run it
B) Move to the program's home folder and run it from there "./programName"
I hope this helps mate.