Question:
Beginner question - Why can't I compile in Dev C++?
2010-06-18 11:10:14 UTC
I'm completely new to programming so sorry if my language isn't particularly technical >.<

I'm trying to learn C to prepare me for starting university this year, so bought a book called "C for dummies". Apparently, I am too dumb to even understand this book, because I can't for the life of me understand this compiling business!

The first program the book tells me to make is:

main () {}

The book says it's not meant to do anything, the idea is it won't bring up any error messages and I will know how to compile - good times. However, this is not the case! When I try to compile it, I get the messages:

"[Linker error] undefined reference to `__cpu_features_init'"

and

"Id returned 1 exit status"

Any idea how to fix this?

Oh, by the way, the book goes on about "gcc dumb.c -o dumb" (dumb is what the program is called), but I have no idea where this fits into compiling...sorry for the, what will obviously be, a noobish question, but I really can't think of what to do!

Thanks in advance :)
Six answers:
Richard
2010-06-18 11:23:35 UTC
All functions must have a return type or void return type, so a skeleton main function would look like this:



int main (void)

{

return 0; // 0 tell the OS that the application exited without error

}



Or if no return (not recommended for function main):



void main (void)

{

}



As for your linker error, this is a problem with your development environment. You may find a solution here: (http://www.gamedev.net/community/forums/topic.asp?topic_id=456599).



Finally, always remember Google is your friend.



@cubbi: void main is not an error and will compile, however the OS expects an integer return (as I'm sure you know) and so I do not recommend using a void return type as I stated before I made the option available. Please be sure that before you answer a question (or thumbs down an answer for that matter) you are properly informed.
Cubbi
2010-06-18 14:58:03 UTC
If the first example in that book contains an error like that, I doubt it would be worthwhile to continue with it.



test.cc:1:7: warning: ISO C++ forbids declaration of 'main' with no type [-pedantic]



Although it may not be important to a beginner since many compilers will figure out that you meant to write "int main() {}", I am afraid to think what kind of errors are there in the following examples. (void main is an error too, by the way)



As for the linker error you got, it is due to incorrect installation. The first link in google suggests checking if there is more than one MinGW library installed and removing extras (devc++ installs its own copy but fails to use it if there's another one present)
2016-12-17 00:21:08 UTC
Dev-C++ is a impressive person friendly compiler, i could recommend posting the difficulty you're having. i do no longer likely be attentive to the different person friendly compilers, so because it truly is why I recommend posting the difficulty as a substitute, yet possibly somebody else will come alongside and supply you a link to a nicer application.
ISkiTheWest
2010-06-18 11:22:34 UTC
well, here is some help with the second part of your question, the line that says:



gcc dumb.c -o dumb



The gcc means that you are running the gnu compiler/linker

on the file dumb.c

and producing a program called dumb (the -o means ouptput)



so presumably if you have the line

main () {}



in a file called dumb.c



then the idea is that the gcc program will build it and create the program called dumb
Charlie Tuna
2010-06-18 11:19:26 UTC
Your issue is definitely not a program bug, but a compiler setup error.



Do you have more than one compiler installed? If so, it's likely that both compilers are trying to link to the same libraries. You would have to remove one of the compilers, or uninstall both, and do a clean re-install of one compilers only.
djp32563
2010-06-18 12:22:43 UTC
I would try to download and install the most recent version of DevC++ (4.9.9.2). I had all kinds of problems compiling on earlier versions, but this version seems to much improved. You can find it here:



http://sourceforge.net/projects/dev-cpp/

or

http://www.bloodshed.net/dev/devcpp.html



Also, make sure you are compiling a console project and not a windows application project.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...