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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:39:51+00:00 2026-05-23T19:39:51+00:00

In libname.h : int add_libname(int, int); In libname.c : #include libname.h int add_libname(int a,

  • 0

In libname.h:

int add_libname(int, int);

In libname.c:

#include "libname.h"

int add_libname(int a, int b)
{
  return a+b;
}

I can build the shared library this way:

gcc -shared -fPIC libname.c -o libname.so

But I can’t use it in another programe test.c:

#include <stdio.h>
#include "libname.h"

int main(int argc, char* argv[])
{
  printf("%d\n", add_libname(1,5));
}

Reporting undefined reference to add_libname when I try to build it..

What’s wrong here?

  • 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-23T19:39:51+00:00Added an answer on May 23, 2026 at 7:39 pm

    Because add_libname takes (int, int) you’re giving it (1+5 = 6) or just (int)

    I think you meant
    add_libname(1, 5);

    Also to compile it correctly you must use gcc like so

    gcc -o myapp test.c -L. -lname
    

    the lib part of libname is ignored as it is implicit

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

Sidebar

Related Questions

In a library/controller, another library can be loaded by using $this->CI->load->library(LIB_NAME); inside the constructor
In MSVC++ you can always do #pragma comment( lib, libname.lib ) TO link a
I installed iplots and rjava packages. When I do this library(iplots), I get the
It seems to me that both work, any difference? Does gcc libname.so ... statically
I have a shared library that I wish to link an executable against using
Thanks for reading this. I am using a shared service (server=sharedLib) when setting up
I'd like to specify the current folder. I can find the current folder: libname
I have a shared library (namely libXXX.so) with a cpp/h file associated. They contains
whats the simplest way to make ocx library working in c#? (I'm using wpf
Could some one please tell me how do we use the text function with

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.