Results 1 to 5 of 5

Thread: g++ library

  1. #1
    Join Date
    Oct 2007
    Beans
    36

    g++ library

    I am writing some .h files. it has come to the point that i would like to have them in one spot so that I can call them when ever i want. is there a place in the Ubuntu system where i can put my .h files in and treat them like iostream or cmath libraries.

  2. #2
    Join Date
    Dec 2007
    Location
    Gainesville, Florida
    Beans
    Hidden!
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: g++ library

    /usr/include is a good place. Usually you'll want to create your own directory in /usr/include, i.e. /usr/include/myincludes. But that's not required.
    Then you include them in source files
    Code:
    #include <myincludes/something.h>

  3. #3
    Join Date
    Oct 2007
    Beans
    36

    Re: g++ library

    that sounds cool. thank you

  4. #4
    Join Date
    Oct 2007
    Beans
    36

    Re: g++ library

    Do I just put my .h files there. what do I do with the complimentary files.

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: g++ library

    Do NOT put your header files in /usr/include; put them in /usr/local/include. That is why this directory exists.

    As for your other question, your .cpp files should be bundled together into a library, which can either be a shared-object type and/or a static type. This should be placed in /usr/local/lib.

    The most basic of commands to build a shared-object and a static library are:
    Code:
    # Form object files from source files
    #
    g++ -Wall -fPIC -c One.cpp
    g++ -Wall -fPIC -c Two.cpp
    g++ -Wall -fPIC -c Etc.cpp
    
    # For shared-object library
    #
    g++ -shared -o libMyStuff.so One.o Two.o Etc.o
    
    # For static library
    #
    ar -r libMyStuff.a One.o Two.o Etc.o
    Use /usr/bin/install, as root (ie. sudo) to install your header file(s) to /usr/local/include:
    Code:
    sudo mkdir -p /usr/local/include/mystuff
    sudo install -m 644 *.h /usr/local/include/mystuff
    Similarly for the shared-object and static library files:
    Code:
    sudo install -m 644 libMyStuff.a /usr/local/lib
    sudo install -m 755 libMyStuff.so /usr/local/lib

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •