LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2009, 12:28 AM   #1
shakeela
LQ Newbie
 
Registered: Oct 2009
Posts: 7

Rep: Reputation: 0
How to write Makefile for compiling simple pgm in rt patch 2.6.24.4


I have written a simple C pgm in RT patch 2.6.24.4 and compiling using gcc 4.1 but i am getting an error that
undefined reference to pci_find_device though i am including the header <linux/pci.h>
My source code is:

#include <stdio.h>
> #include <linux/pci.h>
>
> static int vendorid=0x16a2;
> static int deviceid=0x8139;
>
> int main(int argc , char *argv[])
> {
> int i;
> struct pci_dev *pdev = NULL;
>
> pdev = pci_find_device(vendorid,deviceid,pdev);
>
> return 0;
> }
>

/tmp/cceUpWSo.o: In function `main':
> /tmp/cceUpWSo.o(.text+0x1e): undefined reference to `pci_find_device'
> collect2: ld returned 1 exit status

i dont know why my header is not including so kindly any could tell me how to write simple makefile to compile my pgm.
 
Old 10-20-2009, 12:43 AM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
https://lists.linux-foundation.org/p...st/016185.html
 
Old 10-20-2009, 01:08 AM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
As smeezekittly points out, you're using a deprecated function.

From pci.h:
Code:
#ifdef CONFIG_PCI_LEGACY
struct pci_dev __deprecated *pci_find_device(unsigned int vendor,
                         unsigned int device,
                         struct pci_dev *from);
#endif /* CONFIG_PCI_LEGACY */

...

static inline struct pci_dev *pci_find_device(unsigned int vendor,
                          unsigned int device,
                          struct pci_dev *from)
{
    return NULL;
}
If you need to use it, make sure you're building with a kernel that was compiled with CONFIG_PCI_LEGACY set to y in .config.

Otherwise, I'm sure theres the "New Way" to do this, but I don't know what it is, I'm not an experienced kernel programmer.
 
Old 10-20-2009, 01:33 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

A couple of points:

1. You're getting a *link* error (not a compile error).

Your C compiler is finding "pci.h" just fine. But your "ld" linker isn't finding any library that contains a binary object for function "pci_find_device()".

2. If you're using "<stdio.h>" and you've got a "main()" ... then you're NOT doing kernel code. You've got a user-space program, which will refer to user-space headers and libraries.

I frankly don't know if "pci_find_device()" can be called from a user space program. Or, if so, what library you might need to link in.

SUGGESTION:
It sounds like you want to query your PCI devices in your program. All of the information you could possibly want is available to you in the"/proc" filesystem.

Why not just poke around "/proc" (from a command line). Then, when you find what you're looking for, it's trivial to parse through the same "/proc" files/directories in your program.

IMHO .. PSM
 
Old 10-20-2009, 01:41 AM   #5
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Quote:
Originally Posted by paulsm4 View Post
2. If you're using "<stdio.h>" and you've got a "main()" ... then you're NOT doing kernel code. You've got a user-space program, which will refer to user-space headers and libraries.
Good point; agreed. Which are you intending to program for?
 
Old 10-20-2009, 11:07 AM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Actually, I kind of thought all my points were good

ANOTHER SUGGESTION:
The following two documents might help with what you're actually trying to accomplish:

http://g2pc1.bu.edu/~qzpeng/manual/pcip.pdf

http://www.xml.com/ldd/chapter/book/ch15.html
<= Frankly, if you're going to get into kernel programming, I'd buy the book. The 3rd Edition of the book...

'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 write simple makefile ? shaiva Linux - Newbie 3 09-23-2009 06:08 AM
Simple Makefile help sharathkv25 Programming 3 02-21-2007 04:19 AM
How to write a Makefile mab_123 Linux - Software 1 07-06-2005 12:31 PM
How to write a Makefile? lpriyamb Linux - Software 2 10-15-2003 05:11 AM
problems compiling qt-pgm engman Programming 0 05-31-2001 08:27 PM


All times are GMT -5. The time now is 04:18 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration