I try to figure out Eclipse by writting a HelloWorld.c from scratch and hope that you can give me some help concerning the problems I face.
When launching Eclipse, I select the standard workspace.
In the Project Explorer, I create a new C project, called HelloWorld. Settings are "Empty Project" and "MinGW". Next: Debug and Release activated. Finish.
In the Menu toolbar "Window->Preferences", I make sure that under "General->Workspace" the "Text File Encoding" is set to UTF-8 and "New Text File Line Delimiter" to Unix. Apply and OK. Again under "Window->Preferences->C/C++->New C/C++ Project Wizard", under "Toolchains" I select "MinGW GCC". "Make Toolchain(s) preferred", "Apply", and "OK".
Now all the necessary setings for this C project are saved in a settings file in the project folder - if I understand this right.
In the Project Explorer, ther HelloWorld Project contains now a header-folder with three subfolders (C:/MinGW64/lib/gcc/x86_64-w64-mingw32/someversion/include and .../include-fixed, and C:/MinGW64/x86_64-w64-mingw32/include).
I create a new C Source File with explicit name "HelloWorld.c" and I get a nice window with lines to write any desired code and also an outcommented "HelloWorld.c"-title on top.
So I write
#include <stdio.h>
main(){
printf("Hello World!");
return 0;
}
and save it. So far, so good.
Now, I press "Build All" and get a Warning "return type defaults to 'int' [-Wreturn-type]".
When I press "Debug", I get the message "Info:Nothing to build for HelloWorld" but when I press "Run", the Console shows "Hello World!" anyway.
In previous (very same) projects, I already got error messages like "Launch failed. Binary not found." which disappeard after many times pressing "Build All" and "Run". And also the error message "Program file does not exist." although I just wrote and saved the above C Source File code. I could not solve it, deleted the Project, restarted Eclipse and did all again as explained above.
What did I or am I doing wrong?
Related
I have a small C console program and I want to add an .ico file to it, so that the executable looks nice.
How can I do this in CodeBlocks with MinGW/gcc?
I could not find relevant help via google that a total beginner (like me for C) could follow, so I will Q&A this topic.
First of all you need an .ico file. Put it in the folder with your main.c file.
In CodeBlocks go to File -> New -> Empty File and name it icon.rc. It has to be visible in the Workspace/Project otherwise CodeBlocks will not be aware of this file. It will show up there in a project folder called Resources .
Put the following line in it: MAINICON ICON "filename.ico". MAINICON is just an identifier, you can choose something different. More info 1 & More info 2.
Save the files and compile - CodeBlocks will do everything else for you
What will happen now, is windres.exe (the Resource Compiler) compiling the resource script icon.rc and the icon to an object binary file to obj\Release\icon.res. And the linker will add it to the executable.
It's so easy yet it took me quite a while to find it out - I hope I can save someone else having the same problem some time.
I am trying to learn C programming. And I am using VS Code for running almost everything.
But none of my C Codes execute. The c_cpp_properties.json is configured with the MinGW header files library path included in the "msvc-x64" section. It says "cannot open source file "vcruntime_string.h" (dependency of "string.h")" all the time.
First of all, it's weird that it is not letting you compile by not finding string.h dependency. I suggest to try the following:
Try compiling your files either with gcc or g++ (depending on the language you're using) directly from the terminal, to see if you get the "a.out" file.
Ex: Open your terminal. Find your .c files (if you're programming in C) gcc *.c then ./a.out
Try using CodeBlocks, Build and Run to see if you get the same error.
If 1 or 2 worked, it means your VS software didn't like something when you made the installation process. Reinstall VS.
I had the same problem.
I solved it just by reloading the window.
You can either press Ctrl + R or type "Developer: Reload Window" in the command palette.
You can open the command palette either by pressing Ctrl + Shift + P or going to "View"(up left corner) then "Command Palette..."
Before moving on to question, I'm 100% newbie to programming and I'm on my own.
So please answer my question even though you think it seems very silly.
Somehow I manage to install command line tools successfully:
LazyRen:~ LazyRen$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
LazyRen:~ LazyRen$ xcode-select --install
xcode-select: note: install requested for command line developer tools
LazyRen:~ LazyRen$ gcc
clang: error: no input files
But the problem is when I tried to build the most basic codes with ST3 it gives me
clang: error: no input files
[Finished in 0.0s with exit code 1]
[cmd: ['gcc', 'Hello C World!', '-o', 'Hello C World!']]
[dir: /Users/LazyRen/Library/Application Support/Sublime Text 3/Packages/User]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
This.
I just have no idea what kind of input file is needed. Any hints?
You appear to be lost inside ST3. As you have Xcode why not use it instead? To run a command line "Hello World" C program do the following:
Open Xcode
Select File > New > Project...
On the left side select Application under OS X
On the right select Command Line Tool
Press Next
Fill the 3 text fields with "hello" "LazyRen" & "com.lazyren" - these at not important in this situation, but the Next button won't be enabled till you fill them in.
In the Type menu select C
Press Next
In the standard save dialog locate the folder you wish to store your code in and then press Create
Project will now open in Xcode, select main.c on the left. On doing that the large editing area will show the starting template - which just happens to be "Hello World!"
Select Product > Run - you've run your first command line C program. Output will appear in a small window.
Now continue with your C textbook. Also look at the Xcode documentation. In the latter you will find out how to locate the code you just compiled on the disc to you can run it from Terminal if you wish.
HTH
In eclipse, how do I tell the console to submit the text? When I press enter, it just goes to a new line where I can continue typing and does not submit the text to continue processing.
To heck with eclipse.. I found a way of getting Visual Studio to compile C++ projects as C projects.. much better... after spending so many hours trying to get the IDE working with all its quirks... I don't think I'll be going back to that again (at least not for anything C anyway).
For anyone interested:
http://www.daniweb.com/software-development/cpp/threads/16256/compiling-c-in-visual-studio.net
Basically:
Go to project properties
Go to C/C++ node
Select "Advanced" subnode
Go to property "Compile As" and select option "Compile as C Code (/TC)"
Click OK and go back to solution explorer..
Change file extensions from .cpp to .c
That's it..
Here's the log from the build. This is a brand new project in Xcode 4, so the only non-regular things in it are as follows:
A .c file
A .a library
A bunch of header files
I've been playing with the build settings and searching for answers for a couple of hours now to see if it would go away, but it didn't. Any help you have would be appreciated.!
The output (click for a larger image):
You have a duplicate symbol error - your program can't have two functions called main(). Remove one of them, and you should be able to move forward.