0

For some reason I don't have an option to add *.lib to a win32 console application:

Reference-> Add Reference I followed this guide until the "Add reference" part: https://msdn.microsoft.com/en-us/library/ms235636.aspx

Note that in a C# console application the "Browse" option is available.

  • What could be the reason for the disappearance of the "Browse" option?
  • What are the right steps for adding a static library in case of a win32 console application? Should I copy the *.lib file to application folder?

Thank you

Ofa
  • 67
  • 1
  • 10
  • 1
    Yeah, it doesn't work this way for native (unmanaged) code. You can add a reference to a static library if that static library project is in the same solution. Otherwise, you just add the path to the .lib file in your project's build settings, as described [here](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574400#12574400). – Cody Gray - on strike Feb 12 '17 at 10:08
  • I've tried to include the lib file in Linker -> in Input -> Additional Dependencies and enter the path to the lib file in Linker -> General -> Additional Library Directories. Didn't work for me. – Ofa Feb 12 '17 at 10:25
  • What does "didn't work" mean? I have done this hundreds or so times, and it's worked for me every time. Do you get an error message? What does it say? – Cody Gray - on strike Feb 12 '17 at 10:30
  • Sorry for being unclear at the previous comment. I get compilation errors for using functions that are defined in the library. – Ofa Feb 12 '17 at 10:35
  • You will need prototypes for those functions, too. I assume you're including a header file? – Cody Gray - on strike Feb 12 '17 at 10:53
  • Yes. I'm trying to include a header file from the library but I get an error message "cannot open source file .h " – Ofa Feb 12 '17 at 10:56
  • Should I add the lib file as a resource? – Ofa Feb 12 '17 at 10:57
  • You need to tell the compiler where to find the header file, too. There is a setting in the project properties to tell it where to look for headers. No, don't add the lib as a resource. That won't do anything useful, if it is even possible. – Cody Gray - on strike Feb 12 '17 at 11:02
  • That solved the problem. So in order to include a static library in a win32 console application, the following need to be done: – Ofa Feb 12 '17 at 11:44
  • 1. Enter the lib file in Linker -> in Input -> Additional Dependencie. 2. Enter the path to the lib file in Linker -> General -> Additional Library Directories. 3. Enter the path to the header files in C/C++ -> General -> Additional Include Directories. Doesn't step #3 cancel the idea of static library? It seems to me that we just included the headers that supposed to be included in the library, so the library became unnecessary. – Ofa Feb 12 '17 at 11:51
  • The static library contains the *code*, from your .cpp files. The headers contain the prototypes. This is how C++ works. – Cody Gray - on strike Feb 12 '17 at 12:13
  • Yeah I know. I just didn't know that I should separately include the header files of the library in addition for adding the library itself. Thank you. – Ofa Feb 12 '17 at 12:24

1 Answers1

1

Is it a c win32 console application? If I is, you will find it under project settings, linker options.

Gagan
  • 57
  • 5
  • This should be a comment – ρяσѕρєя K Feb 12 '17 at 10:18
  • As mentioned I've tried to include the lib file in Linker -> in Input -> Additional Dependencies and enter the path to the lib file in Linker -> General -> Additional Library Directories, and it didn't work. – Ofa Feb 12 '17 at 10:27