Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Why g++ work but gcc not ?: (2 Items)
   
Why g++ work but gcc not ?  
A simple test.c:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <fpstatus.h>

int main(int argc, char** argv)
{
double a;

  a = 2;
  printf("a %f is %s \n", a, (isnan(a)) ? "not a number" : "a number");
  return EXIT_SUCCESS;
}
and
# qcc -o test3 test3.c
test3.o: In function `main':
test3.c:(.text+0x21): undefined reference to `_Dclass'
cc: /usr/qnx641/host/qnx6/x86/usr/bin/ntox86-ld error 1
# i386-pc-nto-qnx6.4.0-gcc-4.3.3 -o test3 test3.c
/tmp/cc4tq5Lv.o: In function `main':
test3.c:(.text+0x2b): undefined reference to `_Dclass'
collect2: ld returned 1 exit status
#
but g++ work
# i386-pc-nto-qnx6.4.0-g++-4.3.3 -o test3 test3.c
# ./test3
a 2.000000 is a number
#
The same results is with gcc/g++4.4.2
Re: Why g++ work but gcc not ?  
bogdan celer wrote:
> # qcc -o test3 test3.c
> test3.o: In function `main':
> test3.c:(.text+0x21): undefined reference to `_Dclass'
> cc: /usr/qnx641/host/qnx6/x86/usr/bin/ntox86-ld error 1
> # i386-pc-nto-qnx6.4.0-gcc-4.3.3 -o test3 test3.c
> /tmp/cc4tq5Lv.o: In function `main':
> test3.c:(.text+0x2b): undefined reference to `_Dclass'
> collect2: ld returned 1 exit status
> #
> but g++ work
> # i386-pc-nto-qnx6.4.0-g++-4.3.3 -o test3 test3.c
> # ./test3
> a 2.000000 is a number
> #
> The same results is with gcc/g++4.4.2

You need to link against libm (-lm). g++ works because it implicitly 
links in libm to resolve libstdc++-v3.

Regards,

Ryan Mansfield