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 9237381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:31:23+00:00 2026-06-18T07:31:23+00:00

I am trying to link a static library while creating my program executable using

  • 0

I am trying to link a static library while creating my program executable using the below makefile..

IDIR =../inc
CC=g++ -g
CFLAGS=-I$(IDIR)
WFLAGS=-Wall -W
OFLAGS=-O3
DLINUX=-D_LINUX

ODIR=obj
LDIR =../lib
LIBS=-lm

_OBJ = testclient.o 
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

$(ODIR)/testclient.o: testclient.c
    $(CC) -c $< $(CFLAGS) -o $@
$(ODIR)/file2.o: file2.c
    $(CC) -c $< $(CFLAGS) -o $@

testclient: $(OBJ)
    $(CC) -o $@ $^ $(LIBS) -lccn -pthread 

.PHONY: clean

clean:
    rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ 

I have tried everything available from changing the order of the ‘-lccn‘ parameter to checking whether the function exists in the library (nm libccn.a gives the required function ccn_create() in it). The error returned is :

obj/testclient.o: In function `main':
/root/testClient/src/testclient.c:91: undefined reference to `ccn_create()'

The library libccn.a is in /usr/local/lib. I have also tried changing the directory path and then using -L flag to look in that location. Doesn’t work either. 🙁 ..Any ideas as to how can i make it work ?

  • 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-06-18T07:31:25+00:00Added an answer on June 18, 2026 at 7:31 am

    My guess is that libccn.a is a C library and the header that you use are not designed to be imported by a C++ compiler (there is no extern "C" { } block surrounding the function definition).

    C++ supports function overloading by mangling name of function. When you put a function in a extern "C" { } block, C++ disable name mangling (and thus disable overloading). Here, in your error message, the function mentioned is ccn_create(). Notice the (), this means that the function type is known, and thus the named looked up was a mangled name.

    When you do nm libccn.a you see the real name, and it is ccn_create. That is not a mangled name. So to fix this, you’ll need to surround the function definition in a export "C" { } block. The easiest way to do that is to surround the #include in such a block.

    BTW, you can reproduce the error by doing this.

    $ echo 'void ccn_create();' > ccn.h
    $ echo '#include "ccn.h"
    void ccn_create() { }' > ccn.c
    $ echo '#include "ccn.h"
    int main () {
      ccn_create();
      return 0;
    }' > main.cc
    $ gcc -o ccn.o -c ccn.c
    $ g++ -o main main.cc ccn.o
    Undefined symbols for architecture x86_64:
      "ccn_create()", referenced from:
          _main in cc8XnYRq.o
    ld: symbol(s) not found for architecture x86_64
    $ echo 'extern "C" {
    #include "ccn.h"
    }
    int main () {
      ccn_create();
      return 0;
    }' > main.cc
    $ g++ -o main main.cc ccn.o
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to link my program to the shared library. Im using a makefile
Using MINGW, I'm trying to link my C code with a static C++ library
I am trying to link a static library [1] into another static library [2]
I'm trying to link to a static library and I keep getting linker errors.
I'm trying to build a C/C++ static library using visual studio 2005. Since the
I'm trying to create a simple static C++ library that I can link it
I am trying to link a static third party library compiled with RVCT 2.2
I'm trying to link a static library (.a) file with a .o file which
I'm trying to link to a static library, libcovis.a. Everything looks fine but I
I am trying to link a static library that I created, but I get

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.