LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to write Makefile for compiling simple pgm in rt patch 2.6.24.4 (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-write-makefile-for-compiling-simple-pgm-in-rt-patch-2-6-24-4-a-763088/)

shakeela 10-19-2009 11:28 PM

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.

smeezekitty 10-19-2009 11:43 PM

https://lists.linux-foundation.org/p...st/016185.html

jhwilliams 10-20-2009 12:08 AM

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.

paulsm4 10-20-2009 12:33 AM

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

jhwilliams 10-20-2009 12:41 AM

Quote:

Originally Posted by paulsm4 (Post 3725643)
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?

paulsm4 10-20-2009 10:07 AM

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


All times are GMT -5. The time now is 09:43 PM.