I'm tying to learn how to make and use a static library and I've faced some problems. This is what I've done.
First I've written some code and placed in into String.h
and String.cpp
files.
Then I've compiled it into an object file:
mingw32-g++ -c -O2 -s -DNDEBUG String.cpp -o .\obj\String.o
Then I've archived(?) it:
ar cr .\lib\String.lib .\obj\String.o
And indexed(?) it:
ranlib .\lib\String.lib
After that I've successfully compiled and linked the tests with mingw:
mingw32-g++ -std=c++03 -Wall -O2 -s -DNDEBUG .\test\src\test.cpp .\lib\String.lib -o .\test\bin\test.exe
The test compiled, linked and ran perfectly.
After that I wanted to include this library into my MSVS12 project. I've:
Added a path to the
String.h
to theProject - C/C++ -General - Additional Include Directories
Included
String.h
to some project headerAdded a path to the
String.lib
to theProject - Linker - General - Additional library directories
Added
String.lib
to theProject - Linker - Input - Additional dependencies
After all these steps when I try to build the project the linker gives me many LNK2011
and LNK2019
errors. It seems to me that it can not find the implementation of my functions...
Please, tell me what I'm doing wrong and how can I fix it. Thanks!