public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: -x option for gcc
       [not found] <df39e6ba0610200143p3c0a5eb5u9e0c9556329844d8@mail.gmail.com>
@ 2006-10-20  8:48 ` Anitha Boyapati
  0 siblings, 0 replies; 9+ messages in thread
From: Anitha Boyapati @ 2006-10-20  8:48 UTC (permalink / raw)
  To: Surya Santosh Kumar Allena; +Cc: gcc-help


Hi,


 I got the mail.OK.But -lstdc++  is not helpful.
 
 It gives : undefined reference to main error.
 

 
On Fri, 20 Oct 2006, Surya Santosh Kumar Allena wrote:

> Hi Anitha,
> -lstdc++ must be given while compiling C++ code with gcc.
> Refer to this link:
> http://gcc.gnu.org/ml/gcc-help/2000-04/msg00101.html
> This might be helpful.
> Regards
> Surya Santosh
> 
> Hi Brian,
> 
> 
> 
> On Fri, 20 Oct 2006, Brian Dessent wrote:
> 
> > Anitha Boyapati wrote:
> >
> > >  [I am literally a novice.Kindly bear with me]
> > >
> > >  I wrote a c++ program (test.cc) which runs well with g++.
> > >  Now I tried to compile with with gcc now :
> > >
> > >  gcc -x c++ test.cc
> > >
> > >  Now the compiler shouts at me saying there are some undefined
> references.
> > >  (The list is truly long compared to the source program).
> >
> > The real question is why you would want to do this.  Supplying "-x c++"
> 
> 
>  The reason is simple.Am fascinated by this option at first glance.
> 
> 
> > does not have the same effect as invoking g++, which knows all the
> > necessary libraries and options to pass on to the subprocesses.  All -x
> > does is set the type of language by which the file will be interpreted,
> > but there is more to it.  You will run into all kinds of problems by not
> > invoking the g++ driver for C++ code.
> 
> 
>  Ok.That seems like I need to give a deeper dig to get this option work.
> 
> 
> 
> 
> >
> > Brian
> >
> 
> 
> --
> Regards,
> Anitha B,
> Sankhya Technologies Private Limited.
> 

-- 
Regards,
Anitha B,
Sankhya Technologies Private Limited.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: -x option for gcc
  2006-10-20 11:58     ` John Love-Jensen
@ 2006-10-23  4:29       ` Anitha Boyapati
  0 siblings, 0 replies; 9+ messages in thread
From: Anitha Boyapati @ 2006-10-23  4:29 UTC (permalink / raw)
  To: John Love-Jensen; +Cc: MSX to GCC


Hi John,

On Fri, 20 Oct 2006, John Love-Jensen wrote:

> Hi Anitha,
> 
> > I fail to understand the use of x option  if all it does is to
> > interpret the file by means of given language.Can you please shed some
> > more light on it.
> 
> The -x option is useful for compiling, not linking.
> 
> For example:
> cat Foo.cpp | gcc -c -x c++ - -o Foo.o
> 
> Notice that the input is coming from stdin.  Here, I simply used cat, but it
> could have been any kind of more sophisticated code generator.
> 
> Also notice that I use -c, because using -x with gcc does not turn gcc into
> a C++ toolchain driver.
> 
> In my builds, I use -x a lot, because I do a lot of code massaging with
> preprocessors such as sed and perl to do macro-magic more capable than the
> capabilities of the C preprocessor.
> 
> I'd rather *NOT* have to do such machinations on the code, but I don't want
> to switch from C++.  Java and DPL supports all the code twiddling I need
> natively, without resorting to sed or perl magic.  Anyway, my situation is
> just a case example.
> 
> Another situation to use -x is when the files have an unrecognized
> extension, and you want to explicitly tell the toolchain driver (such as
> gcc, or g++) what the language is for the source file.
> 
> g++ -c -x c++ MyFunnyFile-cpp.23 -o MyFunnyFile.o
> 
> I've only seen that kind of situation in two projects I've worked on.

 Thanks a lot.This helped me in a great way.

> 
> HTH,
> --Eljay
> 

-- 
Regards,
Anitha B,
Sankhya Technologies Private Limited.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: -x option for gcc
@ 2006-10-20 18:30 Kaz Kylheku
  0 siblings, 0 replies; 9+ messages in thread
From: Kaz Kylheku @ 2006-10-20 18:30 UTC (permalink / raw)
  To: gcc-help

Anitha Boyapati wrote:
>    I fail to understand the use of x option  if all it does is to 
>    interpret the file by means of given language.Can you 
> please shed some 
>    more light on it.

I don't understand the source of your difficulties.

The -x option is there for situations when the compiler front end cannot
figure out the type of a file. Perhaps the suffix is missing, or is
incorrect or nonstandard. One situation may be that there is no suffix,
because standard input is being read.

For instance

  mymachine $ gcc -x c -
  #include <stdio.h>
  ... type hello world main() here
  ... then Ctrl-D
  mymachine $ ./a.out
  Hello, world!

Without the -x, how would gcc know that you are typing in the C
language, right?

The -x <lang> option does not mean ``behave as a complete front-end for
language X''. It just means ``interpret files as if they were of this
language''.

Note that in

   gcc -x c++ test.cc

the ``-x c++'' is redundant because the same information is deduced from
the .cc suffix already.

If you want to find out what external symbols are needed by a program,
then compile it to .o files, and then try to link with -nodefaultlibs:

   g++ -c *.cc
   gcc -nodefaultlibs *.o

Then examine the unresolved symbol error messages.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: -x option for gcc
  2006-10-20 11:40   ` Anitha Boyapati
@ 2006-10-20 11:58     ` John Love-Jensen
  2006-10-23  4:29       ` Anitha Boyapati
  0 siblings, 1 reply; 9+ messages in thread
From: John Love-Jensen @ 2006-10-20 11:58 UTC (permalink / raw)
  To: Anitha Boyapati, MSX to GCC

Hi Anitha,

> I fail to understand the use of x option  if all it does is to
> interpret the file by means of given language.Can you please shed some
> more light on it.

The -x option is useful for compiling, not linking.

For example:
cat Foo.cpp | gcc -c -x c++ - -o Foo.o

Notice that the input is coming from stdin.  Here, I simply used cat, but it
could have been any kind of more sophisticated code generator.

Also notice that I use -c, because using -x with gcc does not turn gcc into
a C++ toolchain driver.

In my builds, I use -x a lot, because I do a lot of code massaging with
preprocessors such as sed and perl to do macro-magic more capable than the
capabilities of the C preprocessor.

I'd rather *NOT* have to do such machinations on the code, but I don't want
to switch from C++.  Java and DPL supports all the code twiddling I need
natively, without resorting to sed or perl magic.  Anyway, my situation is
just a case example.

Another situation to use -x is when the files have an unrecognized
extension, and you want to explicitly tell the toolchain driver (such as
gcc, or g++) what the language is for the source file.

g++ -c -x c++ MyFunnyFile-cpp.23 -o MyFunnyFile.o

I've only seen that kind of situation in two projects I've worked on.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: -x option for gcc
  2006-10-20  6:56 Anitha Boyapati
  2006-10-20  7:30 ` Brian Dessent
@ 2006-10-20 11:52 ` Andrew Haley
  1 sibling, 0 replies; 9+ messages in thread
From: Andrew Haley @ 2006-10-20 11:52 UTC (permalink / raw)
  To: Anitha Boyapati; +Cc: gcc-help

Anitha Boyapati writes:
 > 
 > Hi,
 > 
 >  [I am literally a novice.Kindly bear with me]
 > 
 >  I wrote a c++ program (test.cc) which runs well with g++.
 >  Now I tried to compile with with gcc now :
 > 
 >  gcc -x c++ test.cc

g++ test.cc

Andrew.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: -x option for gcc
  2006-10-20  7:30 ` Brian Dessent
  2006-10-20  7:37   ` Anitha Boyapati
@ 2006-10-20 11:40   ` Anitha Boyapati
  2006-10-20 11:58     ` John Love-Jensen
  1 sibling, 1 reply; 9+ messages in thread
From: Anitha Boyapati @ 2006-10-20 11:40 UTC (permalink / raw)
  To: gcc-help


Hi,

On Fri, 20 Oct 2006, Brian Dessent wrote:

> Anitha Boyapati wrote:
> 
> >  gcc -x c++ test.cc
> > 
> >  Now the compiler shouts at me saying there are some undefined references.
> 
> The real question is why you would want to do this.  Supplying "-x c++"
> does not have the same effect as invoking g++, which knows all the
> necessary libraries and options to pass on to the subprocesses.  All -x
> does is set the type of language by which the file will be interpreted,
> but there is more to it.  You will run into all kinds of problems by not
  
   Actually I would like to know this option so this would probably give me 
   insight to what libraries are required for compiling a small helo world.
 
   I fail to understand the use of x option  if all it does is to 
   interpret the file by means of given language.Can you please shed some 
   more light on it.
     

-- 
Regards,
Anitha B,
Sankhya Technologies Private Limited.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: -x option for gcc
  2006-10-20  7:30 ` Brian Dessent
@ 2006-10-20  7:37   ` Anitha Boyapati
  2006-10-20 11:40   ` Anitha Boyapati
  1 sibling, 0 replies; 9+ messages in thread
From: Anitha Boyapati @ 2006-10-20  7:37 UTC (permalink / raw)
  To: gcc-help



Hi Brian,


On Fri, 20 Oct 2006, Brian Dessent wrote:

> Anitha Boyapati wrote:
> 
> >  [I am literally a novice.Kindly bear with me]
> > 
> >  I wrote a c++ program (test.cc) which runs well with g++.
> >  Now I tried to compile with with gcc now :
> > 
> >  gcc -x c++ test.cc
> > 
> >  Now the compiler shouts at me saying there are some undefined references.
> >  (The list is truly long compared to the source program).
> 
> The real question is why you would want to do this.  Supplying "-x c++"

  The reason is simple.Am fascinated by this option at first glance.

> does not have the same effect as invoking g++, which knows all the
> necessary libraries and options to pass on to the subprocesses.  All -x
> does is set the type of language by which the file will be interpreted,
> but there is more to it.  You will run into all kinds of problems by not
> invoking the g++ driver for C++ code.

 Ok.That seems like I need to give a deeper dig to get this option work.
 



> 
> Brian
> 

-- 
Regards,
Anitha B,
Sankhya Technologies Private Limited.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: -x option for gcc
  2006-10-20  6:56 Anitha Boyapati
@ 2006-10-20  7:30 ` Brian Dessent
  2006-10-20  7:37   ` Anitha Boyapati
  2006-10-20 11:40   ` Anitha Boyapati
  2006-10-20 11:52 ` Andrew Haley
  1 sibling, 2 replies; 9+ messages in thread
From: Brian Dessent @ 2006-10-20  7:30 UTC (permalink / raw)
  To: Anitha Boyapati; +Cc: gcc-help

Anitha Boyapati wrote:

>  [I am literally a novice.Kindly bear with me]
> 
>  I wrote a c++ program (test.cc) which runs well with g++.
>  Now I tried to compile with with gcc now :
> 
>  gcc -x c++ test.cc
> 
>  Now the compiler shouts at me saying there are some undefined references.
>  (The list is truly long compared to the source program).

The real question is why you would want to do this.  Supplying "-x c++"
does not have the same effect as invoking g++, which knows all the
necessary libraries and options to pass on to the subprocesses.  All -x
does is set the type of language by which the file will be interpreted,
but there is more to it.  You will run into all kinds of problems by not
invoking the g++ driver for C++ code.

Brian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* -x option for gcc
@ 2006-10-20  6:56 Anitha Boyapati
  2006-10-20  7:30 ` Brian Dessent
  2006-10-20 11:52 ` Andrew Haley
  0 siblings, 2 replies; 9+ messages in thread
From: Anitha Boyapati @ 2006-10-20  6:56 UTC (permalink / raw)
  To: gcc-help


Hi,

 [I am literally a novice.Kindly bear with me]

 I wrote a c++ program (test.cc) which runs well with g++.
 Now I tried to compile with with gcc now :

 gcc -x c++ test.cc
  
 Now the compiler shouts at me saying there are some undefined references.
 (The list is truly long compared to the source program).

------------------------------------------------------------------
 For instance :

 [root@linux3 root]# gcc -x c++ test.cc
/tmp/ccjD2gLW.o(.text+0xc8): In function `main':
: undefined reference to `std::cout'
/tmp/ccjD2gLW.o(.text+0xcd): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> 
>& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, 
std::char_traits<char> >&, char const*)'

 --------------------------------------------------------------------


 Surely I am missing something.Can somebody help me as a start?
 
 (my version is gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)) 

  Thanks in advance.

-- 
Regards,
Anitha B,


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-10-23  4:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <df39e6ba0610200143p3c0a5eb5u9e0c9556329844d8@mail.gmail.com>
2006-10-20  8:48 ` -x option for gcc Anitha Boyapati
2006-10-20 18:30 Kaz Kylheku
  -- strict thread matches above, loose matches on Subject: below --
2006-10-20  6:56 Anitha Boyapati
2006-10-20  7:30 ` Brian Dessent
2006-10-20  7:37   ` Anitha Boyapati
2006-10-20 11:40   ` Anitha Boyapati
2006-10-20 11:58     ` John Love-Jensen
2006-10-23  4:29       ` Anitha Boyapati
2006-10-20 11:52 ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).