Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 997335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:01:00+00:00 2026-05-16T07:01:00+00:00

Lets say I have a C++ program and I want to call functions from

  • 0

Lets say I have a C++ program and I want to call functions from a C object file in it. The constraint is that I’m not allowed to make any changes to the C source files.

In this case I would include the C header as extern “C” in my C++ file, call the function, compile the C object using gcc -c, and pass the result to g++ along with the actual C++ sources.

I guess what I would also do is to put the C-header #include inside a named namespace block in the C++ file, as to keep the local namespace clean (who knows what other fancy stuff there is in the .h file).

What now if I need to call functions from two C object files. Lets say that they have different signatures. But there are also some duplicate functions in the object files. Wouldn’t my linker blow up at this point if I tried to pass both objects to g++ at the same time? Same for globals.

Again: I’m not allowed to change ANY of the C sources. Else I would just rename the .c files to .cxx, wrap their contents and the contents of the corresponding headers inside namespace bla { } and feed everything to g++.

(Yes, C is not a subset of C++, as has already been mentioned in one of the comments)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:01:00+00:00Added an answer on May 16, 2026 at 7:01 am

    Your last paragraph has a good solution – why not make a C++ file something like this:

    namespace c_namespace_1 {
        #include "CFile1.c"
    }
    
    namespace c_namespace_2 {
        #include "CFile2.c"
    }
    

    And so on…. then you could compile this file as C++ and not have to modify the original sources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a program to write text into a file (not really
Lets say I want to make a program on c#.net for a video club
Lets say a have program.exe , i will create a python script that will
lets say i have a function called simpleFunction(); that i call a bunch of
Lets say I have this program below. Now I want to pass both the
Lets say I have hierarchy like this (This is just a test program. Please
I have a command line program developed in c. Lets say, i have a
Let's say I have a program(C++, for example) that allocates multiple objects, never bigger
To make it easy, lets say I have an arraylist allBooks containing class books
Lets say we have the 10 integers from 1 to 10. We also have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.