Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #60857 > unrolled thread
| Started by | Alla _ <modelling.data@gmail.com> |
|---|---|
| First post | 2015-04-23 02:53 -0700 |
| Last post | 2015-05-03 18:06 -0700 |
| Articles | 20 on this page of 24 — 8 participants |
Back to article view | Back to comp.lang.c
Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-23 02:53 -0700
Re: Xcode issues, doesn't compile files Bartc <bc@freeuk.com> - 2015-04-23 11:51 +0100
Re: Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-23 04:39 -0700
Re: Xcode issues, doesn't compile files Bartc <bc@freeuk.com> - 2015-04-23 13:19 +0100
Re: Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-23 07:20 -0700
Re: Xcode issues, doesn't compile files Bartc <bc@freeuk.com> - 2015-04-23 15:33 +0100
Re: Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-23 08:50 -0700
Re: Xcode issues, doesn't compile files Johann Klammer <klammerj@NOSPAM.a1.net> - 2015-04-23 20:31 +0200
Re: Xcode issues, doesn't compile files Robert Wessel <robertwessel2@yahoo.com> - 2015-04-23 14:25 -0500
Re: x86_64 Noob <root@127.0.0.1> - 2015-04-23 21:39 +0200
Re: Xcode issues, doesn't compile files G G <gdotone@gmail.com> - 2015-04-23 12:50 -0700
Re: Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-24 10:37 -0700
Re: Xcode issues, doesn't compile files G G <gdotone@gmail.com> - 2015-04-24 11:15 -0700
Re: Xcode issues, doesn't compile files Keith Thompson <kst-u@mib.org> - 2015-04-23 13:02 -0700
Re: Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-24 06:22 -0700
Re: Xcode issues, doesn't compile files G G <gdotone@gmail.com> - 2015-04-24 10:13 -0700
Re: Xcode issues, doesn't compile files Alla _ <modelling.data@gmail.com> - 2015-04-24 10:34 -0700
Re: Xcode issues, doesn't compile files Hiidenkivi <hiidenkivi@nospam.no> - 2015-04-25 14:41 +0300
Re: Xcode issues, doesn't compile files Hiidenkivi <hiidenkivi@nospam.no> - 2015-04-25 15:05 +0300
Re: Xcode issues, doesn't compile files Keith Thompson <kst-u@mib.org> - 2015-04-25 13:25 -0700
Re: Xcode issues, doesn't compile files Hiidenkivi <hiidenkivi@nospam.no> - 2015-05-03 23:29 +0300
Re: Xcode issues, doesn't compile files Keith Thompson <kst-u@mib.org> - 2015-05-03 13:46 -0700
Re: Xcode issues, doesn't compile files Hiidenkivi <hiidenkivi@nospam.no> - 2015-05-04 03:06 +0300
Re: Xcode issues, doesn't compile files Keith Thompson <kst-u@mib.org> - 2015-05-03 18:06 -0700
Page 1 of 2 [1] 2 Next page →
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-23 02:53 -0700 |
| Subject | Xcode issues, doesn't compile files |
| Message-ID | <f48581af-5efd-4b44-b982-d64c048adc2e@googlegroups.com> |
Hello!
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 <math.h>
#include <stdio.h>
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
Thank you very much!
[toc] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-04-23 11:51 +0100 |
| Message-ID | <mhaip5$cmr$1@dont-email.me> |
| In reply to | #60857 |
On 23/04/2015 10:53, Alla _ wrote:
> #include <math.h>
> #include <stdio.h>
>
> 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
1. Is the program above /exactly/ what you've tried to compile? (Ie. is
it exactly the contents of Prog3task6add.c?). Because it's complaining
there is no 'main', but it's there in your posted version. (Ignore the "_")
2. If you fix that, and there is still a link problem, try using the -lm
switch to gcc (apparently some systems need this when using maths routines).
3. If still no luck, start with a copy of working Hello, World program
and gradually modify to be like the above. Take note of when the above
error starts to appear.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-23 04:39 -0700 |
| Message-ID | <89178acc-6ffb-4b0b-a19f-5710d719eb88@googlegroups.com> |
| In reply to | #60866 |
On Thursday, April 23, 2015 at 2:51:22 PM UTC+4, Bart wrote:
> On 23/04/2015 10:53, Alla _ wrote:
>
> > #include <math.h>
> > #include <stdio.h>
> >
> > 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
>
> 1. Is the program above /exactly/ what you've tried to compile? (Ie. is
> it exactly the contents of Prog3task6add.c?). Because it's complaining
> there is no 'main', but it's there in your posted version. (Ignore the "_")
>
> 2. If you fix that, and there is still a link problem, try using the -lm
> switch to gcc (apparently some systems need this when using maths routines).
>
> 3. If still no luck, start with a copy of working Hello, World program
> and gradually modify to be like the above. Take note of when the above
> error starts to appear.
>
> --
> Bartc
Hello Bart,
Thank you very much for your reply.
1) yes, this is exactly how the program looks; and when people tried to compile it with their xcode, it worked. it seems there is something wrong with my xcode, and apparently this is beyond my understanding at this stage.
2) I am not sure I understand what to fix in it.
Thank you!
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-04-23 13:19 +0100 |
| Message-ID | <mhanu5$vv6$1@dont-email.me> |
| In reply to | #60872 |
On 23/04/2015 12:39, Alla _ wrote:
> On Thursday, April 23, 2015 at 2:51:22 PM UTC+4, Bart wrote:
>> 3. If still no luck, start with a copy of working Hello, World program
>> and gradually modify to be like the above. Take note of when the above
> Thank you very much for your reply.
> 1) yes, this is exactly how the program looks; and when people tried to compile it with their xcode, it worked. it seems there is something wrong with my xcode, and apparently this is beyond my understanding at this stage.
> 2) I am not sure I understand what to fix in it.
>
I thought you said in a previous post that gcc now 'works'?
Does that means that can compile and link this program:
#include <stdio.h>
int main(void){
puts("Hello!");
}
If it can, then use my suggest to gradually modify this program until it
looks like your example.
Or do you mean that gcc now runs, but can't gives 'ld' errors? In that
case you still have some installation issues. If so, then you need to be
fix those so that it can compile simple programs such as the above
before trying more exercises.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-23 07:20 -0700 |
| Message-ID | <be5e5f76-3c45-41e7-83cd-c59f480011c3@googlegroups.com> |
| In reply to | #60877 |
On Thursday, April 23, 2015 at 4:19:21 PM UTC+4, Bart wrote:
> On 23/04/2015 12:39, Alla _ wrote:
> > On Thursday, April 23, 2015 at 2:51:22 PM UTC+4, Bart wrote:
>
> >> 3. If still no luck, start with a copy of working Hello, World program
> >> and gradually modify to be like the above. Take note of when the above
>
> > Thank you very much for your reply.
> > 1) yes, this is exactly how the program looks; and when people tried to compile it with their xcode, it worked. it seems there is something wrong with my xcode, and apparently this is beyond my understanding at this stage.
> > 2) I am not sure I understand what to fix in it.
> >
>
> I thought you said in a previous post that gcc now 'works'?
>
> Does that means that can compile and link this program:
>
> #include <stdio.h>
>
> int main(void){
> puts("Hello!");
> }
>
> If it can, then use my suggest to gradually modify this program until it
> looks like your example.
>
> Or do you mean that gcc now runs, but can't gives 'ld' errors? In that
> case you still have some installation issues. If so, then you need to be
> fix those so that it can compile simple programs such as the above
> before trying more exercises.
>
> --
> Bartc
Bart, sorry, I am not sure I understand what you mean.
1) The program as I have shown in my example is not being compiled when I give the command in Terminal.
This happens only on my computer. Some other people got the result.
Obviously there is a problem with my xcode. I have attached the result Terminal produced.
2) I have created a bunch of other programs, but with only #include <stdio.h> header; those did not cause me any problem.
Thank you!
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-04-23 15:33 +0100 |
| Message-ID | <mhavqs$vv8$1@dont-email.me> |
| In reply to | #60895 |
On 23/04/2015 15:20, Alla _ wrote:
>> Or do you mean that gcc now runs, but gives 'ld' errors? In that
>> case you still have some installation issues. If so, then you need to be
>> fix those so that it can compile simple programs such as the above
>> before trying more exercises.
> Bart, sorry, I am not sure I understand what you mean.
> 1) The program as I have shown in my example is not being compiled when I give the command in Terminal.
> This happens only on my computer. Some other people got the result.
> Obviously there is a problem with my xcode. I have attached the result Terminal produced.
>
> 2) I have created a bunch of other programs, but with only #include <stdio.h> header; those did not cause me any problem.
Do you mean a program like this:
#include <stdio.h>
Or is there some more code? Usually you will need a main() function. My
suggestion was to copy the simplest program you have that works, or
something like this:
#include <stdio.h>
int main(void){
}
(but maybe with puts("Hi"); so that you can run it and see it do
something) and gradually add lines from the problem code, compiling at
each step until it goes wrong. Then hopefully you will find what it is
that causes the problem. So if the above works, next try:
#include <stdio.h>
#include <math.h>
int main(void){
}
and so on.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-23 08:50 -0700 |
| Message-ID | <8f59489c-279d-4424-a2f6-895b9cdea8d8@googlegroups.com> |
| In reply to | #60897 |
On Thursday, April 23, 2015 at 6:34:09 PM UTC+4, Bart wrote:
> On 23/04/2015 15:20, Alla _ wrote:
>
> >> Or do you mean that gcc now runs, but gives 'ld' errors? In that
> >> case you still have some installation issues. If so, then you need to be
> >> fix those so that it can compile simple programs such as the above
> >> before trying more exercises.
>
> > Bart, sorry, I am not sure I understand what you mean.
> > 1) The program as I have shown in my example is not being compiled when I give the command in Terminal.
> > This happens only on my computer. Some other people got the result.
> > Obviously there is a problem with my xcode. I have attached the result Terminal produced.
> >
> > 2) I have created a bunch of other programs, but with only #include <stdio.h> header; those did not cause me any problem.
>
> Do you mean a program like this:
>
> #include <stdio.h>
>
> Or is there some more code? Usually you will need a main() function. My
> suggestion was to copy the simplest program you have that works, or
> something like this:
>
> #include <stdio.h>
>
> int main(void){
> }
>
> (but maybe with puts("Hi"); so that you can run it and see it do
> something) and gradually add lines from the problem code, compiling at
> each step until it goes wrong. Then hopefully you will find what it is
> that causes the problem. So if the above works, next try:
>
> #include <stdio.h>
> #include <math.h>
>
> int main(void){
> }
>
> and so on.
>
> --
> Bartc
Thank you very much for trying to help. Unfortunately, I have to figure out what exactly has caused the problem. I don't understand the error message, yet. There is something with the Xcode I have.
[toc] | [prev] | [next] | [standalone]
| From | Johann Klammer <klammerj@NOSPAM.a1.net> |
|---|---|
| Date | 2015-04-23 20:31 +0200 |
| Message-ID | <mhbdp3$356$1@speranza.aioe.org> |
| In reply to | #60857 |
[snip]
> ld: symbol(s) not found for architecture x86_64
^^^^^^^ are you using an Itanium? They seem rare...
It seems your compiler installation is borkenz.
> collect2: ld returned 1 exit status
>
> Thank you very much!
>
[toc] | [prev] | [next] | [standalone]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2015-04-23 14:25 -0500 |
| Message-ID | <nlhija5ftn85ons0cnojelp467fijbmq2q@4ax.com> |
| In reply to | #60924 |
On Thu, 23 Apr 2015 20:31:06 +0200, Johann Klammer <klammerj@NOSPAM.a1.net> wrote: >[snip] >> ld: symbol(s) not found for architecture x86_64 > ^^^^^^^ are you using an Itanium? They seem rare... >It seems your compiler installation is borkenz. Why would you think he's using IPF? Or that the compiler is trying to generate IPF code? x86-64 is universally 64 bit x86. IA-64 would be IPF.
[toc] | [prev] | [next] | [standalone]
| From | Noob <root@127.0.0.1> |
|---|---|
| Date | 2015-04-23 21:39 +0200 |
| Subject | Re: x86_64 |
| Message-ID | <mhbhnh$9gg$1@dont-email.me> |
| In reply to | #60924 |
On 23/04/2015 20:31, Johann Klammer wrote: > [snip] >> ld: symbol(s) not found for architecture x86_64 > ^^^^^^^ are you using an Itanium? They seem rare... I think you misread. Itanium is ia64. https://gcc.gnu.org/install/specific.html#ia64-x-linux https://en.wikipedia.org/wiki/IA-64 x86_64 is amd64 (aka x64, aka IA-32e, aka EM64T) https://gcc.gnu.org/install/specific.html#x86-64-x-x https://en.wikipedia.org/wiki/X86-64 The Evil Empire has been using amd64 chips since 2005. https://en.wikipedia.org/wiki/Apple%27s_transition_to_Intel_processors Regards.
[toc] | [prev] | [next] | [standalone]
| From | G G <gdotone@gmail.com> |
|---|---|
| Date | 2015-04-23 12:50 -0700 |
| Message-ID | <943d7a19-7bd8-471e-8f12-346bcaa79ca6@googlegroups.com> |
| In reply to | #60857 |
On Thursday, April 23, 2015 at 5:53:57 AM UTC-4, Alla _ wrote: > Hello! > > > 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. i'm using Xcode 6.3 it compiles and runs on my system.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-24 10:37 -0700 |
| Message-ID | <01402908-a563-4f36-ab66-c0d079dab70d@googlegroups.com> |
| In reply to | #60939 |
On Thursday, April 23, 2015 at 11:50:28 PM UTC+4, G G wrote: > On Thursday, April 23, 2015 at 5:53:57 AM UTC-4, Alla _ wrote: > > Hello! > > > > > > 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. > > i'm using Xcode 6.3 it compiles and runs on my system. and, yes, that's what people told me in class (virtual class at CS50): they also can run this on Xcode 6.3 I wish I could update my OS. One of the reasons I am learning programing: I am so scared to update because I do not know anything yet, and do not understand how stuff works; well, now I am a bit better in terms of understanding ;) but it's still a long way
[toc] | [prev] | [next] | [standalone]
| From | G G <gdotone@gmail.com> |
|---|---|
| Date | 2015-04-24 11:15 -0700 |
| Message-ID | <0cb703ee-9720-4c1f-9ab3-5d7185e495ad@googlegroups.com> |
| In reply to | #61022 |
I wish I could update my OS. One of the reasons I am learning programing: I am so scared to update because I do not know anything yet, and do not understand how stuff works; well, now I am a bit better in terms of understanding ;) but it's still a long way /*************/ well, as for learning C, you're in a great place. these guys (people) are really good. i'm like you learning C. i try to study, and ask questions when the college folks are out of school, so not to hinder their learning process. Good luck, backup, save, and backup again, then blow it away. :-) g/
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-04-23 13:02 -0700 |
| Message-ID | <87h9s6ipf2.fsf@kst-u.example.com> |
| In reply to | #60857 |
Alla _ <modelling.data@gmail.com> writes:
> 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 <math.h>
> #include <stdio.h>
>
> 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
Given the error message, I expect that you'd get the same error
compiling the following 1-line program:
int main(void) { }
You should be able to compile it with
gcc -c foo.c
but you'll get the same error as above if you try to compile and link it
using
gcc foo.c -o foo
Your code is correct and your command line are correct. Apparently your
implementation is not configured correctly; perhaps some component
wasn't installed.
Since we deal with the C *language* here, this is not the best place to
ask for advice on this particular problem. You need to find a forum
that deals with Xcode configuration issues. It's likely others have
encountered the same problem. A Google search for "Xcode undefined
symbol _main" (without the quotes) turns up a number of hits; I haven't
taken the time to check which ones are relevant to your problem.
You might find that stackoverflow.com is a good place for questions like
this. (Do a search first to see if your question has already been asked
and answered.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
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"
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-24 06:22 -0700 |
| Message-ID | <ce356fe7-6d78-4c6f-8500-e642edc21454@googlegroups.com> |
| In reply to | #60857 |
On Thursday, April 23, 2015 at 1:53:57 PM UTC+4, Alla _ wrote:
> Hello!
>
>
> 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 <math.h>
> #include <stdio.h>
>
> 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
>
> Thank you very much!
Hello Everyone,
Thank you for your answers. It's good to get confirmation that my code works.
I am also trying to get explanation on Xcode issue and help at Apple Developer site.
I hope to solve this, otherwise I wouldn't be able to proceed.
Thank you!
[toc] | [prev] | [next] | [standalone]
| From | G G <gdotone@gmail.com> |
|---|---|
| Date | 2015-04-24 10:13 -0700 |
| Message-ID | <c1cc8c1b-e990-41c8-92ca-c3367b62f0a3@googlegroups.com> |
| In reply to | #60994 |
Uh, i'm sure you have tried this, but just in case, if you can update the os to the latest version. download and install Xcode from the apple store. if you can't install the latest os, update your os, trash old version of Xcode and download the latest version. mac 10.10.3 Xcode 6.3 macbook pro retina. you could try your code in the terminal Clang yeurCfile.c to run it, type at the prompt ./a.out
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-04-24 10:34 -0700 |
| Message-ID | <2f8e85d7-fce8-4eec-8596-b3e9bcca24ca@googlegroups.com> |
| In reply to | #61019 |
On Friday, April 24, 2015 at 9:13:12 PM UTC+4, G G wrote: > Uh, i'm sure you have tried this, but just in case, if you can update the os to the latest version. download and install Xcode from the apple store. > > if you can't install the latest os, update your os, trash old version of Xcode and download the latest version. > > mac 10.10.3 > Xcode 6.3 > macbook pro retina. > > you could try your code in the terminal > Clang yeurCfile.c > to run it, type at the prompt ./a.out Thank you very much! Yes, it would be the best way! And I wish I could update my os, I am dreaming about it, but I am afraid I will loose everything I have now, and especially I will not be able to reinstall Microsoft Office back. So, I am afraid. Also, they say that Maverick is not a good OS, I heard people had problems with it.
[toc] | [prev] | [next] | [standalone]
| From | Hiidenkivi <hiidenkivi@nospam.no> |
|---|---|
| Date | 2015-04-25 14:41 +0300 |
| Message-ID | <03L_w.5955$Jg1.2546@uutiset.elisa.fi> |
| In reply to | #60857 |
Alla _ kirjoitti:
> Hello!
>
>
> 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 <math.h>
> #include <stdio.h>
>
> 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
>
> Thank you very much!
>
Try to compile this:
#include <stdio.h>
#include <math.h>
int main (void)
{
float result;
float x = (float) 2.55;
float y1, y2;
int i = 3, z = 2;
y1 = (float) pow( x, i );
y2 = (float) pow( x, z );
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.
--
Hiidenkivi
[toc] | [prev] | [next] | [standalone]
| From | Hiidenkivi <hiidenkivi@nospam.no> |
|---|---|
| Date | 2015-04-25 15:05 +0300 |
| Message-ID | <RpL_w.5959$Jg1.147@uutiset.elisa.fi> |
| In reply to | #61074 |
Hiidenkivi kirjoitti:
> Alla _ kirjoitti:
>> Hello!
>>
>>
>> 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 <math.h>
>> #include <stdio.h>
>>
>> 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
>>
>> Thank you very much!
>>
>
>
#include <stdio.h>
#include <math.h>
int main (void)
{
float y1, y2, result;
float x = 2.55f;
int i = 3, z = 2;
y1 = (float) pow( x, i );
y2 = (float) pow( x, z );
result = 3 * y1 - 5 * y2 + 6;
printf ("If x equals %f, then the given polynomial equals %f\n", x,
result);
return 0;
}
This is the same except with "the right way" to declare a literal float
by adding f behind the value.
--
Hiidenkivi
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-04-25 13:25 -0700 |
| Message-ID | <87sibogdka.fsf@kst-u.example.com> |
| In reply to | #61074 |
Hiidenkivi <hiidenkivi@nospam.no> 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 <math.h>
>> #include <stdio.h>
>>
>> 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 <stdio.h>
> #include <math.h>
>
> 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 <http://www.ghoti.net/~kst>
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"
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c
csiph-web