Re: compiling C code using aCC on HPUX

From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 10/25/03


Date: Fri, 24 Oct 2003 17:18:28 -0700

wenmang wrote:

> We have the 3rd party libraries written in C.
> And every header file from 3rd party has the guard:
>
> #ifdef __cplusplus
> #define extern "C" {
> :
> APIs...
> :
> }
> #endif
> :
>
> To me, it is clear that the 3rd party libraries must be compiled using
> C and C++ compiler should not do anything about them and linker should
> take care of them at link time.
>
> Here is my question:
> Could I compile C++ program using those C APIs?
> What I mean here is: I want to use aCC(HPUX) to compile everything
> and treat all 3rd party C APIs as regular C functions but I failed.
>
> If 3rd party header files don't have extern "C" guard,
> could I succeed?
> If I want to succeed, I should using C++ compiler to recompile all 3rd
> party libraries(C codes), is this a correct statement?

You are confused.
The third party header files contain something like this:

        #ifdef __cplusplus
        extern "C" {
        #endif/*__cplusplus */
        /* function declarations*/
        #ifdef __cplusplus
          }
        #endif/*__cplusplus */

The third party source files should contain something like this:

        #ifdef __cplusplus
        extern "C" {
        #endif/*__cplusplus */
        /* function definitions */
        #ifdef __cplusplus
          }
        #endif/*__cplusplus */

Your C++ compiler may actually call the C compiler
if the source files have a .c extension.
Consult the man page for your C++ compiler
to find the option that overrides this behavior.

There is no guarantee that functions compiled by a C compiler
(or even another C++ compiler for that matter)
can be called by programs compiled by your C++ compiler.
It is usually best to recompile everything with your C++ compiler
if you have all of the source code.



Relevant Pages

  • Re: includes -- best form?
    ... > in the header file. ... you really need to be careful about that. ... One customer group of an old compiler I worked on had many problems ... long time to compile and big source files sometimes took hours! ...
    (comp.lang.cpp)
  • compiling C code using aCC on HPUX
    ... We have the 3rd party libraries written in C. ... C and C++ compiler should not do anything about them and linker should ... If 3rd party header files don't have extern "C" include guard, ...
    (comp.lang.cpp)
  • Re: Microcontroller development board
    ... >> I don't believe that TI has ever had their own C compiler for the ... The limited version of the IAR compiler, ... > kits or as a TI download, has been getting better with every version; ... There are also plenty of 4th party compilers out there ...
    (sci.electronics.design)
  • Re: Control for selecting dates and times
    ... I *think* that is only available if the compiler version of VB is installed or if a 3rd party application that used it is installed on the user computer... ... what are the limitations of them? ...
    (microsoft.public.excel.programming)
  • Re: NativeOverlapped default constructor error
    ... I am porting code from another party, and am working in Managed C++. ... constructor DOES exist. ... The compiler recognizes what ...
    (microsoft.public.vc.language)