public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc compile problem ...
@ 2000-01-26  6:51 Brian J. Dent
  2000-01-26 12:10 ` Alexandre Oliva
  2000-04-01  0:00 ` Brian J. Dent
  0 siblings, 2 replies; 9+ messages in thread
From: Brian J. Dent @ 2000-01-26  6:51 UTC (permalink / raw)
  To: help-gcc

gcc help,

Obviously I am new to the GNU gcc compiler.

I've been trying compile a program on our SUN with gcc 
(sparc-sun-solaris2.7/2.95.1) and it contains some intrinsic 
functions.  When I get to the point of linking it doesn't recognize the 
functions, eg:  sqrt.  Below is a test program.  What is missing that I am 
not finding the built-in functions to link with?  Thanks for any help.

file:marc.c:
#include <stdio.h>
#include <math.h>

main()
{
         double x = 2;
         printf("sqrt of %d is %f\n",x,sqrt(x));
}

gcc -c marc.c
gcc -o marc.out marc.o
Undefined                       first referenced
  symbol                             in file
sqrt                                marc.o
ld: fatal: Symbol referencing errors. No output written to marc.out
collect2: ld returned 1 exit status

- bjd
____________________________
Brian J. Dent
CompuDent
v (831) 649-0948 f (707) 222-1209
http://www.redshift.com/~briandent/

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

* Re: gcc compile problem ...
  2000-01-26  6:51 gcc compile problem Brian J. Dent
@ 2000-01-26 12:10 ` Alexandre Oliva
  2000-04-01  0:00   ` Alexandre Oliva
  2000-04-01  0:00 ` Brian J. Dent
  1 sibling, 1 reply; 9+ messages in thread
From: Alexandre Oliva @ 2000-01-26 12:10 UTC (permalink / raw)
  To: Brian J. Dent; +Cc: help-gcc

On Jan 26, 2000, "Brian J. Dent" <briandent@redshift.com> wrote:

> sqrt                                marc.o
> ld: fatal: Symbol referencing errors. No output written to marc.out

Try `-lm'.  Math functions are defined in libm.

-- 
Alexandre Oliva http://www.ic.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

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

* gcc compile problem ...
  2000-01-26  6:51 gcc compile problem Brian J. Dent
  2000-01-26 12:10 ` Alexandre Oliva
@ 2000-04-01  0:00 ` Brian J. Dent
  1 sibling, 0 replies; 9+ messages in thread
From: Brian J. Dent @ 2000-04-01  0:00 UTC (permalink / raw)
  To: help-gcc

gcc help,

Obviously I am new to the GNU gcc compiler.

I've been trying compile a program on our SUN with gcc 
(sparc-sun-solaris2.7/2.95.1) and it contains some intrinsic 
functions.  When I get to the point of linking it doesn't recognize the 
functions, eg:  sqrt.  Below is a test program.  What is missing that I am 
not finding the built-in functions to link with?  Thanks for any help.

file:marc.c:
#include <stdio.h>
#include <math.h>

main()
{
         double x = 2;
         printf("sqrt of %d is %f\n",x,sqrt(x));
}

gcc -c marc.c
gcc -o marc.out marc.o
Undefined                       first referenced
  symbol                             in file
sqrt                                marc.o
ld: fatal: Symbol referencing errors. No output written to marc.out
collect2: ld returned 1 exit status

- bjd
____________________________
Brian J. Dent
CompuDent
v (831) 649-0948 f (707) 222-1209
http://www.redshift.com/~briandent/

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

* Re: gcc compile problem ...
  2000-01-26 12:10 ` Alexandre Oliva
@ 2000-04-01  0:00   ` Alexandre Oliva
  0 siblings, 0 replies; 9+ messages in thread
From: Alexandre Oliva @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Brian J. Dent; +Cc: help-gcc

On Jan 26, 2000, "Brian J. Dent" <briandent@redshift.com> wrote:

> sqrt                                marc.o
> ld: fatal: Symbol referencing errors. No output written to marc.out

Try `-lm'.  Math functions are defined in libm.

-- 
Alexandre Oliva http://www.ic.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

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

* Re: GCC compile problem ...
  2002-09-27 15:52   ` Sebastian Huber
@ 2002-09-30  4:49     ` John Love-Jensen
  0 siblings, 0 replies; 9+ messages in thread
From: John Love-Jensen @ 2002-09-30  4:49 UTC (permalink / raw)
  To: gcc-help

Hi Sebastian,

> I think, that this is not true. If you assign a temporary object to a constant
> reference, the object will survive until the reference is destroyed.

Thanks Sebastian, I stand corrected!  A const-reference has lifespan beyond
the full expression.

q.v. Stroustrup's C++PL 3rd ed, section 10.4.10

Sincerely,
--Eljay

Live like you'll die tomorrow.  Learn like you'll live forever.

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

* Re: GCC compile problem ...
  2002-09-27  9:35 ` John Love-Jensen
@ 2002-09-27 15:52   ` Sebastian Huber
  2002-09-30  4:49     ` John Love-Jensen
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Huber @ 2002-09-27 15:52 UTC (permalink / raw)
  To: gcc-help

