0

I wanted to create a static library to use in my project like Boost library for example.
So I created a Win32 console application project and I chose static library and I compiled it.
Then, in my project I added the directory containing .h file in Properties/Configuration Properties/VC++ Directorie/Include Directories and the directory containing .lib file in Properties/Configuration Properties/VC++ Directorie/Libraries Directories like Boost library, but I have error "LNK2019 unresolved external symbol".

Why it simply doesn't work like boost library while I make the same process?

moth
  • 345
  • 1
  • 13
  • 1
    You probably need to add the library to the linker inputs – jpw Aug 26 '14 at 11:01
  • Why with boost, I don't need to add it to the linker inputs? – moth Aug 26 '14 at 11:06
  • I have no idea how boost works, so I can't tell you. – jpw Aug 26 '14 at 11:07
  • How to create or add a static library without add it to the linker inputs. Because I frequently use library which I include it as describe in my first post (my question). Else when I add it to the linker inputs, it doesn't work : error LNK2005. – moth Aug 26 '14 at 11:16

2 Answers2

1

may be you forgot to write:

#pragma comment(lib, "boost.lib")

in your code

Dean
  • 86
  • 4
  • No, boost works very good. This is my own library I created which doesn't work. – moth Aug 26 '14 at 11:04
  • just replace "boost.lib" with your own library name – Dean Aug 26 '14 at 11:49
  • maybe because of different CRT libraries. try to set /MDd for both application and library http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx – Dean Aug 26 '14 at 12:19
  • I was wrong. Actually, #pragma comment(lib, "myLib.lib") works perfectly. I had #pragma comment(lib, "myLib.lib") in my header file and it works with adding the directory containing .h file in Properties/Configuration Properties/VC++ Directorie/Include Directories and the directory containing .lib file in Properties/Configuration Properties/VC++ Directorie/Libraries Directories. Sorry and thx. – moth Aug 26 '14 at 12:34
0

You need to specify the name of the library to use (in additional dependencies in the linker options) as well as tell it which directory the additional libraries are in.

You can use #pragma comment instead, but it can be more manageable to use the build settings.

doctorlove
  • 18,872
  • 2
  • 46
  • 62
  • Why with boost, I don't need to add it to the linker inputs? – moth Aug 26 '14 at 11:07
  • Boost is partly header only, so you don't have to link any library to use it. And I am not sure if boost also suuport pragma comment linkage. – KimKulling Aug 26 '14 at 11:27
  • First, boost *is* partly header only - apart from the libraries. Second, anything can use the pragma comment lib, but since was given in another answer I wanted to point out there are other ways of doing this - you can get in a mess if you need different debug and release versions. – doctorlove Aug 26 '14 at 11:30