views:

64

answers:

2

I've added a .lib to my c project,

but still can't use things defined in that .lib in .c

main()
{
  structure_defined_inthat_lib c;
  ...

I added that .lib this way:

Right click ,property,Linker,Input,

and in "Additional Dependencies",I type in "D:\path\name.lib"

Anything wrong?

+3  A: 

You need to include the header files defining the stuff in that library into the code where you want to use that stuff. That header file must be on one of the paths specified in C++->General->Additional include directories - you might need to add the path to the header to that list.

Also you only specify the filename of the library in "Additional dependencies" in the linker settings and provide the path to that file in "Additional library directories".

sharptooth
I tried `#include <headinthatlib.h>`,but it reports:No such file or directory
Upvotes for the second paragraph in particular. The point is that you can change the library folders for different configurations (e.g. to link a debug version of the library into debug builds of your project) but have the library names stay the same. I don't know why paths on library names aren't accepted at all, even for single-configuration projects, except that VC++ creates two-configuration projects (debug and release) by default.
Steve314
In the "C/C++" properties, look for "General" and "Additional Include Directories" - many libraries keep the headers in with the source (not in the same folder, but a sibling folder) but put the libraries in a separare debug / release folder which *only* contains the output of the compiler (possibly including object files and other intermediate stuff), so the include path and the library path are kept separate.
Steve314
@Steve314 ,I've done the two steps pointed out by sharptooth,but still can't include that file.
Maybe you need to use #include "headinthatlib.h" rather than #include <headinthatlib.h>. Failing that, I'm out of ideas.
Steve314
A: 

You need both the library and the header to use the functions defined in the library. If you know the function signatures, you can also declare them using extern.

Max Shawabkeh