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

  • SEARCH
  • Home
  • 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 4074804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:13:03+00:00 2026-05-20T17:13:03+00:00

I have a static library of functions written in C. Let’s say the header

  • 0

I have a static library of functions written in C. Let’s say the header file is called myHeader.h and looks like:

#ifndef MYHEADER_H
#define MYHEADER_H

void function1();
void function2();

#endif

function1 and function2 aren’t anything too special. Let’s say they exist in a file called impl1.c which looks like:

#include "myHeader.h"

void function1() {
    // code
}
void function2() {
    // more code
}

All of the code mentioned so far is compiled into some static library called libMyLib.a. I’d rather not modify any of the code used to build this library. I also have a C++ header (cppHeader.h) that looks like:

#ifndef CPPHEADER_H
#define CPPHEADER_H

class CppClass {
    private:
        double attr1;
    public:
        void function3();
};
#endif

Then cppHeader.cpp looks like:

#include "cppHeader.h"
#include "myHeader.h"

// constructor
CppClass::CppClass(){}

void CppClass::function3() {
    function1();
}

When I try to compile this, I get an error about an undefined reference to function1(). I believe that I’ve linked everything properly when compiling. I’m pretty rusty in my C++. I’m sure that I’m just doing something stupid. I hope that my simple example code illustrates the problem well enough.

Thanks in advance for any help!

  • 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-20T17:13:04+00:00Added an answer on May 20, 2026 at 5:13 pm

    The other solution (to the one suggested originally by Yann) is to surround your “C” header with:

     #ifdef __cplusplus
     extern "C" {
     #endif
    
     #ifdef __cplusplus
     }
     #endif 
    

    Which saves you from having to remember to do:

     extern "C" {
     #include "foo.h"
     }
    

    every place you use foo.h

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

Sidebar

Related Questions

I have got a C function in a static library, let's call it A,
I have a static library written in C++ and I have a structure describing
I have a static library (let's call it S) that uses a category (NSData+Base64
I have a static C library (say mylib.a ) and I was wondering if
I have a binary file - Windows static library (*.lib). Is there a simple
I have a file named common.cs which contains commonly used functions like this public
I have a static library static_library.a How to list functions and methods realized there.
I have C++ source code (xyz.cpp) for static library called libxyz.lib, in this xyz.cpp
I write a static library: libA.a. I have another application called B.o. B.o doesn't
I have a static library *.lib created using MSVC on windows. The size of

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.