Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Compilation problem with HP UNIC GCC

SOLVED
Go to solution
Highlighted
CA1490051
Frequent Advisor

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



14 REPLIES
Steven Schweda
Honored Contributor
Solution

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
[...]
Srimalik
Valued Contributor

Re: Compilation problem with HP UNIC GCC

try g++
abandon all hope, ye who enter here..
Steven Schweda
Honored Contributor

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.
CA1490051
Frequent Advisor

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
Steven Schweda
Honored Contributor

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.
Kapil Jha
Honored Contributor

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......
Dennis Handly
Acclaimed Contributor

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;
CA1490051
Frequent Advisor

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




Steven Schweda
Honored Contributor

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.
Dennis Handly
Acclaimed Contributor

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
CA1490051
Frequent Advisor

Re: Compilation problem with HP UNIC GCC

Hi All,

Thank you very much for your support


thanks and regards
Vikram
Srimalik
Valued Contributor

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..
Dennis Handly
Acclaimed Contributor

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;
Srimalik
Valued Contributor

Re: Compilation problem with HP UNIC GCC

symptoms of old age :)
abandon all hope, ye who enter here..