views:

15

answers:

1

Hey,

I want to write a program that outputs a list of libraries that I should link to given source code (or object) files (for C or C++ programs).

In *nix, there are useful tools such as sdl-config and llvm-config. But, I want my program to work on Windows, too.

Usage:

get-library-names -l /path/to/lib a.cpp b.cpp c.cpp d.obj

Then, get-library-names would get a list of function names that are invoked from a.cpp, b.cpp, c.cpp, and d.obj. And, it'll search all library files in /path/to/lib directory and list libraries that are needed to link properly.

Is there such tool already written? Is it not trivial to write a such tool? How do you find what libraries you should link to?

Thanks.

A: 

Yeah, you can create a pkg-config file which will allow you to run 'pkg-config --cflags' to get the compiler flags or 'pkg-config --libs' to get the linker libraries.

http://pkg-config.freedesktop.org/wiki/

If you're on Linux, just try looking into /usr/lib/pkgconfig to find some example .pc files that you can use as models. You can still use pkg-config on Windows as well, but it's not something that comes with it.

bratsche
It looks like you need to hard code flags. For example, in a .pc file, Libs: -lfoo -lbar ... I was wondering if it's possible to get library names by traversing source code and shared library files.
numeric