LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2011, 10:01 PM   #1
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
howto setup personal static library


I have
Code:
$HOME/.local/lib
$HOME/.local/include
And in my .bashrc
Code:
[[ -d ~/.local/include ]] && export CPATH="$HOME/.local/include:$CPATH"
[[ -d ~/.local/lib ]] && export LIBRARY_PATH="$HOME/.local/lib:$LIBRARY_PATH"
I have a file example.h:
Code:
#ifndef __EXAMPLE_H__
#define __EXAMPLE_H__

void example();

#endif
And I file example.cc:
Code:
#include <example.h>
#include <iostream>
	using std::cout;
	using std::endl;

void example()
{
	cout << "Hello, World!" << endl;
}
I'm creating libexample.a
Code:
$ g++ -O2 -Wall -c example.cc
$ ar rsv libexample.a example.o
and placing the header and archive in the appropriate directory.

If I have a utility that uses the library, compiling like this works fine:
Code:
$ g++ -Wall main.cc -lexample
Is there a way not to need the -l? Is the term auto-linking?

Any other comments or suggestions in my attempt at a personal library?
 
Old 11-13-2011, 11:23 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Sg like this:

Code:
mkdir $HOME/include
mkdir $HOME/lib

export CPPFLAGS="$CPPFLAGS -I$HOME/include"
export LDFLAGS="$LDFLAGS -L$HOME/lib -lexample"

make main
PS: for including example.h, use quotes:

#include "example.h"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a static library to my own static library gmsa Programming 6 03-31-2010 08:33 AM
creating static library that includes another static library kskkumar Programming 2 10-22-2007 10:51 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration