Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Xcode issues, doesn't compile files Date: Sat, 25 Apr 2015 13:25:57 -0700 Organization: None to speak of Lines: 93 Message-ID: <87sibogdka.fsf@kst-u.example.com> References: <03L_w.5955$Jg1.2546@uutiset.elisa.fi> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="2448"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bQ3I1bSa3oxk4B7REfyao" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:54Jz5U9kfWEGkZBUR6QzGsoqmGg= sha1:RyNXSBNqx3Erd0pTotk5NLwtX9Q= Xref: csiph.com comp.lang.c:61100 Hiidenkivi writes: > Alla _ kirjoitti: >> I've written simple programs from Chapter 3 exercises (Programming in >> C). A few people have tested them on their machines, and they work: >> their Xcode compiles both programs. My one does not. >> >> Here is the first one. >> >> #include >> #include >> >> int main (void) >> { >> float x = 2.55, y1, y2 ; >> int i = 3, z = 2 ; >> y1 = pow( x, i ) ; >> y2 = pow( x, z ) ; >> float result ; >> >> result = 3 * y1 - 5 * y2 + 6 ; >> printf ("If x equals %f, then the given polynomial equals %f\n", x, result) ; >> >> return 0 ; >> } >> >> Here is what I get after trying to compile: >> >> alla [11:41 AM] >> 95-28-37-123:~ Alla$ gcc Prog3task6add.c -o Prog3task6add >> Undefined symbols for architecture x86_64: >> "_main", referenced from: >> start in crt1.10.6.o >> ld: symbol(s) not found for architecture x86_64 >> collect2: ld returned 1 exit status > > Try to compile this: > > #include > #include > > int main (void) > { > float result; > float x = (float) 2.55; The cast is pointless. The double value of 2.55 will be implicitly converted to float. You could write 2.55f if you really want to avoid the conversion, but the result is going to be the same. > float y1, y2; > int i = 3, z = 2; > > y1 = (float) pow( x, i ); > y2 = (float) pow( x, z ); Again, the casts are pointless, merely specifying a conversion that would be done implicitly. You could use powf() rather than pow() -- or, probably better, change all the float variables to double. (powf() wasn't introduced until C99, which might be relevant in some environments.) > result = 3 * y1 - 5 * y2 + 6; > printf ("If x equals %f, then the given polynomial equals %f\n", x, result); > > return 0; > } > > I just want to see if it makes any difference. I can nearly guarantee that it won't. On my system, both programs produce the same output. On the OP's system, the original program doesn't produce any output at all, because it doesn't build. The error message is: Undefined symbols for architecture x86_64: "_main", referenced from: start in crt1.10.6.o which means that the C implementation itself is misconfigured. Tweaking the code isn't going to change that. I expect the OP would have exactly the same problem with *any* C program, including the trivial: int main(void){} You need to read and understand the error message before you can figure out how to fix the problem. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"