Hello John,

On Friday 27 September 2002 09:31, John Love-Jensen wrote:
> Hi Gerhard,
>
> The TEMPORARY from test.getString is being set to a REFERENCE.
>
> The TEMPORARY is destructed, more-or-less, after the semicolon that set the
> string reference to the temporary.
>
> The cout << s << "\n"; is operating on the s string that has been
> destructed, which is very dangerous.

I think, that this is not true. If you assign a temporary object to a constant 
reference, the object will survive until the reference is destroyed.

> Who knows what state that freed STACK
> memory and HEAP memory will be in, especially during the machinations of
> the ostream processing.
>
> Borland C++ 5.5 and Microsoft Visual C++ 6.0 should be ashamed.  Shame.
> Shame.
>
> --Eljay

Bye

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

* Re: GCC compile problem ...
  2002-09-27  9:09 GCC " gcc
  2002-09-27  9:30 ` Sebastian Huber
@ 2002-09-27  9:35 ` John Love-Jensen
  2002-09-27 15:52   ` Sebastian Huber
  1 sibling, 1 reply; 9+ messages in thread
From: John Love-Jensen @ 2002-09-27  9:35 UTC (permalink / raw)
  To: gcc, gcc-help

Hi Gerhard,

The TEMPORARY from test.getString is being set to a REFERENCE.

The TEMPORARY is destructed, more-or-less, after the semicolon that set the
string reference to the temporary.

The cout << s << "\n"; is operating on the s string that has been
destructed, which is very dangerous.  Who knows what state that freed STACK
memory and HEAP memory will be in, especially during the machinations of the
ostream processing.

Borland C++ 5.5 and Microsoft Visual C++ 6.0 should be ashamed.  Shame.
Shame.

--Eljay

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

* Re: GCC compile problem ...
  2002-09-27  9:09 GCC " gcc
@ 2002-09-27  9:30 ` Sebastian Huber
  2002-09-27  9:35 ` John Love-Jensen
  1 sibling, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2002-09-27  9:30 UTC (permalink / raw)
  To: gcc-help

Hi!

On Friday 27 September 2002 09:09, gcc@wiesinger.com wrote:
> Hello!
>
> I have the following compile problem with gcc 3.0.4.
>
> Borland C++ 5.5 and Microsoft Visual C++ 6.0 works well.
>
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> class Test
> {
> public:
>         string getString() { return "hallo"; }
> };
>
> int main(int argc, char* argv)
> {
>         Test test;
>
>         string& s = test.getString(); // Error here

This is not ok, because you try to initialize a non-const reference with a 
temporary string object.

>         // works well: string s = test.getString();

This is ok, because of the assignment operator looks like:
operator=( const std::string&)

>         cout << s << "\n";

This is also ok, because the overloaded shift operator takes a constant 
reference.

>         // gcc --version: 3.0.4
> }
>
> main.cpp: In function `int main (int, char *)':
> main.cpp:17: initialization of non-const reference type `class string
> &'
> main.cpp:17: from rvalue of type `basic_string<char,
> string_char_traits<char>, __default_alloc_template<true, 0> >'
> make[1]: *** [main.o] Error 1
>
> Why aren't there references allowed here with gcc? Is this not Ansi C++
> conform?
>
> Ciao,
> Gerhard

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

* GCC compile problem ...
@ 2002-09-27  9:09 gcc
  2002-09-27  9:30 ` Sebastian Huber
  2002-09-27  9:35 ` John Love-Jensen
  0 siblings, 2 replies; 9+ messages in thread
From: gcc @ 2002-09-27  9:09 UTC (permalink / raw)
  To: gcc-help

Hello!

I have the following compile problem with gcc 3.0.4.

Borland C++ 5.5 and Microsoft Visual C++ 6.0 works well.

#include <string>
#include <iostream>

using namespace std;

class Test
{
public:
        string getString() { return "hallo"; }
};

int main(int argc, char* argv)
{
        Test test;

        string& s = test.getString(); // Error here
        // works well: string s = test.getString();
        cout << s << "\n";

        // gcc --version: 3.0.4
}

main.cpp: In function `int main (int, char *)':
main.cpp:17: initialization of non-const reference type `class string
&'
main.cpp:17: from rvalue of type `basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0> >'
make[1]: *** [main.o] Error 1

Why aren't there references allowed here with gcc? Is this not Ansi C++
conform?

Ciao,
Gerhard


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

end of thread, other threads:[~2002-09-30 11:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-26  6:51 gcc compile problem Brian J. Dent
2000-01-26 12:10 ` Alexandre Oliva
2000-04-01  0:00   ` Alexandre Oliva
2000-04-01  0:00 ` Brian J. Dent
2002-09-27  9:09 GCC " gcc
2002-09-27  9:30 ` Sebastian Huber
2002-09-27  9:35 ` John Love-Jensen
2002-09-27 15:52   ` Sebastian Huber
2002-09-30  4:49     ` John Love-Jensen

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).