LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-17-2012, 09:59 AM   #16
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081

Quote:
Originally Posted by mreff555 View Post
I'm speaking theoretically here, I'm not saying that there are more headers I should be adding or that the opencv library is poorly written. I'm simply trying to relate. Is the symptoms I'm describing something that could be seen when insufficient header information is included?
The symptoms you describe suggest memory corruption, try running with valgrind. I think -Wimplicit-int, -Wimplicit-function-declaration (both enabled by -Wall) would catch any missing header problems.
 
Old 07-18-2012, 02:02 AM   #17
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Note: If a module doesn't include its own header, inconsistencies may arise. Use option -Wmissing-prototypes to detect this problem.
 
Old 07-18-2012, 04:22 AM   #18
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
There are two kind of libraries that can link with our program
1. Static libraries (libdemo.a)
2. Dynamic libraries (libdemo.so) also known as shared objects

static libraries are merged when we binary is generated, but in case of shared objects they are linked to the binary.
I mention little more on this link
http://way2piyush.blogspot.in/2012/0...d-objects.html

shared objects can also be loaded and unloaded at run time via dlsym().
 
Old 07-18-2012, 05:09 PM   #19
doughyi8u
Member
 
Registered: Apr 2010
Posts: 254

Original Poster
Rep: Reputation: 10
How would I compile a simple "hello world" program using a static library (file.a) and not the standard libc.so?

Last edited by doughyi8u; 07-18-2012 at 05:10 PM. Reason: error
 
Old 07-18-2012, 11:13 PM   #20
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
1. specify file.a at linkage: gcc -o hello hello.c file.a
2. not possible: libc is essential for every C program
 
Old 07-19-2012, 12:22 AM   #21
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
create data.c
#include <stdio.h>
void hello()
{
printf("Hello !!! successful eith static library\n");
}

$gcc -Wall -c data.c
$ar -cvq libtest_static.a data.o

create abc.c
#include <stdio.h>
int main()
{
hello();
return 0;
}
$gcc -o abc abc.c libtest_static.a
$./abc

Note : all the file are stored in my current directory.
Hope it will help you.
 
Old 07-19-2012, 12:34 AM   #22
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
actually you can direct the linker to use static or dynamic libs: see the -static and -shared options. It depends on what libs are available (some libs have only static versions, some libs have only dynamic versions and some have both).
 
  


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 check missing header files included from another header file adisan82 Linux - Software 1 01-28-2011 03:57 AM
OO Header question goatpiper Linux - Software 1 02-27-2006 11:27 AM
Create header file for existing .c file hk_michael Programming 5 02-25-2005 05:26 PM
hdr(header file) question? bbmak Linux - Newbie 1 09-10-2004 01:45 AM
Antiquated header file question? GoboFraggle Programming 1 02-05-2003 11:52 PM

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

All times are GMT -5. The time now is 02:23 AM.

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