Compilation problem with HP UNIC GCC (428 Views)
Reply
Frequent Advisor
CA1490051
Posts: 81
Registered: ‎06-07-2007
Message 1 of 15 (428 Views)
Accepted Solution

Compilation problem with HP UNIC GCC

Hi All,

I have installed GCC-4.2.1 and trying to compile the sample cpp file.

my cpp file ex1.cpp looks as below

#include


int main()
{
cout <<" Hello World "<< endl;

}


if i give gcc ex1.cpp

the following errors are popping up.

ld: Unsatisfied symbol "std::basic_string, std::allocator >::size() const" in file /var/tmp//cc3k7lkb.o
ld: Unsatisfied symbol "__gxx_personality_v0" in file /var/tmp//cc3k7lkb.o
ld: Unsatisfied symbol "std::basic_string, std::allocator >::operator[](unsigned long) const" in file /var/tmp//cc3k7lkb.o
ld: Unsatisfied symbol "std::ios_base::Init::~Init()" in file /var/tmp//cc3k7lkb.o
ld: Unsatisfied symbol "std::ios_base::Init::Init()" in file /var/tmp//cc3k7lkb.o
5 errors.
collect2: ld returned 1 exit status
bash-2.04$


Can anybody tell me what is happening here?


thanks and regards
Vikram



Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 2 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

My C++ knowledge is remarkably weak, but I
get better results when I include one more
statement, and when I use a C++ compiler:

dy # cat ex1a.cpp
#include

using namespace std;

int main()
{
cout <<" Hello World "<< endl;
}

dy # g++ ex1a.cpp

dy # ./a.out
Hello World

For the record:

dy # uname -a
HP-UX dy B.11.11 U 9000/785 2012616114 unlimited-user license

dy # g++ --version
g++ (GCC) 4.2.2
[...]
Valued Contributor
Srimalik
Posts: 436
Registered: ‎11-28-2006
Message 3 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

try g++
abandon all hope, ye who enter here..
Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 4 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

> try g++

Now, why didn't I think of that? No, wait.
I did.

On the other hand:

dy # g++ ex1.cpp
ex1.cpp: In function 'int main()':
ex1.cpp:5: error: 'cout' was not declared in this scope
ex1.cpp:5: error: 'endl' was not declared in this scope

which is why I added:

using namespace std;

Sometimes it pays actually to _try_ a
suggestion before offering it.

But thanks for playing.
Frequent Advisor
CA1490051
Posts: 81
Registered: ‎06-07-2007
Message 5 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

Hi Steve,


yes it is working with g++, but problem i have to use gcc only. I also tried adding

using namespace std;

but not working!!!!!
Also i want to clearify her, whether both
gcc and g++ are same ? Can a g++ compiler compile complex and big C programs ?


thanks and regards
Vikram
Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 6 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

> [...] i have to use gcc only. [...]

Why? gcc is a C compiler. g++ is a C++
compiler. Both are included in the GCC (the
GNU Compiler Collection).

http://gcc.gnu.org/

> [...] but not working!!!!!

If I can show you exactly what did work, why
can't you show us exactly what didn't work?

> [...] whether both
> gcc and g++ are same ?

Do they do the same things? Obviously not.

> Can a g++ compiler compile complex and big
> C programs ?

Why would I use a C++ compiler on a complex
and big C program? Or any other C program?
I normally use a C compiler on a C program,
and a C++ compiler on a C++ program. It only
_seems_ more complicated that way.
Honored Contributor
Kapil Jha
Posts: 1,478
Registered: ‎01-23-2006
Message 7 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

My C and C++ is weak , but as far as I remember gcc is GNU C compliler and g++ is C++ compiler and so C++ program cannot be compiled with gcc.

You may check google gcc vs g++
Hope this help!!!
BR,
Kapil
I am in this small bowl, I wane see the real world......
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 8 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

>Steven: why can't you show us exactly what didn't work?

This should be obvious. :-) It seems that gcc will compile C++ sources. But it won't link them.

>Why would I use a C++ compiler on a complex and big C program?

Because you want the extra strong type checking? :-)

>I normally use a C compiler on a C program,
and a C++ compiler on a C++ program.

Exactly.

>I get better results when I include one more statement: using namespace std;

If you are using aC++ and going back and forth between -AP and -AA, you should use:
namespace std {} using namespace std;
Frequent Advisor
CA1490051
Posts: 81
Registered: ‎06-07-2007
Message 9 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

Hi All,

My Cpp code is as follows

#include
using namespace std;

int main()
{
cout <<" Hello World "<< endl;

}

And the error messages i am getting is as follows.

bash-2.04$ gcc HelloWorld.cpp
ld: Unsatisfied symbol "std::basic_string, std::allocator >::size() const" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "__gxx_personality_v0" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::basic_string, std::allocator >::operator[](unsigned long) const" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::ios_base::Init::~Init()" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::ios_base::Init::Init()" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::basic_ostream >& std::operator<< <:char_traits> >(std::basic_ostream >&, char const*)" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::basic_ostream >& std::endl >(std::basic_ostream >&)" in file /var/tmp//ccZjzzfc.o
ld: Unsatisfied symbol "std::cout" in file /var/tmp//ccZjzzfc.o
9 errors.
collect2: ld returned 1 exit status
bash-2.04$


I thought gcc and g++ are similar. But, now it seems gcc cannot be used for c++ programs.
The reason i want to use gcc is i want to link to a library file that is generated by gcc (library contains just a function which i want to call from the C++ Program ).

My idea is not to cause any conflicts between the lib file and the code which i want to compile with g++...

Since both are GNU compilers i think there should not be any conflicts?

Please correct me if i am wrong..


thanks and regards
Vikram




Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 10 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

> I thought gcc and g++ are similar.

They are related, but they have different
names for a reason.

> The reason i want to use gcc is i want to
> link to a library file that is generated by
> gcc (library contains just a function which
> i want to call from the C++ Program ).

I would not expect any special problems doing
that. There are some things which you may
need to do with the C function prototypes in
your C++ code, but that's normal.

I would try a making a simple C++ program
which calls one of the functions in your C
library, compile the C code with gcc, compile
the C++ code with g++, and link using g++.
If that fails, come back with the new error
messages.

If you've never seen anything like this:

#ifdef __cplusplus
extern "C" {
#endif

then you'll probably need to do some reading
on how to combine C and C++ programs.
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 11 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

>The reason i want to use gcc is i want to link to a library file that is generated by gcc

You still need g++ to link.

>My idea is not to cause any conflicts between the lib file and the code which i want to compile with g++

Mangling issues have to be solved with source changes, as Steven mentions.

>Since both are GNU compilers i think there should not be any conflicts?

It's the same ABI.

>Steven: then you'll probably need to do some reading on how to combine C and C++ programs.

See the following:
http://docs.hp.com/en/10946/otherlangs.htm#callinghpc
Frequent Advisor
CA1490051
Posts: 81
Registered: ‎06-07-2007
Message 12 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

Hi All,

Thank you very much for your support


thanks and regards
Vikram
Valued Contributor
Srimalik
Posts: 436
Registered: ‎11-28-2006
Message 13 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC


Now, why didn't I think of that? No, wait.
I did.

On the other hand:

dy # g++ ex1.cpp
ex1.cpp: In function 'int main()':
ex1.cpp:5: error: 'cout' was not declared in this scope
ex1.cpp:5: error: 'endl' was not declared in this scope

These errors can be solved by two ways:

1) using namspace std directive.
2) changing #include to

The second one will give a warning though, as using iostream.h is depricated.
abandon all hope, ye who enter here..
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 14 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

>Srikrishan: These errors can be solved by two ways:

You forgot qualification:
std::cout <<" Hello World "<< std::endl;
Valued Contributor
Srimalik
Posts: 436
Registered: ‎11-28-2006
Message 15 of 15 (428 Views)

Re: Compilation problem with HP UNIC GCC

symptoms of old age :)
abandon all hope, ye who enter here..
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.