Thread: how to make a library, again..

  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    6

    how to make a library, again..

    Hi, two days ago I asked if it was possible to create a librarie that could be used without having to inform the compiler of its use.
    Apperently this is not the case.

    I started to follow some tutorials to create a dynamically linked library but I always get the same error when trying to compile a source code with it:
    gcc test.c -L. -l_string
    test.c:1:24: fatal error: lib_string.h: No such file or directory
    #include "lib_string.h"
    gcc test.c -l_string
    test.c:1:24: fatal error: lib_string.h: No such file or directory
    #include "lib_string.h"





    Here is a screen shot of all the commands that I've used:
    how to make a library, again..-screenshot-2-jpg

    low, medium and high .c are source codes for the functions that I want to put in my library.
    mylib.h is the header that contains a prototype for every function.
    test.c is a tiny script to see if the library works.
    Last edited by Mpetou; 09-06-2020 at 02:12 PM. Reason: the post conatins the image twice

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,578
    What compiler/IDE are you using?

    It looks like your compiler can't find the header file lib_string.h. Does the file exist? If it does exist where exactly is it located? Is it in the same directory as the source file?

    By the way I don't see a file named lib_string.h in your "ls" lines

    Show your code, all of it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,420
    > mylib.h is the header that contains a prototype for every function.
    Then your test.c should have
    #include "mylib.h"
    not
    #include "lib_string.h"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    6

    new problem

    Quote Originally Posted by jimblumberg View Post
    What compiler/IDE are you using?

    It looks like your compiler can't find the header file lib_string.h. Does the file exist? If it does exist where exactly is it located? Is it in the same directory as the source file?

    By the way I don't see a file named lib_string.h in your "ls" lines

    Show your code, all of it.
    Hi, I use gcc and vim.

    Indeed, it turns out that i should not include lib_string.h.
    So I tried without it but now I get the following error:
    ➜ medium_tutorial gcc -L. test.c -l_string
    /usr/lib/gcc/i686-pc-cygwin/4.9.2/../../../../i686-pc-cygwin/bin/ld: cannot find -lmylib
    collect2: error: ld returned 1 exit status

    Do you guys have any idea of what this means.
    If I understand correctly(which I probably don't) ld is used to link files so I thought that maybe lib_string.so wasn't in the LD_LIBRARY_PATH but it is!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i make static library ?
    By Isaaaac in forum Windows Programming
    Replies: 1
    Last Post: 09-16-2009, 11:51 AM
  2. how to make a library ??
    By Hussain Hani in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2007, 10:09 PM
  3. How to make my own header/library?
    By Ash1981 in forum C Programming
    Replies: 7
    Last Post: 12-31-2005, 08:01 PM
  4. Noob tryin to make a library
    By raven420smoke in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 05:48 AM
  5. howto make a static library?
    By mart_man00 in forum C Programming
    Replies: 2
    Last Post: 07-19-2003, 11:10 PM

Tags for this Thread