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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:40:08+00:00 2026-06-16T04:40:08+00:00

I am trying to build a Library to use in an application. I built

  • 0

I am trying to build a Library to use in an application. I built the library as below, and when i compile the application i get the below error:

I have done the beolw things.

I use:

gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 

In Library to be called from application:

Here i have lot of modules, but entry point to this library is func()
(i.e., main () is replaced with func() so that i can call the module, also func () is not declared as ‘static’.)

In one of files:

int func ();
...

int func () 
{ ... } 

Then built the Library as:

gcc -Wall file.c -o file.o
...
...

ar rvs libfun.a $(OBJS)

Also used ranlib and nm -s on libfun.a seperately to build symbol table,
but the total size of archive did not change after using these commands and still got the linking error.
Here $(OBJS) contains all the object files

In Application:

extern int func ();

Compile with:

gcc -Wall -L./path-to-lib  -lfun  -o appl

Then i get the below error:

In function `main':
undefined reference to `func()'
collect2: ld returned 1 exit status

I tried to build symbol table with “ar s” and “ranlib” but the results is same.

One thing i observed is there is a difference in contents of “ar” which i built and the archives already present in project for other modules.

The archive built by me contains (ouput with “nm -s libfun.a” ):

Archive index:
Cfg1 in f1.o
mCfg1 in f1.o
dpCfg in f1.o

But the other archives which i am using without any changes contain below strange pattern:

Archive index:
_Z29platformSetjP38tagTCPIP_INTERFACE_INSTANCE_ATTRIBUTES in platform.o
_Z27platformTestSetTcpjP20tagTCPIP_CONFIG_DATAPh in platform.o
_Z23platformSetTcpIpjP20tagTCPIP_CONFIG_DATA in platform.o

I am not sure what is the difference above. Is it a shared Library or a Static library ?

I am trying to compile with GCC and build archive with ‘ar’, but the other library files may be using g++ compiler. I am not sure. Just in case it matters.

What am i doing wrong here in building my library ? Please help?

Regards.

  • 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-16T04:40:09+00:00Added an answer on June 16, 2026 at 4:40 am

    I found out the reason for the error.
    I was mixing the static library with other libraries compiled with position independent code (PIC) and some other flags. Adding "-fPIC" flag solved the issue.

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

Sidebar

Related Questions

I'm trying to use the post build command line to get my class library
I have a android webservice client application. I am trying to use the java
I am trying to use the Jets3t library within an Android application, and I
I'trying to use Google APIs Client Library for Java to get information about user's
I am trying to build my own web application and searching a PDF library
We have a c++ application which I recently ported from Linux/gcc to build on
I have an android application which uses jni and I'm trying to automate build
I'm trying to add unit testing to an ASP.NET MVC application I have built.
I am trying to build the FFmpeg library to use in my android app
I'm trying to use an external library DevExpress.XtraTreeList.v8.1.dll in my vsto office addin built

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.