I'm new to C and I'm trying to compile a HelloWorld program. I'm using GNU GCC 4.9.2. I've looked online for many solutions but none of them worked: Every time I compile the program, it hits me with this error:
"Undefined reference to 'WinMain#16'"
Please bear in mind that I HAVE configured the project as a console project, not a windows project and that I have written the main function correctly.
Here's the code:
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
Finally, note that I can successfully compile, build, and run C++ programs with code blocks. For some reason, I can't do the same for C. Additionally, I tried compiling the source file from the command line and the issue still persisted.
Compilation lines:
I solved the problem and I don't know how. I changed the C debugger from gcc to gnu, it gave me a different error. I then changed it back to gcc and it started working randomly. I've been trying to solve this problem for literally 6 hours. Then I try some random nonsense and guess what? it works.
I hate software development.
I love software development.
Related
code: http://www.ioccc.org/1988/phillipps.c
How do i run this on Coderunner?
I've encountered some compiling problems that i can't solve after searching on the internet.Can someone help me out?
If I am not being informative enough, i'm sorry, but please tell me how i can do better at asking these tech questions.
compiling errors below(i use coderunner)
The program is written in an old dialect of C and is relying on some features now considered broken. Clang (the compiler in question) is not happy about the third argument of main and I don't think you can convince it to accept that.
You can either install gcc, that compiler will accept the code with just warnings. But I don't think coderunner has gcc integration.
Or you can manually unscrew the objectionable bit of the code.
Replace all instances of the word main with mayn in the code and add this bit of code to the beginning of the file:
main() {
mayn(1,0,0);
}
Now you can enjoy the program under clang/coderunner as well.
I have a big problem with compilation of my program in VS Code. I'm writing a simple program but when I try to compile it and run it shows 2 problems. (I'm trying to translate it as clear as I can).
There is a problem with element #include. Please upgrade element includePath.
Can't open source file "stdio.h"
I'm writing the program in C language. I have to say that I'm a fresh programmer so if you can help me, please write it as simple as it's possible.
I'm adding the program, but I think it's very simple and that's not the issue:
#include <stdio.h>
int main()
{
printf("costam\n");
return 0;
}
So this is my first post. I am preparing for some upcoming college courses on programming, one of them deals with C. I have been teaching myself for a little while and have never encountered this problem before, even though I have used the same code. I am having the issue on any ide that I use, which are MS Visual Studio 2019, and Codeblocks, both 16.01 and 17.12.
The problem is when I try to include an inline function, the compiler brings up an error: identifier "keep_window_open" is undefined, as well as the error: 'keep_window_open':identifier not found.
This never happened until I upgraded Codeblocks from 16.01 to 17.12, so that leads to believe something happened with the compiler or some settings that I don't know about, or how to change.
I have tried going back to Codeblocks 16.01, but still get the same error. All my previous programs, that use the exact same code still compile and run, so I am at a lost and completely frustrated. Enough so to think about changing my major, which I really do not want to do. I enjoy programming. But this problem is killing me.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
inline void keep_window_open() { char ch; scanf("%s", ch); }
int main()
{
printf ("Lets see if this stupid thing works\n");
keep_Window_open();
return 0;
}
The problem is the line of code:
keep_Window_open();
If I comment it out, the program will compile and run, however I can't see it, because all it does is flash and then close the console window. And I need to use this code to see the output window. As I have said I have used this code in many other programs, most of which are much more complex than this, and they all still compile and run. It is only on new projects that I try to create.
I expect the window to stay open until the user presses and enters a key, like it always has before. I am stuck, and would appreciate some input on how to proceed, other than throw myself in front of a bus.
OK, so I was able to solve the issue in CodeBlocks, but not in Visual Studio. I changed the code to have the inline function below the main function, and now when compiled and run in CodeBlocks (17.12) it works exactly like it should, or how I thought it should.
However when I try the same solution in Visual Studio, after putting the inline function below the main function I now get a new error:
'keep_window_open' redefinition basic types
Since I usually use CodeBlocks for C, Visual Studio for C++ and intellij for java, I am not going to worry about this, as long as it works in CodeBlocks I should be OK. However I am curious as to why it work in one IDE and not the other?
I am new to this programming thing, and there is much to learn, and I know virtually nothing about compilers and linkers, as I am focusing on programming techniques and syntax in several different languages.
I'm want to learn C programming with K&R using XCode, but I can't even get the Hello World to work right - it's giving me errors it shouldn't, I guess because it's being very technical. Can I get XCode to relax on requirements? Would greatly appreciate some advice! Thanks.
Xcode Bah! Just compile from the command line:
gcc myfile.c -o myfile
You don't need Xcode, but if you want to ... Xcode has hello world built in. Make a new project "Command Line Utility", "Standard Tool", give it a name, have a look in "Source", and you'll see the Hello World program:
#include <stdio.h>
int main (int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
return 0;
}
Click "Build and Run" and it goes, you see:
Running…
Hello, World!
Debugger stopped.
Program exited with status value:0.
I will agree with ergosys above. Xcode is realistically made for Objective-C coding, and even its "Command Line Utility" template is sheer overkill. Anything in K&R will compile flawlessly with
gcc -Wall filename.c
except maybe some of the more advanced stuff. K&R doesn't go into object compiling or linking extensively, since it's only meant to teach you the language. Grasp compilation though, and learning C will be much easier. I much prefer using Makefile's or gcc/g++ than IDE's like Xcode or Eclipse.
I'm gonna assume that XCode is demanding Ansi Standard C, while you are using an early edition of the K&R book, whch still uses the old style.
Unless you are doing this just so you can interprete some ancient C code, don't bother with the old style. Use the Ansi Standard syntax.
Honestly, XCode is way more than you need if using K&R. K&R is about basics, XCode is about making you pull your hair out.
I actually prefer to use the command line instead of an IDE on the Mac.
At least for K&R, using the command line is the way you want to go. Try:
gcc -o outputfile code.c
If you want to get into iPhone/iPod or Cocoa applications, then use Xcode. But more times than most, XCode is overkill and will probably just slow you down.
As I said in my comment, you shouldn't see an error from Xcode with the hello world program from K&R. You might be seeing some warnings, or you have mistyped something. Remember to select the correct language for compiling (you want C, of course).
Can I get XCode to relax on requirements?
In general, you want the compiler to be able to warn you for things that it thinks are not "right". In some cases, the warnings are harmless, and can be turned off, but in most of the cases, the warnings expose issues with your program. I like compiling my code with the maximum warnings enabled for example, because it saves me a lot of time later.
If you are getting errors, you should post (copy-paste) your code here.
Finally, look at the errata page for K&R. It has some bug fixes or corrections, but nothing for hello world.
(It could be that you're using the first edition of the book, in which case you shouldn't use that book to learn C.)
In my Turbo C++ program, I can't run any of the graphics program. When it compiles, it shows an error like:
undefined symbol _line, _closegraph,_ getmaxx etc...
Is it due to the settings of my c-program?
Is this an old program that was written for Turbo C++, and that you're trying to compile with a modern compiler? If so, it might be the case that the program uses compiler-specific extensions and libraries, that are simply not available in the compiler you're using now.
If that is the case, you must either
find an existing library for your current environment that emulates the old Turbo C++ one, or
find out exactly what each call is supposed to do, and change the code to use something that your environment supports.
It's compile error and not link error. Looks like "graphics.h" is missing.
Do
#include "graphics.h"
Those errors are typical of a missing library in your build. Try linking the appropriate libraries and rebuild the solution (most likely graphics.lib).
-John
If the problem is of compiling error then you may add the header file:
#include<graphics.h>
if the problem still persists then make sure you have added the header file:
#include<dos.h>