Operating System - HP-UX
1833757 Members
2670 Online
110063 Solutions
New Discussion

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

 
Zhu Wang_1
Occasional Advisor

Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

I posted earlier today, however, I don't see it posted.
I have a project which contains a few C code and ONE C++ program which calls functions defined in the C code. I used aCC to cimpile all these code and ar a library libl1.a. I have other code (C++ code) for this project and when I linked this library, I got some unsatisfied symbol in the object file of that C++ in libl1.a. I DID remember to use
ifdef __cplusplus
extern "C" {
...
in the header file for that C++ file.
I used aCC to compile both C and C++ code.
All the code compiles and links fine on other platforms using g++.
Any hint? Thanks a lot.
Ciao.
11 REPLIES 11
A. Clay Stephenson
Acclaimed Contributor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

 
If it ain't broke, I can fix that.
Zhu Wang_1
Occasional Advisor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

This doesn't really help. But thanks for replying.
I doubt some options for aCC were not set right. The option I use is
aCC -z +DA2.0W +DO11.0

Any advice?
Ciao.
Steven Gillard_2
Honored Contributor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

Possibly a silly questions, but are you using aCC to link or are you calling ld directly? Calling ld directly won't work if there's c++ libraries involved.

Cheers,
Steve
Zhu Wang_1
Occasional Advisor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

I am using aCC to link.
Ciao.
Steven Gillard_2
Honored Contributor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

OK, you actually don't need the extern "C" declarations, because all the code has been compiled with aCC.

Therefore you aren't really mixing C with C++ at all, everything is being compiled as C++.

If you remove the extern "C" declarations all should work.

Cheers,
Steve
Zhu Wang_1
Occasional Advisor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

I have tried to get rid of the extern "C", but this will generate more errors like duplicated defined symbol with ld. ( I am using aCC to compile and link). Again, I don't have this problem on pther platforms.
Is there a way to generate a library of the mix of the C and C++ code and link with other part of the program to get a 64 bit executable on HP? I heard there are some gcc for 64 bit, but I can't find on our system.
Thanks.
Ciao.
Steven Gillard_2
Honored Contributor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

You'll receive a duplicate symbol error if you're trying to link together two libraries or object files with the same function or variable name defined.

Try using nm++ to dump the names of the symbols in each of your object files and look for where the duplicates are.

As for extern C, definitely leave those declarations out. The only reason to use them is if you have code compiled with a C compiler that you need to link with. This is because the C and C++ compilers have different methods of generating symbol names. Since you're using the aCC C++ compiler to compile all the code you don't need them because all your symbol names will be generated in the C++ method. In fact using them will result in unsatisfied symbols.

If you can provide a small example I may be able to help further. I can't explain without more information why it would work on other platforms and not with aCC.

Regards,
Steve
Zhu Wang_1
Occasional Advisor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

The code is too big and complex for me to show any part of it. It's also too big for me to modify for any duplicated symbol. Also, considering all code work well for other platforms, I am reluctant to change all the header files to get rid of the duplicate symbol.
Is there any other compiler for me to compile C code for HP 64 bit?
Ciao.
Steven Gillard_2
Honored Contributor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

I've never seen gcc do 64bit on HPUX, but I don't use it very often. Do you have the HP ANSI C compiler on your system? If so try compiling the C code with that. Those two are the only C compilers I've used.
Zhu Wang_1
Occasional Advisor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

I did try the gcc for 64 bit, but again, it generated more then 20 thousand error messges like TYPE MISMATCH ... NOTYPE... error.
What is the HP ACSI C compiler? What's the program name?
Thanks.
Ciao.
Steven Gillard_2
Honored Contributor

Re: Unsatisfied symbol error in aCC link with mixed C and C++ for 64 bit

The HP ANSI C compiler replaces the bundled compiler, so its just 'cc'. To see if its installed on your system, run:

$ cc -Ae

If it comes back saying that the -Ae option is only available with the ANSI C product, then you don't have it.

I think you can purchase it online from software.hp.com - just look for the C / ANSI C Developers bundle, product id B3901BA.

I've also found from another thread that HP have a freely available version of gcc that will compile 64bit apps. Take a look at:

http://h21007.www2.hp.com/dspp/tech/tech_TechSoftwareDetailPage_IDX/1,1703,547,00.html

Cheers,
Steve