Thread: How to generate .pc file for a library?

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    How to generate .pc file for a library?

    Hi,
    Generally, when installing a C /C++ library, is it possible to specify that generating its pc file is desired? If it is, how to specify? Will the directory of the pc file be added to PKG_CONFIG_PATH automatically? Thanks!

    For example, I couldn't fetch info of libjpeg and libpng by using pkg_config:

    "$ pkg-config --cflags --libs libjpeg
    Package libjpeg was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libjpeg.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libjpeg' found"

    "$ pkg-config --cflags --libs zlib
    Package zlib was not found in the pkg-config search path.
    Perhaps you should add the directory containing `zlib.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'zlib' found"

    Thanks a lot!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    .pc files aren't magical. They're not generated, they're written. (With some text substitutions at installation time to fill in the install path.) So if a library doesn't provide a .pc file, you can either write one yourself (it isn't hard - the pgk-config man-page explains it) or use some other way to find the location of the library. (Of course, writing your own .pc file isn't much use when distributing.)

    zlib and libjpeg don't provide package config files.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Thanks!
    If no pc files, what are the other possible ways to find the location of a given library?
    Last edited by lehe; 02-02-2009 at 03:03 PM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There is none. If you have a configure script, do the standard thing: add a --with-zlib=/path/to/zlib option, and default to relying on standard include and library directories. Attempt to compile and link a test program. If it fails, tell the user. There's got to be existing macros for this.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Do you mean to specify where to install in the configure file?

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No, to specify where the existing version was installed.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    I think I still understand in a wrong way.

    Since the library has already been installed and its configure file was only used during its installation, how can modifying its configure file will let users know what its files are and where they are by building a test C/C++ program that uses the library?

    What is the purpose of "--with-libraryname" in the configure file of a library?

    Thanks for clarification!

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lehe View Post
    I think I still understand in a wrong way.

    Since the library has already been installed and its configure file was only used during its installation, how can modifying its configure file will let users know what its files are and where they are by building a test C/C++ program that uses the library?

    What is the purpose of "--with-libraryname" in the configure file of a library?

    Thanks for clarification!
    No, the configure file modifies the .pc file.

    --with-libraryname tells configure that "libraryname" lives at a non-standard location.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    After configure file is modified, how does the change in configure file take effect without reinstalling the library? I know I am wrong, but I think it is only used when calling "./configure" during installation. After installation, I can delete the whole package including configure file from where the library is built.

    And how to get the information that --with-libraryname tells configure?

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lehe View Post
    After configure file is modified, how does the change in configure file take effect without reinstalling the library? I know I am wrong, but I think it is only used when calling "./configure" during installation. After installation, I can delete the whole package including configure file from where the library is built.

    And how to get the information that --with-libraryname tells configure?
    That is correct. And the .pc file is generated DURING the build which is based on the ./configure run. You do not CHANGE configure - you change the .pc file.

    Once the library file is installed, you can't move it (without changing the .pc file, at least).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I was talking about the configure file for your program.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM