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?

4
  • 1
    You probably need to add the library to the linker inputs Commented Aug 26, 2014 at 11:01
  • Why with boost, I don't need to add it to the linker inputs? Commented Aug 26, 2014 at 11:06
  • I have no idea how boost works, so I can't tell you. Commented Aug 26, 2014 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. Commented Aug 26, 2014 at 11:16

2 Answers 2

1

may be you forgot to write:

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

in your code

Sign up to request clarification or add additional context in comments.

4 Comments

No, boost works very good. This is my own library I created which doesn't work.
just replace "boost.lib" with your own library name
maybe because of different CRT libraries. try to set /MDd for both application and library msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
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.
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.

3 Comments

Why with boost, I don't need to add it to the linker inputs?
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.