C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error: "syntax error: got (, expecting Newline"

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Deepak
Guest





PostPosted: Thu Nov 25, 2004 12:05 am    Post subject: Error: "syntax error: got (, expecting Newline" Reply with quote



Hi friends i tried to compile following programs and link it, i got an error like

// hellofunc.h
/*
example include file
*/

extern void myPrintHelloMake(void);



// hellomake.cpp
#include "hellofunc.h"

int main()
{
// call a function in another file
myPrintHelloMake();

return 0;
}





// hellofunc.cpp
#include "hellofunc.h"
#include <iostream.h>


void myPrintHelloMake(void)
{

cout<<"Hello make files n";

return;

}

i compiled the file with following commands on MKS KORN SHELL

cc hellofunc.cpp
cc hellomake.cpp
cc -hello hellofunc.obj hellomake.obj



i got this following error
"syntax error: got (, expecting Newline"

i cant understand why i get this error please help me in solving this problem.
your help is really appreciated..



regards,
Deepak

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Fri Nov 26, 2004 1:05 pm    Post subject: Re: Error: "syntax error: got (, expecting Newline" Reply with quote



[email]deepsalumini (AT) hotmail (DOT) com[/email] (Deepak) wrote in message
news:<5cede6f1.0411240334.6d4820a6 (AT) posting (DOT) google.com>...

Quote:
Hi friends i tried to compile following programs and link it, i got an
error like

// hellofunc.h
/*
example include file
*/

extern void myPrintHelloMake(void);


Quote:
// hellomake.cpp
#include "hellofunc.h"

int main()
{
// call a function in another file
myPrintHelloMake();

return 0;
}


Quote:
// hellofunc.cpp
#include "hellofunc.h"
#include <iostream.h

void myPrintHelloMake(void)
{

cout<<"Hello make files n";

return;

}

i compiled the file with following commands on MKS KORN SHELL

And what compiler. (The shell used to invoke the compiler is generally
not that important. The compiler is.)

Quote:
cc hellofunc.cpp
cc hellomake.cpp
cc -hello hellofunc.obj hellomake.obj

This command looks strange. But what it should be depends on the
compiler. If it is VC++, the line should be:
cl /Fehello hellofunc.obj hellomake.obj
If it is g++, the line should be:
g++ -o hello hellofunc.o hellomake.o
Note, however, that in both cases, the name of the compiler is not cc.
(Under Unix, cc is normally the name of the C compiler. And if you
invoked it as above, you'd get error messages like "suffix .cpp not
known", or if it does try to compile the code, "include file

Quote:
i got this following error
"syntax error: got (, expecting Newline"

Where? (All of the compilers I know output the file name and line
number in error messages.)

Quote:
i cant understand why i get this error please help me in solving this
problem. your help is really appreciated..

Your code looks correct, albeit somewhat outdated. (For a modern
compiler, you should prefer <iostream> and <ostream>, rather than
<iostream.h>, and put cout in std::. But most, if not all, compilers
will still support <iostream.h>, so as to not break existing code.)

I suspect that the problem is somehow linked with the -hello option --
maybe you're telling the compiler to do something special with the
object file, like treat it as a source. But without more information
(compiler, etc.), it's impossible to tell.

BTW: it is not usual in C++ to specify (void). When there are no
parameters, we just write (), unless the code is in a header which must
also be used in C.

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ulrich Eckhardt
Guest





PostPosted: Fri Nov 26, 2004 1:13 pm    Post subject: Re: Error: "syntax error: got (, expecting Newline" Reply with quote



Deepak wrote:
Quote:
i compiled the file with following commands on MKS KORN SHELL

cc hellofunc.cpp
cc hellomake.cpp
cc -hello hellofunc.obj hellomake.obj

i got this following error
"syntax error: got (, expecting Newline"

Ok, which of the three commands generated that error? Also, did you manage
to compile a normal 'hello world' that does not consist of several files?
Anyhow, there are two possible errors in the commands above:
- using 'cc': it is possible that 'cc' is a C compiler, not a C++ compiler.
It depends on your system though.
- the last line should probably rather read 'cc -o hello ..', while the
first two probably need to be 'cc -c ..', at least with all compilers I
know it needs to be like that.

Two more things I noticed:
- If there is a switch to turn on compiler warnings, use that.
- Consider dumping your textbook, as it seems to teach an old and deprecated
C++ dialect. Go to accu.org and pick a book from the 'most recommended'
book reviews.

Uli

--
FAQ: http://parashift.com/c++-faq-lite/

/* bittersweet C++ */
default: break;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.